Skip to content

Commit ccf87a0

Browse files
committed
finish the local testing: this fixes #10 completely.
Now we just need some live testing of the functional stuff and we are at beta1.
1 parent 66260d2 commit ccf87a0

File tree

5 files changed

+252
-72
lines changed

5 files changed

+252
-72
lines changed

tests/test_functional.py

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
# Copyright (c) 2016 Adobe Systems Incorporated. All rights reserved.
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to deal
5+
# in the Software without restriction, including without limitation the rights
6+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
# copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in all
11+
# copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
# SOFTWARE.
20+
21+
import pytest
22+
23+
from umapi_client import IdentityTypes
24+
from umapi_client import UserAction
25+
26+
27+
def test_user_adobeid():
28+
user = UserAction(email="[email protected]")
29+
assert user.wire_dict() == {"do": [], "user": "[email protected]"}
30+
31+
32+
def test_user_enterpriseid():
33+
user = UserAction(id_type=IdentityTypes.enterpriseID, email="[email protected]")
34+
assert user.wire_dict() == {"do": [], "user": "[email protected]"}
35+
36+
37+
def test_user_enterpriseid_username():
38+
with pytest.raises(ValueError):
39+
user = UserAction(id_type=IdentityTypes.enterpriseID, username="dbrotsky", domain="o.on-the-side.net")
40+
41+
42+
def test_user_federatedid():
43+
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
44+
assert user.wire_dict() == {"do": [], "user": "[email protected]"}
45+
46+
47+
def test_user_federatedid_username():
48+
user = UserAction(id_type=IdentityTypes.federatedID, username="dbrotsky", domain="k.on-the-side.net")
49+
assert user.wire_dict() == {"do": [], "user": "dbrotsky", "domain": "k.on-the-side.net"}
50+
51+
52+
def test_create_user_adobeid():
53+
user = UserAction(email="[email protected]")
54+
user.create()
55+
assert user.wire_dict() == {"do": [{"addAdobeID": {"email": "[email protected]"}}],
56+
"user": "[email protected]"}
57+
58+
59+
def test_create_user_adobeid_country():
60+
user = UserAction(email="[email protected]")
61+
with pytest.raises(ValueError):
62+
user.create(country="US")
63+
64+
65+
def test_create_user_enterpriseid():
66+
user = UserAction(id_type=IdentityTypes.enterpriseID, email="[email protected]")
67+
user.create(first_name="Daniel", last_name="Brotsky")
68+
assert user.wire_dict() == {"do": [{"createEnterpriseID": {"email": "[email protected]",
69+
"firstName": "Daniel", "lastName": "Brotsky",
70+
"country": "UD"}}],
71+
"user": "[email protected]"}
72+
73+
74+
def test_create_user_federatedid():
75+
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
76+
user.create(first_name="Daniel", last_name="Brotsky", country="US")
77+
assert user.wire_dict() == {"do": [{"createFederatedID": {"email": "[email protected]",
78+
"firstName": "Daniel", "lastName": "Brotsky",
79+
"country": "US"}}],
80+
"user": "[email protected]"}
81+
82+
83+
def test_create_user_federatedid_username():
84+
user = UserAction(id_type=IdentityTypes.federatedID, username="dbrotsky", domain="k.on-the-side.net")
85+
user.create(first_name="Daniel", last_name="Brotsky", country="US", email="[email protected]")
86+
assert user.wire_dict() == {"do": [{"createFederatedID": {"email": "[email protected]",
87+
"firstName": "Daniel", "lastName": "Brotsky",
88+
"country": "US"}}],
89+
"user": "dbrotsky", "domain": "k.on-the-side.net"}
90+
91+
92+
def test_create_user_federatedid_username_mismatch():
93+
user = UserAction(id_type=IdentityTypes.federatedID, username="dbrotsky", domain="k.on-the-side.net")
94+
with pytest.raises(ValueError):
95+
user.create(first_name="Daniel", last_name="Brotsky", country="US", email="[email protected]")
96+
97+
98+
def test_update_user_federatedid():
99+
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
100+
user.update(first_name="Johnny", last_name="Danger")
101+
assert user.wire_dict() == {"do": [{"update": {"firstName": "Johnny", "lastName": "Danger"}}],
102+
"user": "[email protected]"}
103+
104+
105+
def test_update_user_enterpriseid_username():
106+
user = UserAction(id_type=IdentityTypes.enterpriseID, email="[email protected]")
107+
with pytest.raises(ValueError):
108+
user.update(username="dbrotsky1")
109+
110+
111+
def test_update_user_federatedid_username():
112+
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
113+
user.update(username="dbrotsky1")
114+
assert user.wire_dict() == {"do": [{"update": {"username": "dbrotsky1"}}],
115+
"user": "[email protected]"}
116+
117+
118+
def test_add_product_federatedid():
119+
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
120+
user.add_group(groups=["Photoshop", "Illustrator"])
121+
assert user.wire_dict() == {"do": [{"add": {"product": ["Photoshop", "Illustrator"]}}],
122+
"user": "[email protected]"}
123+
124+
125+
def test_remove_product_federatedid():
126+
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
127+
user.remove_group(groups=["Photoshop", "Illustrator"])
128+
assert user.wire_dict() == {"do": [{"remove": {"product": ["Photoshop", "Illustrator"]}}],
129+
"user": "[email protected]"}
130+
131+
132+
def test_remove_product_federatedid_all():
133+
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
134+
user.remove_group(all_groups=True)
135+
assert user.wire_dict() == {"do": [{"remove": "all"}],
136+
"user": "[email protected]"}
137+
138+
139+
def test_add_role_enterpriseid():
140+
user = UserAction(id_type=IdentityTypes.enterpriseID, email="[email protected]")
141+
user.add_role(groups=["Photoshop", "Illustrator"])
142+
assert user.wire_dict() == {"do": [{"addRoles": {"admin": ["Photoshop", "Illustrator"]}}],
143+
"user": "[email protected]"}
144+
145+
146+
def test_remove_role_enterpriseid():
147+
user = UserAction(id_type=IdentityTypes.enterpriseID, email="[email protected]")
148+
user.remove_role(groups=["Photoshop", "Illustrator"])
149+
assert user.wire_dict() == {"do": [{"removeRoles": {"admin": ["Photoshop", "Illustrator"]}}],
150+
"user": "[email protected]"}
151+
152+
153+
def test_remove_from_organization_federatedid():
154+
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
155+
user.remove_from_organization()
156+
assert user.wire_dict() == {"do": [{"removeFromOrg": {}}],
157+
"user": "[email protected]"}
158+
159+
160+
def test_remove_from_organization_adobeid():
161+
user = UserAction(id_type=IdentityTypes.adobeID, email="[email protected]")
162+
user.remove_from_organization()
163+
assert user.wire_dict() == {"do": [{"removeFromOrg": {}}],
164+
"user": "[email protected]"}
165+
166+
167+
def test_remove_from_organization_delete_federatedid():
168+
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
169+
user.remove_from_organization(delete_account=True)
170+
assert user.wire_dict() == {"do": [{"removeFromOrg": {"removedDomain": "k.on-the-side.net"}}],
171+
"user": "[email protected]"}
172+
173+
174+
def test_remove_from_organization_delete_adobeid():
175+
user = UserAction(id_type=IdentityTypes.adobeID, email="[email protected]")
176+
with pytest.raises(ValueError):
177+
user.remove_from_organization(delete_account=True)
178+
179+
180+
def test_delete_account_enterpriseid():
181+
user = UserAction(id_type=IdentityTypes.enterpriseID, email="[email protected]")
182+
user.delete_account()
183+
assert user.wire_dict() == {"do": [{"removeFromDomain": {"domain": "o.on-the-side.net"}}],
184+
"user": "[email protected]"}
185+
186+
187+
def test_delete_account_adobeid():
188+
user = UserAction(id_type=IdentityTypes.adobeID, email="[email protected]")
189+
with pytest.raises(ValueError):
190+
user.delete_account()

