Skip to content

Commit 8b29825

Browse files
committed
add CRUD for organization members
1 parent 36d0b37 commit 8b29825

2 files changed

Lines changed: 96 additions & 0 deletions

File tree

auth0/v3/management/organizations.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,50 @@ def delete_organization_connection(self, id, connection_id):
175175
"""
176176

177177
return self.client.delete(self._url(id, 'enabled_connections', connection_id))
178+
179+
# Organization Members
180+
def all_organization_members(self, id, page=None, per_page=None):
181+
"""Retrieves a list of all the organization members.
182+
183+
Args:
184+
id (str): the ID of the organization.
185+
186+
page (int): The result's page number (zero based). When not set,
187+
the default value is up to the server.
188+
189+
per_page (int, optional): The amount of entries per page. When not set,
190+
the default value is up to the server.
191+
192+
See: https://auth0.com/docs/api/management/v2#!/Clients/get_clients
193+
"""
194+
params = {}
195+
params['page'] = page
196+
params['per_page'] = per_page
197+
198+
return self.client.get(self._url(id, 'members'), params=params)
199+
200+
def create_organization_members(self, id, body):
201+
"""Adds members to an organization.
202+
203+
Args:
204+
id (str): the ID of the organization.
205+
206+
body (dict): Attributes from the members to add.
207+
208+
See: https://auth0.com/docs/api/v2#!/Clients/post_clients
209+
"""
210+
211+
return self.client.post(self._url(id, 'members'), data=body)
212+
213+
def delete_organization_members(self, id, body):
214+
"""Deletes members from the given organization.
215+
216+
Args:
217+
id (str): Id of organization.
218+
219+
body (dict): Attributes from the members to delete
220+
221+
See: https://auth0.com/docs/api/management/v2#!/Clients/delete_clients_by_id
222+
"""
223+
224+
return self.client.delete(self._url(id, 'members'), data=body)

auth0/v3/test/management/test_organizations.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,53 @@ def test_delete_organization_connection(self, mock_rc):
153153

154154
mock_instance.delete.assert_called_with(
155155
'https://domain/api/v2/organizations/test-org/enabled_connections/test-con'
156+
)
157+
158+
# Organization Connections
159+
@mock.patch('auth0.v3.management.organizations.RestClient')
160+
def test_all_organization_members(self, mock_rc):
161+
mock_instance = mock_rc.return_value
162+
163+
c = Organizations(domain='domain', token='jwttoken')
164+
165+
# Default parameters are requested
166+
c.all_organization_members('test-org')
167+
168+
args, kwargs = mock_instance.get.call_args
169+
170+
self.assertEqual('https://domain/api/v2/organizations/test-org/members', args[0])
171+
self.assertEqual(kwargs['params'], {'page': None,
172+
'per_page': None})
173+
174+
# Specific pagination
175+
c.all_organization_members('test-org', page=7, per_page=25)
176+
177+
args, kwargs = mock_instance.get.call_args
178+
179+
self.assertEqual('https://domain/api/v2/organizations/test-org/members', args[0])
180+
self.assertEqual(kwargs['params'], {'page': 7,
181+
'per_page': 25})
182+
183+
@mock.patch('auth0.v3.management.organizations.RestClient')
184+
def test_create_organization_members(self, mock_rc):
185+
mock_instance = mock_rc.return_value
186+
187+
c = Organizations(domain='domain', token='jwttoken')
188+
c.create_organization_members('test-org', {'a': 'b', 'c': 'd'})
189+
190+
mock_instance.post.assert_called_with(
191+
'https://domain/api/v2/organizations/test-org/members',
192+
data={'a': 'b', 'c': 'd'}
193+
)
194+
195+
@mock.patch('auth0.v3.management.organizations.RestClient')
196+
def test_delete_organization_members(self, mock_rc):
197+
mock_instance = mock_rc.return_value
198+
199+
c = Organizations(domain='domain', token='jwttoken')
200+
c.delete_organization_members('test-org', {'a': 'b', 'c': 'd'})
201+
202+
mock_instance.delete.assert_called_with(
203+
'https://domain/api/v2/organizations/test-org/members',
204+
data={'a': 'b', 'c': 'd'}
156205
)

0 commit comments

Comments
 (0)