Coverage for fio_wrapper/endpoints/endpoints_v1/group.py: 100%

31 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-11-16 11:50 +0100

1from typing import List, Optional 

2from fio_wrapper.decorator import apikey_required 

3from fio_wrapper.endpoints.abstracts.abstract_endpoint import AbstractEndpoint 

4from fio_wrapper.endpoints.abstracts.abstract_group import AbstractGroup 

5from fio_wrapper.models.group_models import ( 

6 BurnList, 

7 GroupHub, 

8 GroupList, 

9 Group as GroupModel, 

10 GroupMembershipList, 

11) 

12 

13 

14class Group(AbstractGroup, AbstractEndpoint): 

15 @apikey_required 

16 def all(self, timeout: Optional[float] = None) -> GroupList: 

17 """Gets all groups from FIO 

18 

19 Note: 

20 FIO API Key Required 

21 

22 Args: 

23 timeout (float, optional): Request timeout in seconds. Defaults to None. 

24 

25 Raises: 

26 UnknownFIOResponse: FIO returned an unknown response 

27 

28 Returns: 

29 GroupList: List of Groups 

30 """ 

31 (status, data) = self.adapter.get( 

32 endpoint=self.urls.group_all_url(), timeout=timeout 

33 ) 

34 

35 if status == 200: 

36 return GroupList.model_validate(data) 

37 

38 @apikey_required 

39 def get(self, groupid: int, timeout: Optional[float] = None) -> GroupModel: 

40 """Gets group information for specified GroupID from FIO 

41 

42 Note: 

43 FIO API Key Required 

44 

45 Args: 

46 groupid (int): GroupModelId 

47 timeout (float, optional): Request timeout in seconds. Defaults to None. 

48 

49 Raises: 

50 UnknownFIOResponse: FIO returned an unknown response 

51 

52 Returns: 

53 GroupModel: GroupModel 

54 """ 

55 (status, data) = self.adapter.get( 

56 endpoint=self.urls.group_get_url(groupid=groupid), timeout=timeout 

57 ) 

58 

59 if status == 200: 

60 return GroupModel.model_validate(data) 

61 

62 @apikey_required 

63 def memberships(self, timeout: Optional[float] = None) -> GroupMembershipList: 

64 """Gets all groups the FIO API Key is member of 

65 

66 Note: 

67 FIO API Key Required 

68 

69 Args: 

70 timeout (float, optional): Request timeout in seconds. Defaults to None. 

71 

72 Raises: 

73 UnknownFIOResponse: FIO returned an unknown response 

74 

75 Returns: 

76 GroupMembershipList: List of Group Memberships 

77 """ 

78 (status, data) = self.adapter.get( 

79 endpoint=self.urls.group_memberships_url(), timeout=timeout 

80 ) 

81 

82 if status == 200: 

83 return GroupMembershipList.model_validate(data) 

84 

85 @apikey_required 

86 def hub(self, members: List[str], timeout: Optional[float] = None) -> GroupHub: 

87 """Gets the groups Hub information from FIO 

88 

89 Note: 

90 FIO API Key Required 

91 

92 Args: 

93 members (List[str]): List of members, e.g. ["NAME1", "NAME2"] 

94 timeout (float, optional): Request timeout in seconds. Defaults to None. 

95 

96 Raises: 

97 UnknownFIOResponse: FIO returned an unknown response 

98 

99 Returns: 

100 GroupHub: GroupHub data from FIO 

101 """ 

102 (status, data) = self.adapter.post( 

103 endpoint=self.urls.group_hub_url(), data=members, timeout=timeout 

104 ) 

105 

106 if status == 200: 

107 return GroupHub.model_validate(data) 

108 

109 @apikey_required 

110 def burn(self, groupid: int, timeout: Optional[float] = None) -> BurnList: 

111 """Gets the groups Burn information from FIO 

112 

113 Note: 

114 FIO API Key Required 

115 

116 Args: 

117 groupid (int): GroupModelId 

118 timeout (float, optional): Request timeout in seconds. Defaults to None. 

119 

120 Raises: 

121 UnknownFIOResponse: FIO returned an unknown response 

122 

123 Returns: 

124 BurnList: List of Burn data 

125 """ 

126 (status, data) = self.adapter.get( 

127 endpoint=self.urls.group_burn_url(groupid=groupid), timeout=timeout 

128 ) 

129 

130 if status == 200: 

131 return BurnList.model_validate(data)