Skip to content

Commit e6c7780

Browse files
authored
Merge pull request #42 from adobe-apiplatform/v2
Fix #41: handle unicode strings in Python 2.7. Prep for release of v2.4.
2 parents c37a958 + d9e2dd2 commit e6c7780

File tree

4 files changed

+154
-39
lines changed

4 files changed

+154
-39
lines changed

HISTORY.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,11 @@ Enhancement release:
6262
* document all accepted `auth_dict` keys
6363
* (No Issue)
6464
* certify for Python 3.6
65+
66+
### Version 2.4
67+
68+
Bug fix release:
69+
70+
* [Issue 41](https://github.com/adobe-apiplatform/umapi-client.py/issues/41)
71+
* accept unicode strings from Python 2.7 clients
72+
* do unicode-compliant validation of usernames and email addresses

tests/test_functional.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# coding: utf-8
2+
13
# Copyright (c) 2016-2017 Adobe Systems Incorporated. All rights reserved.
24
#
35
# Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -36,11 +38,33 @@ def test_user_adobeid():
3638
"useAdobeID": True}
3739

3840

41+
def test_user_adobeid_unicode():
42+
user = UserAction(email=u"lwałę[email protected]")
43+
assert user.wire_dict() == {"do": [],
44+
"user": u"lwałę[email protected]",
45+
"useAdobeID": True}
46+
47+
48+
def test_user_adobeid_unicode_error_trailing_dot():
49+
with pytest.raises(ValueError):
50+
UserAction(email=u"lwałę[email protected]")
51+
52+
53+
def test_user_adobeid_unicode_error_unicode_dot_above():
54+
with pytest.raises(ValueError):
55+
UserAction(email=u"l˙wałę[email protected]")
56+
57+
3958
def test_user_enterpriseid():
4059
user = UserAction(id_type=IdentityTypes.enterpriseID, email="[email protected]")
4160
assert user.wire_dict() == {"do": [], "user": "[email protected]"}
4261

4362

63+
def test_user_enterpriseid_unicode():
64+
user = UserAction(id_type=IdentityTypes.enterpriseID, email=u"lwałę[email protected]")
65+
assert user.wire_dict() == {"do": [], "user": u"lwałę[email protected]"}
66+
67+
4468
def test_user_enterpriseid_username():
4569
with pytest.raises(ValueError):
4670
UserAction(id_type=IdentityTypes.enterpriseID, username="dbrotsky", domain="o.on-the-side.net")
@@ -51,11 +75,21 @@ def test_user_federatedid():
5175
assert user.wire_dict() == {"do": [], "user": "[email protected]"}
5276

5377

78+
def test_user_federatedid_unicode():
79+
user = UserAction(id_type=IdentityTypes.federatedID, email=u"lwałę[email protected]")
80+
assert user.wire_dict() == {"do": [], "user": u"lwałę[email protected]"}
81+
82+
5483
def test_user_federatedid_username():
5584
user = UserAction(id_type=IdentityTypes.federatedID, username="dbrotsky", domain="k.on-the-side.net")
5685
assert user.wire_dict() == {"do": [], "user": "dbrotsky", "domain": "k.on-the-side.net"}
5786

5887

88+
def test_user_federatedid_username_unicode():
89+
user = UserAction(id_type=IdentityTypes.federatedID, username=u"lwałęsa", domain="k.on-the-side.net")
90+
assert user.wire_dict() == {"do": [], "user": u"lwałęsa", "domain": "k.on-the-side.net"}
91+
92+
5993
def test_create_user_adobeid():
6094
user = UserAction(email="[email protected]")
6195
user.create()
@@ -91,6 +125,16 @@ def test_create_user_federatedid():
91125
"user": "[email protected]"}
92126

93127

128+
def test_create_user_federated_id_unicode():
129+
user = UserAction(id_type=IdentityTypes.federatedID, email=u"lwałę[email protected]")
130+
user.create(first_name="Lech", last_name=u"Wałęsa", country="PL")
131+
assert user.wire_dict() == {"do": [{"createFederatedID": {"email": u"lwałę[email protected]",
132+
"firstname": "Lech", "lastname": u"Wałęsa",
133+
"country": "PL",
134+
"option": "ignoreIfAlreadyExists"}}],
135+
"user": u"lwałę[email protected]"}
136+
137+
94138
def test_create_user_federatedid_username():
95139
user = UserAction(id_type=IdentityTypes.federatedID, username="dbrotsky", domain="k.on-the-side.net")
96140
user.create(first_name="Daniel", last_name="Brotsky", country="US", email="[email protected]")
@@ -101,6 +145,16 @@ def test_create_user_federatedid_username():
101145
"user": "dbrotsky", "domain": "k.on-the-side.net"}
102146

103147

