Skip to content

Commit 0ac71d9

Browse files
committed
Fix #2 plus tweaks from testing. Release 2.0.
* Cleaned up removefromorg, removefromdomain * Added all the group types and role types * Added UserGroup actions * allowed for disabling timeouts for testing * make string delimiters consistent NOTE: Still could use doc updates for UserGroup actions.
1 parent c105957 commit 0ac71d9

File tree

8 files changed

+266
-76
lines changed

8 files changed

+266
-76
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: 107 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
import pytest
2222

2323
from umapi_client import IdentityTypes, GroupTypes, RoleTypes
24-
from umapi_client import UserAction
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():
@@ -43,7 +43,7 @@ def test_user_enterpriseid():
4343

4444
def test_user_enterpriseid_username():
4545
with pytest.raises(ValueError):
46-
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")
4747

4848

4949
def test_user_federatedid():
@@ -98,7 +98,7 @@ def test_create_user_federatedid_username():
9898

9999

100100
def test_create_user_federatedid_username_email():
101-
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",
102102
103103
user.create(first_name="Daniel", last_name="Brotsky", country="US")
104104
assert user.wire_dict() == {"do": [{"createFederatedID": {"email": "[email protected]",
@@ -134,47 +134,73 @@ def test_update_user_federatedid_username():
134134
"user": "[email protected]"}
135135

136136

137-
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():
138145
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
139-
user.add_group(groups=["Photoshop", "Illustrator"])
146+
user.add_to_groups(groups=["Photoshop", "Illustrator"])
140147
assert user.wire_dict() == {"do": [{"add": {"product": ["Photoshop", "Illustrator"]}}],
141148
"user": "[email protected]"}
142149

143150

144-
def test_add_usergroup_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():
145165
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
146-
user.add_group(groups=["Photoshop", "Illustrator"], group_type=GroupTypes.usergroup)
166+
user.add_to_groups(groups=["Photoshop", "Illustrator"], group_type=GroupTypes.usergroup)
147167
assert user.wire_dict() == {"do": [{"add": {"usergroup": ["Photoshop", "Illustrator"]}}],
148168
"user": "[email protected]"}
149169

150170

151-
def test_remove_product_federatedid():
171+
def test_remove_from_products_federatedid():
152172
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
153-
user.remove_group(groups=["Photoshop", "Illustrator"], group_type="product")
173+
user.remove_from_groups(groups=["Photoshop", "Illustrator"], group_type="product")
154174
assert user.wire_dict() == {"do": [{"remove": {"product": ["Photoshop", "Illustrator"]}}],
155175
"user": "[email protected]"}
156176

157177

158-
def test_remove_groups_federatedid_all():
178+
def test_remove_from_groups_federatedid_all():
159179
user = UserAction(id_type='federatedID', email="[email protected]")
160-
user.remove_group(all_groups=True)
180+
user.remove_from_groups(all_groups=True)
161181
assert user.wire_dict() == {"do": [{"remove": "all"}],
162182
"user": "[email protected]"}
163183

164184

165-
def test_remove_groups_federatedid_all_error():
185+
def test_remove_from_groups_federatedid_all_error():
166186
user = UserAction(id_type='federatedID', email="[email protected]")
167187
with pytest.raises(ValueError):
168-
user.remove_group(all_groups=True, group_type="usergroup")
188+
user.remove_from_groups(all_groups=True, group_type="usergroup")
169189

170190

171191
def test_add_role_enterpriseid():
172192
user = UserAction(id_type=IdentityTypes.enterpriseID, email="[email protected]")
173-
user.add_role(groups=["Photoshop", "Illustrator"], role_type=RoleTypes.admin)
193+
user.add_role(groups=["Photoshop", "Illustrator"])
174194
assert user.wire_dict() == {"do": [{"addRoles": {"admin": ["Photoshop", "Illustrator"]}}],
175195
"user": "[email protected]"}
176196

177197

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+
178204
def test_remove_role_enterpriseid():
179205
user = UserAction(id_type='enterpriseID', email="[email protected]")
180206
user.remove_role(groups=["Photoshop", "Illustrator"], role_type="productAdmin")
@@ -221,3 +247,69 @@ def test_delete_account_adobeid():
221247
user = UserAction(id_type=IdentityTypes.adobeID, email="[email protected]")
222248
with pytest.raises(ValueError):
223249
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)