Skip to content

Commit 43fd003

Browse files
authored
Merge pull request #35 from adobe-apiplatform/v2
v2.1 - match migration of server API.
2 parents e5123c9 + 2030322 commit 43fd003

File tree

7 files changed

+54
-26
lines changed

7 files changed

+54
-26
lines changed

HISTORY.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,12 @@ Enhancement release:
3333
* (No issue)
3434
* fix misspellings
3535
* change .gitignore so that .gitignore is not ignored
36+
37+
### Version 2.1
38+
39+
Server-compatibility release:
40+
41+
* (No Issue)
42+
* fix typos in docs
43+
* fix param documentation in functional API
44+
* update wire protocol for remove_from_organization with deletion of account to match server changes

docs/usage-instructions-v2.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ a Python dictionary of its attributes.
9696
The following code enumerates the first 5 users, printing the email of each.
9797
This will only have fetched the first page of results. Then, after the loop,
9898
the `all_results` call will force the fetch of all remaining pages so the
99-
list of all results can be constructed. ()Once the `all_results` call has been made,
99+
list of all results can be constructed. (Once the `all_results` call has been made,
100100
you cannot enumerate again without first calling `reload`.)
101101

102102
```python
103-
users = umapi_client.QueryUsers(conn)
103+
users = umapi_client.UsersQuery(conn)
104104
# print first 5 users
105105
for i, user in enumerate(users):
106106
if i == 5: break
@@ -109,13 +109,22 @@ for i, user in enumerate(users):
109109
user_count = len(users.all_results())
110110
```
111111

112+
You can also query for a particular user by email:
113+
114+
```python
115+
query = umapi_client.UserQuery(conn, "[email protected]")
116+
jruser = query.result()
117+
if jruser:
118+
name = jruser["lastname"] + ", " + jruser["firstname"]
119+
```
120+
112121
## Get a List of Groups
113122

114123
This list of groups will contain both user groups and product license
115124
configuration groups.
116125