umapi_client/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
from .connection import Connection
2222
from .api import Action, QuerySingle, QueryMultiple
23-
from .users import UserAction, UserQuery, UsersQuery, IdentityTypes, GroupTypes, RoleTypes, IfAlreadyExistsOptions
24-
from .groups import GroupsQuery
2523
from .error import ClientError, RequestError, ServerError, UnavailableError
24+
from .functional import IdentityTypes, GroupTypes, RoleTypes, IfAlreadyExistsOptions
25+
from .functional import UserAction, UserQuery, UsersQuery
26+
from .functional import GroupsQuery

umapi_client/connection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __init__(self,
8181
:param retry_random_delay: The max random delay to add on each exponential backoff retry
8282
8383
Additional keywords are allowed to make it easy to pass a big dictionary with other values
84-
:param kwargs:
84+
:param kwargs: any keywords passed that we ignore.
8585
"""
8686
self.org_id = str(org_id)
8787
self.endpoint = user_management_endpoint
@@ -133,7 +133,6 @@ def status(self, remote=False):
133133
as well as data about version and build. The server data is
134134
cached, unless the remote flag is specified.
135135
136-
:param local: whether to include the local status in the return
137136
:param remote: whether to query the server for its latest status
138137
:return: tuple of status dicts: (local, server).
139138
"""
@@ -359,6 +358,7 @@ def call():
359358
return requests.get(self.endpoint + path, auth=self.auth, timeout=self.timeout)
360359

361360
total_time = wait_time = 0
361+
result = None
362362
for num_attempts in range(1, self.retry_max_attempts + 1):
363363
if wait_time > 0:
364364
sleep(wait_time)
@@ -368,7 +368,7 @@ def call():
368368
result = call()
369369
except requests.Timeout:
370370
total_time += int(self.timeout)
371-
raise UnavailableError(num_attempts, total_time, None)
371+
raise UnavailableError(num_attempts, total_time, result)
372372
if result.status_code == 200:
373373
return result
374374
elif result.status_code in [429, 502, 503, 504]:

0 commit comments

Comments
 (0)