148+
def test_create_user_federatedid_username_unicode():
149+
user = UserAction(id_type=IdentityTypes.federatedID, username=u"lwałęsa", domain="k.on-the-side.net")
150+
user.create(first_name="Lech", last_name=u"Wałęsa", country="PL", email=u"lwałę[email protected]")
151+
assert user.wire_dict() == {"do": [{"createFederatedID": {"email": u"lwałę[email protected]",
152+
"firstname": "Lech", "lastname": u"Wałęsa",
153+
"country": "PL",
154+
"option": "ignoreIfAlreadyExists"}}],
155+
"user": u"lwałęsa", "domain": "k.on-the-side.net"}
156+
157+
104158
def test_create_user_federatedid_username_email():
105159
user = UserAction(id_type=IdentityTypes.federatedID, username="dbrotsky", domain="k.on-the-side.net",
106160
@@ -126,6 +180,13 @@ def test_update_user_federatedid():
126180
"user": "[email protected]"}
127181

128182

183+
def test_update_user_federatedid_unicode():
184+
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
185+
user.update(first_name=u"André", last_name="Danger")
186+
assert user.wire_dict() == {"do": [{"update": {"firstname": u"André", "lastname": "Danger"}}],
187+
"user": "[email protected]"}
188+
189+
129190
def test_update_user_enterpriseid_username():
130191
user = UserAction(id_type=IdentityTypes.enterpriseID, email="[email protected]")
131192
with pytest.raises(ValueError):
@@ -153,6 +214,13 @@ def test_add_products_federatedid():
153214
"user": "[email protected]"}
154215

155216

217+
def test_add_products_federatedid_unicode():
218+
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
219+
user.add_to_groups(groups=["Photoshop", u"Người vẽ minh hoạ"])
220+
assert user.wire_dict() == {"do": [{"add": {"product": ["Photoshop", u"Người vẽ minh hoạ"]}}],
221+
"user": "[email protected]"}
222+
223+
156224
def test_add_to_groups_federatedid_all():
157225
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
158226
user.add_to_groups(all_groups=True)
@@ -173,6 +241,13 @@ def test_add_to_usergroups_federatedid():
173241
"user": "[email protected]"}
174242

175243

244+
def test_add_to_usergroups_federatedid_unicode():
245+
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
246+
user.add_to_groups(groups=["Photoshop", u"Người vẽ minh hoạ"], group_type=GroupTypes.usergroup)
247+
assert user.wire_dict() == {"do": [{"add": {"usergroup": ["Photoshop", u"Người vẽ minh hoạ"]}}],
248+
"user": "[email protected]"}
249+
250+
176251
def test_remove_from_products_federatedid():
177252
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
178253
user.remove_from_groups(groups=["Photoshop", "Illustrator"], group_type="product")
@@ -200,6 +275,13 @@ def test_add_role_enterpriseid():
200275
"user": "[email protected]"}
201276

202277

278+
def test_add_role_enterpriseid_unicode():
279+
user = UserAction(id_type=IdentityTypes.enterpriseID, email="[email protected]")
280+
user.add_role(groups=[u"người quản lý"])
281+
assert user.wire_dict() == {"do": [{"addRoles": {"admin": [u"người quản lý"]}}],
282+
"user": "[email protected]"}
283+
284+
203285
def test_add_role_enterpriseid_error():
204286
user = UserAction(id_type=IdentityTypes.enterpriseID, email="[email protected]")
205287
with pytest.raises(ValueError):
@@ -228,6 +310,14 @@ def test_remove_from_organization_adobeid():
228310
"useAdobeID": True}
229311

230312

313+
def test_remove_from_organization_adobeid_unicode():
314+
user = UserAction(id_type='adobeID', email=u"lwałę[email protected]")
315+
user.remove_from_organization()
316+
assert user.wire_dict() == {"do": [{"removeFromOrg": {"deleteAccount": False}}],
317+
"user": u"lwałę[email protected]",
318+
"useAdobeID": True}
319+
320+
231321
def test_remove_from_organization_delete_federatedid():
232322
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
233323
user.remove_from_organization(delete_account=True)
@@ -303,6 +393,13 @@ def test_add_users():
303393
"usergroup": "SampleUsers"}
304394

305395

396+
def test_add_users_unicode():
397+
group = UserGroupAction(group_name=u"người quản lý")
398+
group.add_users(users=[u"lwałę[email protected]", u"tkolář@test1.on-the-side.net"])
399+
assert group.wire_dict() == {"do": [{"add": {"user": [u"lwałę[email protected]", u"tkolář@test1.on-the-side.net"]}}],
400+
"usergroup": u"người quản lý"}
401+
402+
306403
def test_add_users_error():
307404
group = UserGroupAction(group_name="SampleUsers")
308405
with pytest.raises(ValueError):

0 commit comments

Comments
 (0)