117126
```python
118-
groups = umapi_client.QueryGroups(conn)
127+
groups = umapi_client.GroupsQuery(conn)
119128
# print all the group details
120129
for group in groups:
121130
print(group)

tests/test_functional.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,29 +216,31 @@ def test_remove_role_enterpriseid():
216216
def test_remove_from_organization_federatedid():
217217
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
218218
user.remove_from_organization()
219-
assert user.wire_dict() == {"do": [{"removeFromOrg": {}}],
219+
assert user.wire_dict() == {"do": [{"removeFromOrg": {"deleteAccount": False}}],
220220
"user": "[email protected]"}
221221

222222

223223
def test_remove_from_organization_adobeid():
224224
user = UserAction(id_type='adobeID', email="[email protected]")
225225
user.remove_from_organization()
226-
assert user.wire_dict() == {"do": [{"removeFromOrg": {}}],
226+
assert user.wire_dict() == {"do": [{"removeFromOrg": {"deleteAccount": False}}],
227227
"user": "[email protected]",
228228
"useAdobeID": True}
229229

230230

231231
def test_remove_from_organization_delete_federatedid():
232232
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
233233
user.remove_from_organization(delete_account=True)
234-
assert user.wire_dict() == {"do": [{"removeFromOrg": {}}, {"removeFromDomain": {}}],
234+
assert user.wire_dict() == {"do": [{"removeFromOrg": {"deleteAccount": True}}],
235235
"user": "[email protected]"}
236236

237237

238238
def test_remove_from_organization_delete_adobeid():
239239
user = UserAction(id_type=IdentityTypes.adobeID, email="[email protected]")
240-
with pytest.raises(ValueError):
241-
user.remove_from_organization(delete_account=True)
240+
user.remove_from_organization(delete_account=True)
241+
assert user.wire_dict() == {"do": [{"removeFromOrg": {"deleteAccount": True}}],
242+
"user": "[email protected]",
243+
"useAdobeID": True}
242244

243245

244246
def test_delete_account_enterpriseid():

tests/test_live.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,31 @@ def test_status(config):
5757
def test_list_users(config):
5858
conn, _ = config
5959
users = umapi_client.UsersQuery(connection=conn, in_domain="")
60+
user_count = 0
6061
for user in users:
6162
email = user.get("email", "")
6263
if re.match(r".*@adobe.com$", str(email).lower()):
6364
assert str(user["type"]) == "adobeID"
64-
logging.info("Found %d users.", len(users.all_results()))
65+
user_count += 1
66+
if user_count >= 2000:
67+
logging.info("Quitting enumeration after 2000 users.")
68+
break
69+
logging.info("Found %d users.", user_count)
6570

6671
def test_list_groups(config):
6772
conn, params = config
6873
groups = umapi_client.GroupsQuery(connection=conn)
74+
group_count = 0
6975
for group in groups:
7076
name = group.get("groupName")
71-
logging.debug("Group: %s", group)
72-
if group.get("memberCount", 0) > params["big_group_size"]:
73-
assert name in params["big_groups"]
74-
logging.info("Found %d groups.", len(groups.all_results()))
77+
member_count = group.get("memberCount", -1)
78+
logging.info("Group %s has %d members.", name, member_count)
79+
assert member_count >= 0
80+
group_count += 1
81+
logging.info("Found %d groups.", group_count)
82+
groups.reload()
83+
group_count_2 = len(groups.all_results())
84+
assert group_count == group_count_2
7585

7686
def test_get_user(config):
7787
conn, params = config

umapi_client/error.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ def __init__(self, attempts, seconds, result):
2929

3030
class ServerError(Exception):
3131
def __init__(self, result):
32-
Exception.__init__(self, "Server error: " + result.text)
32+
Exception.__init__(self, "Server error ({}): ".format(result.status_code) + result.text)
3333
self.result = result
3434

3535

3636
class RequestError(Exception):
3737
def __init__(self, result):
38-
Exception.__init__(self, "Request Error: " + result.text)
38+
Exception.__init__(self, "Request Error ({}): ".format(result.status_code) + result.text)
3939
self.result = result
4040

4141

umapi_client/functional.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def add_to_groups(self, groups=None, all_groups=False, group_type=None):
205205
Add user to some (typically PLC) groups. Note that, if you add to no groups, the effect
206206
is simply to do an "add to organization Everybody group", so we let that be done.
207207
:param groups: list of group names the user should be added to
208-
:param all_groups: a boolean meaning remove from all (don't specify groups or group_type in this case)
208+
:param all_groups: a boolean meaning add to all (don't specify groups or group_type in this case)
209209
:param group_type: the type of group (defaults to "product")
210210
:return: the User, so you can do User(...).add_to_groups(...).add_role(...)
211211
"""
@@ -252,8 +252,8 @@ def remove_from_groups(self, groups=None, all_groups=False, group_type=None):
252252
def add_role(self, groups=None, role_type=RoleTypes.admin):
253253
"""
254254
Make user have a role (typically PLC admin) with respect to some PLC groups.
255-
:param groups: list of group names the user should be an admin for
256-
:param role_type: the type of role (defaults to "admin")
255+
:param groups: list of group names the user should have this role for
256+
:param role_type: the role (defaults to "admin")
257257
:return: the User, so you can do User(...).add_role(...).add_to_groups(...)
258258
"""
259259
if not groups:
@@ -268,7 +268,7 @@ def add_role(self, groups=None, role_type=RoleTypes.admin):
268268
def remove_role(self, groups=None, role_type=RoleTypes.admin):
269269
"""
270270
Remove user from a role (typically admin) of some groups.
271-
:param groups: list of group names the user should NOT be an admin for
271+
:param groups: list of group names the user should NOT have this role for
272272
:param role_type: the type of role (defaults to "admin")
273273
:return: the User, so you can do User(...).remove_role(...).remove_from_groups(...)
274274
"""
@@ -288,9 +288,7 @@ def remove_from_organization(self, delete_account=False):
288288
:param delete_account: Whether to delete the account after removing from the organization (default false)
289289
:return: None, because you cannot follow this command with another.
290290
"""
291-
self.append(removeFromOrg={})
292-
if delete_account:
293-
self.delete_account()
291+
self.append(removeFromOrg={"deleteAccount": True if delete_account else False})
294292
return None
295293

296294
def delete_account(self):
@@ -356,9 +354,9 @@ def __init__(self, group_name=None, **kwargs):
356354

357355
def add_to_products(self, products=None, all_products=False):
358356
"""
359-
Add user product to some PLC products.
357+
Add user group to some product license configuration groups (PLCs), or all of them.
360358
:param products: list of product names the user should be added to
361-
:param all_products: a boolean meaning remove from all (don't specify products in this case)
359+
:param all_products: a boolean meaning add to all (don't specify products in this case)
362360
:return: the Group, so you can do Group(...).add_to_products(...).add_users(...)
363361
"""
364362
if all_products:
@@ -373,7 +371,7 @@ def add_to_products(self, products=None, all_products=False):
373371

374372
def remove_from_products(self, products=None, all_products=False):
375373
"""
376-
Remove user group from some PLC products, or all of them.
374+
Remove user group from some product license configuration groups (PLCs), or all of them.
377375
:param products: list of product names the user group should be removed from
378376
:param all_products: a boolean meaning remove from all (don't specify products in this case)
379377
:return: the Group, so you can do Group(...).remove_from_products(...).add_users(...)

umapi_client/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
2020

21-
__version__ = "2.0.3"
21+
__version__ = "2.1"

0 commit comments

Comments
 (0)