Skip to content

Commit 4bfa16b

Browse files
authored
Merge pull request #26 from adobe-apiplatform/v2
Merge v2 release into master
2 parents 5f24bfd + 0ac71d9 commit 4bfa16b

File tree

8 files changed

+286
-79
lines changed

8 files changed

+286
-79
lines changed

docs/usage-instructions-v2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ users from user groups and product configuration groups. Because each
226226
operation specifier returns the user, it's easy to chain the together:
227227

228228
```python
229-
user2.add_group(groups=["Photoshop", "Illustrator"]).remove_group(groups=["CC All Apps"])
229+
user2.add_to_groups(groups=["Photoshop", "Illustrator"]).remove_from_groups(groups=["CC All Apps"])
230230
```
231231

232232
The details of all the possible commands are specified in the code,

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from setuptools import setup, find_packages
2222

2323
setup(name='umapi-client',
24-
version='2.0rc2',
24+
version='2.0',
2525
description='Client for the User Management API (UMAPI) from Adobe - see https://adobe.ly/2h1pHgV',
2626
long_description=('The User Management API (aka the UMAPI) is an Adobe-hosted network service '
2727
'which provides Adobe Enterprise customers the ability to manage their users. This '

tests/test_connections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import requests
2727

2828
from conftest import mock_connection_params, MockResponse
29-
from umapi_client import Connection, UnavailableError, ServerError, RequestError, ClientError
29+
from umapi_client import Connection, UnavailableError, ServerError, RequestError
3030

3131

3232
def test_remote_status_success():

tests/test_functional.py

Lines changed: 127 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,20 @@
2020

2121
import pytest
2222

23-
from umapi_client import IdentityTypes
24-
from umapi_client import UserAction
23+
from umapi_client import IdentityTypes, GroupTypes, RoleTypes
24+
from umapi_client import UserAction, UserGroupAction
2525

2626

2727
def test_user_emptyid():
2828
with pytest.raises(ValueError):
29-
user = UserAction(id_type=IdentityTypes.federatedID)
29+
UserAction(id_type=IdentityTypes.federatedID)
3030

3131

3232
def test_user_adobeid():
3333
user = UserAction(email="[email protected]")
34-
assert user.wire_dict() == {"do": [], "user": "[email protected]"}
34+
assert user.wire_dict() == {"do": [],
35+
"user": "[email protected]",
36+
"useAdobeID": True}
3537

3638

3739
def test_user_enterpriseid():
@@ -41,7 +43,7 @@ def test_user_enterpriseid():
4143

4244
def test_user_enterpriseid_username():
4345
with pytest.raises(ValueError):
44-
user = UserAction(id_type=IdentityTypes.enterpriseID, username="dbrotsky", domain="o.on-the-side.net")
46+
UserAction(id_type=IdentityTypes.enterpriseID, username="dbrotsky", domain="o.on-the-side.net")
4547

4648

4749
def test_user_federatedid():
@@ -58,7 +60,8 @@ def test_create_user_adobeid():
5860
user = UserAction(email="[email protected]")
5961
user.create()
6062
assert user.wire_dict() == {"do": [{"addAdobeID": {"email": "[email protected]"}}],
61-
"user": "[email protected]"}
63+
"user": "[email protected]",
64+
"useAdobeID": True}
6265

6366

6467
def test_create_user_adobeid_country():
@@ -95,7 +98,7 @@ def test_create_user_federatedid_username():
9598

9699

97100
def test_create_user_federatedid_username_email():
98-
user = UserAction(id_type=IdentityTypes.federatedID,username="dbrotsky", domain="k.on-the-side.net",
101+
user = UserAction(id_type=IdentityTypes.federatedID, username="dbrotsky", domain="k.on-the-side.net",
99102
100103
user.create(first_name="Daniel", last_name="Brotsky", country="US")
101104
assert user.wire_dict() == {"do": [{"createFederatedID": {"email": "[email protected]",
@@ -131,38 +134,77 @@ def test_update_user_federatedid_username():
131134
"user": "[email protected]"}
132135

133136

134-
def test_add_product_federatedid():
137+
def test_add_org_federatedid():
138+
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
139+
user.add_to_groups()
140+
assert user.wire_dict() == {"do": [{"add": {"product": []}}],
141+
"user": "[email protected]"}
142+
143+
144+
def test_add_products_federatedid():
135145
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
136-
user.add_group(groups=["Photoshop", "Illustrator"])
146+
user.add_to_groups(groups=["Photoshop", "Illustrator"])
137147
assert user.wire_dict() == {"do": [{"add": {"product": ["Photoshop", "Illustrator"]}}],
138148
"user": "[email protected]"}
139149

140150

141-
def test_remove_product_federatedid():
151+
def test_add_to_groups_federatedid_all():
152+
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
153+
user.add_to_groups(all_groups=True)
154+
assert user.wire_dict() == {"do": [{"add": "all"}],
155+
"user": "[email protected]"}
156+
157+
158+
def test_add_to_groups_federatedid_all_error():
159+
user = UserAction(id_type="federatedID", email="[email protected]")
160+
with pytest.raises(ValueError):
161+
user.add_to_groups(all_groups=True, groups=["Photoshop"])
162+
163+
164+
def test_add_to_usergroups_federatedid():
165+
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
166+
user.add_to_groups(groups=["Photoshop", "Illustrator"], group_type=GroupTypes.usergroup)
167+
assert user.wire_dict() == {"do": [{"add": {"usergroup": ["Photoshop", "Illustrator"]}}],
168+
"user": "[email protected]"}
169+
170+
171+
def test_remove_from_products_federatedid():
142172
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
143-
user.remove_group(groups=["Photoshop", "Illustrator"])
173+
user.remove_from_groups(groups=["Photoshop", "Illustrator"], group_type="product")
144174
assert user.wire_dict() == {"do": [{"remove": {"product": ["Photoshop", "Illustrator"]}}],
145175
"user": "[email protected]"}
146176

147177

148-
def test_remove_product_federatedid_all():
178+
def test_remove_from_groups_federatedid_all():
149179
user = UserAction(id_type='federatedID', email="[email protected]")
150-
user.remove_group(all_groups=True)
180+
user.remove_from_groups(all_groups=True)
151181
assert user.wire_dict() == {"do": [{"remove": "all"}],
152182
"user": "[email protected]"}
153183

154184

185+
def test_remove_from_groups_federatedid_all_error():
186+
user = UserAction(id_type='federatedID', email="[email protected]")
187+
with pytest.raises(ValueError):
188+
user.remove_from_groups(all_groups=True, group_type="usergroup")
189+
190+
155191
def test_add_role_enterpriseid():
156192
user = UserAction(id_type=IdentityTypes.enterpriseID, email="[email protected]")
157193
user.add_role(groups=["Photoshop", "Illustrator"])
158194
assert user.wire_dict() == {"do": [{"addRoles": {"admin": ["Photoshop", "Illustrator"]}}],
159195
"user": "[email protected]"}
160196

161197

198+
def test_add_role_enterpriseid_error():
199+
user = UserAction(id_type=IdentityTypes.enterpriseID, email="[email protected]")
200+
with pytest.raises(ValueError):
201+
user.add_role(groups=[], role_type=RoleTypes.admin)
202+
203+
162204
def test_remove_role_enterpriseid():
163205
user = UserAction(id_type='enterpriseID', email="[email protected]")
164-
user.remove_role(groups=["Photoshop", "Illustrator"])
165-
assert user.wire_dict() == {"do": [{"removeRoles": {"admin": ["Photoshop", "Illustrator"]}}],
206+
user.remove_role(groups=["Photoshop", "Illustrator"], role_type="productAdmin")
207+
assert user.wire_dict() == {"do": [{"removeRoles": {"productAdmin": ["Photoshop", "Illustrator"]}}],
166208
"user": "[email protected]"}
167209

168210

@@ -177,13 +219,14 @@ def test_remove_from_organization_adobeid():
177219
user = UserAction(id_type='adobeID', email="[email protected]")
178220
user.remove_from_organization()
179221
assert user.wire_dict() == {"do": [{"removeFromOrg": {}}],
180-
"user": "[email protected]"}
222+
"user": "[email protected]",
223+
"useAdobeID": True}
181224

182225

183226
def test_remove_from_organization_delete_federatedid():
184227
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
185228
user.remove_from_organization(delete_account=True)
186-
assert user.wire_dict() == {"do": [{"removeFromOrg": {"removedDomain": "k.on-the-side.net"}}],
229+
assert user.wire_dict() == {"do": [{"removeFromOrg": {}}, {"removeFromDomain": {}}],
187230
"user": "[email protected]"}
188231

189232

@@ -196,11 +239,77 @@ def test_remove_from_organization_delete_adobeid():
196239
def test_delete_account_enterpriseid():
197240
user = UserAction(id_type=IdentityTypes.enterpriseID, email="[email protected]")
198241
user.delete_account()
199-
assert user.wire_dict() == {"do": [{"removeFromDomain": {"domain": "o.on-the-side.net"}}],
242+
assert user.wire_dict() == {"do": [{"removeFromDomain": {}}],
200243
"user": "[email protected]"}
201244

202245

203246
def test_delete_account_adobeid():
204247
user = UserAction(id_type=IdentityTypes.adobeID, email="[email protected]")
205248
with pytest.raises(ValueError):
206249
user.delete_account()
250+
251+
252+
def test_add_to_products():
253+
group = UserGroupAction(group_name="SampleUsers")
254+
group.add_to_products(products=["Photoshop", "Illustrator"])
255+
assert group.wire_dict() == {"do": [{"add": {"product": ["Photoshop", "Illustrator"]}}],
256+
"usergroup": "SampleUsers"}
257+
258+
259+
def test_add_to_products_all():
260+
group = UserGroupAction(group_name="SampleUsers")
261+
group.add_to_products(all_products=True)
262+
assert group.wire_dict() == {"do": [{"add": "all"}],
263+
"usergroup": "SampleUsers"}
264+
265+
266+
def test_add_to_products_all_error():
267+
group = UserGroupAction(group_name="SampleUsers")
268+
with pytest.raises(ValueError):
269+
group.add_to_products(all_products=True, products=["Photoshop"])
270+
271+
272+
def test_remove_from_products():
273+
group = UserGroupAction(group_name="SampleUsers")
274+
group.remove_from_products(products=["Photoshop", "Illustrator"])
275+
assert group.wire_dict() == {"do": [{"remove": {"product": ["Photoshop", "Illustrator"]}}],
276+
"usergroup": "SampleUsers"}
277+
278+
279+
def test_remove_from_products_all():
280+
group = UserGroupAction(group_name="SampleUsers")
281+
group.remove_from_products(all_products=True)
282+
assert group.wire_dict() == {"do": [{"remove": "all"}],
283+
"usergroup": "SampleUsers"}
284+
285+
286+
def test_remove_from_products_all_error():
287+
group = UserGroupAction(group_name="SampleUsers")
288+
with pytest.raises(ValueError):
289+
group.remove_from_products(all_products=True, products=["Photoshop"])
290+
291+
292+
def test_add_users():
293+
group = UserGroupAction(group_name="SampleUsers")
294+
group.add_users(users=["[email protected]", "[email protected]"])
295+
assert group.wire_dict() == {"do": [{"add": {"user": ["[email protected]", "[email protected]"]}}],
296+
"usergroup": "SampleUsers"}
297+
298+
299+
def test_add_users_error():
300+
group = UserGroupAction(group_name="SampleUsers")
301+
with pytest.raises(ValueError):
302+
group.add_users(users=[])
303+
304+
305+
def test_remove_users():
306+
group = UserGroupAction(group_name="SampleUsers")
307+
group.remove_users(users=["[email protected]", "[email protected]"])
308+
assert group.wire_dict() == {"do": [{"remove": {"user": ["[email protected]", "[email protected]"]}}],
309+
"usergroup": "SampleUsers"}
310+
311+
312+
def test_remove_users_error():
313+
group = UserGroupAction(group_name="SampleUsers")
314+
with pytest.raises(ValueError):
315+
group.remove_users(users=[])

umapi_client/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323
from .error import ClientError, RequestError, ServerError, UnavailableError
2424
from .functional import IdentityTypes, GroupTypes, RoleTypes, IfAlreadyExistsOptions
2525
from .functional import UserAction, UserQuery, UsersQuery
26-
from .functional import GroupsQuery
26+
from .functional import UserGroupAction, GroupsQuery

umapi_client/api.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
2020

21-
import re
22-
2321
import six
2422

2523
from .connection import Connection
@@ -49,14 +47,14 @@ def split(self, max_commands):
4947
:param max_commands: max number of commands allowed in any action
5048
:return: the list of commands created from this one
5149
"""
52-
prior = Action(**self.frame)
53-
prior.commands = list(self.commands)
54-
self.split_actions = [prior]
55-
while len(prior.commands) > max_commands:
56-
next = Action(**self.frame)
57-
prior.commands, next.commands = prior.commands[0:max_commands], prior.commands[max_commands:]
58-
self.split_actions.append(next)
59-
prior = next
50+
a_prior = Action(**self.frame)
51+
a_prior.commands = list(self.commands)
52+
self.split_actions = [a_prior]
53+
while len(a_prior.commands) > max_commands:
54+
a_next = Action(**self.frame)
55+
a_prior.commands, a_next.commands = a_prior.commands[0:max_commands], a_prior.commands[max_commands:]
56+
self.split_actions.append(a_next)
57+
a_prior = a_next
6058
return self.split_actions
6159

6260
def wire_dict(self):

umapi_client/connection.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ def __init__(self,
4141
org_id,
4242
auth_dict=None,
4343
auth=None,
44-
ims_host='ims-na1.adobelogin.com',
45-
ims_endpoint_jwt='/ims/exchange/jwt/',
46-
user_management_endpoint='https://usermanagement.adobe.io/v2/usermanagement',
44+
ims_host="ims-na1.adobelogin.com",
45+
ims_endpoint_jwt="/ims/exchange/jwt/",
46+
user_management_endpoint="https://usermanagement.adobe.io/v2/usermanagement",
4747
test_mode=False,
4848
logger=logging.getLogger("umapi_client"),
4949
retry_max_attempts=4,
@@ -79,6 +79,9 @@ def __init__(self,
7979
:param retry_max_attempts: How many times to retry on temporary errors
8080
:param retry_first_delay: The time to delay first retry (grows exponentially from there)
8181
:param retry_random_delay: The max random delay to add on each exponential backoff retry
82+
:param timeout_seconds: How many seconds to wait for server response (default=60, <= 0 or None means forever)
83+
:param throttle_actions: Max number of actions to pack into a single call
84+
:param throttle_commands: Max number of commands allowed in a single action
8285
8386
Additional keywords are allowed to make it easy to pass a big dictionary with other values
8487
:param kwargs: any keywords passed that we ignore.
@@ -90,7 +93,7 @@ def __init__(self,
9093
self.retry_max_attempts = retry_max_attempts
9194
self.retry_first_delay = retry_first_delay
9295
self.retry_random_delay = retry_random_delay
93-
self.timeout = float(timeout_seconds) if float(timeout_seconds) > 0.0 else 60.0
96+
self.timeout = float(timeout_seconds) if timeout_seconds and float(timeout_seconds) > 0.0 else None
9497
self.throttle_actions = max(int(throttle_actions), 1)
9598
self.throttle_commands = max(int(throttle_commands), 1)
9699
self.action_queue = []

0 commit comments

Comments
 (0)