Skip to content

Commit

Permalink
Add get_aliases func + fix tests (#769)
Browse files Browse the repository at this point in the history
  • Loading branch information
crayolakat authored Nov 21, 2022
1 parent f0a1137 commit 9a00b10
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
15 changes: 15 additions & 0 deletions parsons/google/google_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ def _paginate_request(self, endpoint, collection, params=None):

return Table(ret)

def get_aliases(self, group_key, params=None):
"""
Get aliases for a group. `Google Admin API Documentation <https://developers.google.com/\
admin-sdk/directory/reference/rest/v1/groups.aliases/list>`_
`Args:`
group_key: str
The Google group id
params: dict
A dictionary of fields for the GET request
`Returns:`
Table Class
"""
return self._paginate_request('groups/' + group_key + '/aliases', 'aliases', params)

def get_all_group_members(self, group_key, params=None):
"""
Get all members in a group. `Google Admin API Documentation <https://developers.google.com/\
Expand Down
34 changes: 22 additions & 12 deletions test/test_google/test_google_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,45 @@ def __init__(self):


class TestGoogleAdmin(unittest.TestCase):
mock_all_group_members = Table([
{'email': '[email protected]'}, {'email': '[email protected]'},
{'email': '[email protected]'}
mock_aliases = Table([
{'alias': '[email protected]'}, {'alias': '[email protected]'}
])
mock_all_group_members = Table([{'email': '[email protected]'}])
mock_all_groups = Table([
{'email': '[email protected]', 'id': 1},
{'email': '[email protected]', 'id': 2},
{'email': '[email protected]', 'id': 3}
{
'aliases': ['[email protected]', '[email protected]'],
'email': '[email protected]', 'id': 1
},
{'aliases': None, 'email': '[email protected]', 'id': 2},
{'aliases': None, 'email': '[email protected]', 'id': 3}
])

def setUp(self):
self.google_admin = MockGoogleAdmin()

def test_aliases(self):
self.google_admin.client.request = MagicMock(return_value=(
'',
'{"aliases": [{"alias": "[email protected]"},''{"alias": "fakeemail8@fakedomain'
'.com"}]}'.encode()
))
assert_matching_tables(self.google_admin.get_aliases('1'), self.mock_aliases)

def test_all_group_members(self):
self.google_admin.client.request = MagicMock(return_value=(
'',
'{"members": [{"email": "[email protected]"}, {"email": '
'"[email protected]"}, {"email": "[email protected]"}]}'.encode()
'{"members": [{"email": "[email protected]"}]}'.encode()
))
assert_matching_tables(
self.google_admin.get_all_group_members('group_key'), self.mock_all_group_members
self.google_admin.get_all_group_members('1'), self.mock_all_group_members
)

def test_all_groups(self):
self.google_admin.client.request = MagicMock(return_value=(
'',
'{"groups": [{"email": "fakeemail4@fakedomain.com", "id": 1}, {"email": '
'"fakeemail5@fakedomain.com", "id": 2}, {"email": "fakeemail6@fakedomain.com", "id": '
'3}]}'.encode()
'{"groups": [{"aliases": ["fakeemail7@fakedomain.com", "[email protected]"], "e'
'mail": "fakeemail4@fakedomain.com", "id": 1}, {"email": "fakeemail5@fakedomain.com", "'
'id": 2}, {"email": "[email protected]", "id": 3}]}'.encode()
))
assert_matching_tables(
self.google_admin.get_all_groups({'domain': 'fakedomain.com'}), self.mock_all_groups
Expand Down

0 comments on commit 9a00b10

Please sign in to comment.