Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get_aliases() function to Google Admin connector #769

Merged
merged 1 commit into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you walk me through why we need to change the tests for these other methods? Are you just doing some cleanup, or did something actually change?

'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