def get(self, key, value): """Retrieve single group record by id or name Keyword Args: id (str): Full Group ID name (str): Group name Raises: TypeError: Unexpected or more than one keyword argument provided ValueError: No matching group found based on provided inputs Returns: Group: Group instance matching provided inputs """ if key == 'id': response = self._swimlane.request('get', 'groups/{}'.format(value)) return Group(self._swimlane, response.json()) else: response = self._swimlane.request( 'get', 'groups/lookup?name={}'.format(value)) matched_groups = response.json() for group_data in matched_groups: if group_data.get('name') == value: return Group(self._swimlane, group_data) raise ValueError( 'Unable to find group with name "{}"'.format(value))
def list(self): """Retrieve list of all groups Returns: :class:`list` of :class:`~swimlane.core.resources.usergroup.Group`: List of all Groups """ response = self._swimlane.request('get', 'groups') return [ Group(self._swimlane, raw_group_data) for raw_group_data in response.json().get('groups', []) ]
def test_find_by_name_does_not_exist(self, mock_client): mock_client.get.return_value = [] groups = Group.find(name='Some Other Group') self.assertEqual(list(groups), [])
def test_find_by_name(self, mock_client): mock_client.get.return_value = MOCK_GROUPS groups = list(Group.find(name='Mock Group')) self.assertEqual(len(groups), 1) self.assertIsInstance(groups[0], Group)
def test_find_by_id(self, mock_client): mock_client.get.return_value = MOCK_GROUP group = Group.find(group_id='123') self.assertIsInstance(group, Group) self.assertEqual(group.id, '123')
def test_init(self): group = Group(MOCK_GROUP) for key, value in MOCK_GROUP.items(): self.assertEqual(getattr(group, key), value)