Exemplo n.º 1
0
    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))
Exemplo n.º 2
0
    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', [])
        ]
Exemplo n.º 3
0
 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), [])
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
 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')
Exemplo n.º 6
0
 def test_init(self):
     group = Group(MOCK_GROUP)
     for key, value in MOCK_GROUP.items():
         self.assertEqual(getattr(group, key), value)
Exemplo n.º 7
0
 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), [])
Exemplo n.º 8
0
 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)
Exemplo n.º 9
0
 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')