Skip to content

Commit d119ff6

Browse files
authored
Merge pull request #56 from adobe-apiplatform/v2
fix #54, fix #55: less client-side validations/defaulting
2 parents 89a4c74 + c62c7ac commit d119ff6

File tree

3 files changed

+32
-31
lines changed

3 files changed

+32
-31
lines changed

tests/test_functional.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,19 @@ def test_create_user_adobeid():
103103

104104
def test_create_user_adobeid_country():
105105
user = UserAction(email="[email protected]")
106-
with pytest.raises(ValueError):
107-
user.create(country="US")
106+
user.create(country="US")
107+
assert user.wire_dict() == {"do": [{"addAdobeID": {"email": "[email protected]",
108+
"country": "US",
109+
"option": "ignoreIfAlreadyExists"}}],
110+
"user": "[email protected]",
111+
"useAdobeID": True}
108112

109113

110114
def test_create_user_enterpriseid():
111115
user = UserAction(id_type=IdentityTypes.enterpriseID, email="[email protected]")
112116
user.create(first_name="Daniel", last_name="Brotsky")
113117
assert user.wire_dict() == {"do": [{"createEnterpriseID": {"email": "[email protected]",
114118
"firstname": "Daniel", "lastname": "Brotsky",
115-
"country": "UD",
116119
"option": "ignoreIfAlreadyExists"}}],
117120
"user": "[email protected]"}
118121

@@ -175,6 +178,14 @@ def test_create_user_federatedid_username_mismatch():
175178
user.create(first_name="Daniel", last_name="Brotsky", country="US", email="[email protected]")
176179

177180

181+
def test_update_user_adobeid():
182+
user = UserAction(id_type=IdentityTypes.adobeID, email="[email protected]")
183+
user.update(first_name="Johnny", last_name="Danger")
184+
assert user.wire_dict() == {"do": [{"update": {"firstname": "Johnny", "lastname": "Danger"}}],
185+
"user": "[email protected]",
186+
"useAdobeID": True}
187+
188+
178189
def test_update_user_federatedid():
179190
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
180191
user.update(first_name="Johnny", last_name="Danger")
@@ -192,7 +203,7 @@ def test_update_user_federatedid_unicode():
192203
def test_update_user_enterpriseid_username():
193204
user = UserAction(id_type=IdentityTypes.enterpriseID, email="[email protected]")
194205
with pytest.raises(ValueError):
195-
user.update(username="dbrotsky1")
206+
user.update(username="dbrotsky1@o.on-the-side.net")
196207

197208

198209
def test_update_user_federatedid_username():

umapi_client/functional.py

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -155,43 +155,34 @@ def create(self, first_name=None, last_name=None, country=None, email=None,
155155
:param on_conflict: IfAlreadyExistsOption (or string name thereof) controlling creation of existing users
156156
:return: the User, so you can do User(...).create(...).add_to_groups(...)
157157
"""
158-
# all types handle email and on_conflict similarly
158+
# first validate the params: email, on_conflict, first_name, last_name, country
159159
create_params = {}
160160
if email is None:
161-
email = self.email
161+
if not self.email:
162+
raise ArgumentError("You must specify email when creating a user")
162163
elif self.email is None:
163164
self._validate(email=email)
164165
self.email = email
165166
elif self.email.lower() != email.lower():
166167
raise ArgumentError("Specified email (%s) doesn't match user's email (%s)" % (email, self.email))
168+
create_params["email"] = self.email
167169
if on_conflict in IfAlreadyExistsOptions.__members__:
168170
on_conflict = IfAlreadyExistsOptions[on_conflict]
169171
if on_conflict not in IfAlreadyExistsOptions:
170172
raise ArgumentError("on_conflict must be one of {}".format([o.name for o in IfAlreadyExistsOptions]))
171173
if on_conflict != IfAlreadyExistsOptions.errorIfAlreadyExists:
172174
create_params["option"] = on_conflict.name
175+
if first_name: create_params["firstname"] = first_name # per issue #54 now allowed for all identity types
176+
if last_name: create_params["lastname"] = last_name # per issue #54 now allowed for all identity types
177+
if country: create_params["country"] = country # per issue #55 should not be defaulted
173178

174-
# each type handles the create differently
179+
# each type is created using a different call
175180
if self.id_type == IdentityTypes.adobeID:
176-
# Adobe ID doesn't allow anything but email
177-
if first_name or last_name or country:
178-
raise ArgumentError("You cannot specify first or last name or country for an Adobe ID.")
179-
return self.insert(addAdobeID=dict(email=email, **create_params))
181+
return self.insert(addAdobeID=dict(**create_params))
182+
elif self.id_type == IdentityTypes.enterpriseID:
183+
return self.insert(createEnterpriseID=dict(**create_params))
180184
else:
181-
# Federated and Enterprise allow specifying the name
182-
if first_name: create_params["firstname"] = first_name
183-
if last_name: create_params["lastname"] = last_name
184-
if self.id_type == IdentityTypes.enterpriseID:
185-
# Enterprise ID can default country, already has email on create
186-
create_params["country"] = country if country else "UD"
187-
return self.insert(createEnterpriseID=dict(email=email, **create_params))
188-
else:
189-
# Federated ID must specify email if that wasn't done already
190-
if not email:
191-
raise ArgumentError("You must specify email when creating a Federated ID")
192-
if not country:
193-
raise ArgumentError("You must specify country when creating a Federated ID")
194-
return self.insert(createFederatedID=dict(email=email, country=country, **create_params))
185+
return self.insert(createFederatedID=dict(**create_params))
195186

196187
def update(self, email=None, username=None, first_name=None, last_name=None, country=None):
197188
"""
@@ -203,11 +194,10 @@ def update(self, email=None, username=None, first_name=None, last_name=None, cou
203194
:param country: new country for this user
204195
:return: the User, so you can do User(...).update(...).add_to_groups(...)
205196
"""
206-
if self.id_type is IdentityTypes.adobeID:
207-
raise ArgumentError("You cannot update any attributes of an Adobe ID.")
208-
if email: self._validate(email=email)
209-
if username and self.id_type is IdentityTypes.enterpriseID:
210-
self._validate(email=username)
197+
if email:
198+
self._validate(email=email)
199+
if username:
200+
self._validate(username=username)
211201
updates = {}
212202
for k, v in six.iteritems(dict(email=email, username=username,
213203
firstname=first_name, lastname=last_name,

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.7"
21+
__version__ = "2.8"

0 commit comments

Comments
 (0)