Skip to content

Commit 8b306e4

Browse files
committed
Fix #27.
* Change firstName and lastName keys to firstname and lastname on create and update. * Fix test_mode network calls to return result as expected.
1 parent 4bfa16b commit 8b306e4

File tree

6 files changed

+48
-15
lines changed

6 files changed

+48
-15
lines changed

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.0',
24+
version='2.0.1',
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,27 @@ def test_get_success():
6060
assert conn.make_call("").json() == ["test", "body"]
6161

6262

63+
def test_get_success_test_mode():
64+
with mock.patch("umapi_client.connection.requests.get") as mock_get:
65+
mock_get.return_value = MockResponse(200, body=["test", "body"])
66+
conn = Connection(test_mode=True, **mock_connection_params)
67+
assert conn.make_call("").json() == ["test", "body"]
68+
69+
6370
def test_post_success():
6471
with mock.patch("umapi_client.connection.requests.post") as mock_post:
6572
mock_post.return_value = MockResponse(200, body=["test", "body"])
6673
conn = Connection(**mock_connection_params)
6774
assert conn.make_call("", [3, 5]).json() == ["test", "body"]
6875

6976

77+
def test_post_success_test_mode():
78+
with mock.patch("umapi_client.connection.requests.post") as mock_post:
79+
mock_post.return_value = MockResponse(200, body=["test", "body"])
80+
conn = Connection(test_mode=True, **mock_connection_params)
81+
assert conn.make_call("", [3, 5]).json() == ["test", "body"]
82+
83+
7084
def test_get_timeout():
7185
with mock.patch("umapi_client.connection.requests.get") as mock_get:
7286
mock_get.side_effect = requests.Timeout

tests/test_functional.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_create_user_enterpriseid():
7474
user = UserAction(id_type=IdentityTypes.enterpriseID, email="[email protected]")
7575
user.create(first_name="Daniel", last_name="Brotsky")
7676
assert user.wire_dict() == {"do": [{"createEnterpriseID": {"email": "[email protected]",
77-
"firstName": "Daniel", "lastName": "Brotsky",
77+
"firstname": "Daniel", "lastname": "Brotsky",
7878
"country": "UD"}}],
7979
"user": "[email protected]"}
8080

@@ -83,7 +83,7 @@ def test_create_user_federatedid():
8383
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
8484
user.create(first_name="Daniel", last_name="Brotsky", country="US")
8585
assert user.wire_dict() == {"do": [{"createFederatedID": {"email": "[email protected]",
86-
"firstName": "Daniel", "lastName": "Brotsky",
86+
"firstname": "Daniel", "lastname": "Brotsky",
8787
"country": "US"}}],
8888
"user": "[email protected]"}
8989

@@ -92,7 +92,7 @@ def test_create_user_federatedid_username():
9292
user = UserAction(id_type=IdentityTypes.federatedID, username="dbrotsky", domain="k.on-the-side.net")
9393
user.create(first_name="Daniel", last_name="Brotsky", country="US", email="[email protected]")
9494
assert user.wire_dict() == {"do": [{"createFederatedID": {"email": "[email protected]",
95-
"firstName": "Daniel", "lastName": "Brotsky",
95+
"firstname": "Daniel", "lastname": "Brotsky",
9696
"country": "US"}}],
9797
"user": "dbrotsky", "domain": "k.on-the-side.net"}
9898

@@ -102,7 +102,7 @@ def test_create_user_federatedid_username_email():
102102
103103
user.create(first_name="Daniel", last_name="Brotsky", country="US")
104104
assert user.wire_dict() == {"do": [{"createFederatedID": {"email": "[email protected]",
105-
"firstName": "Daniel", "lastName": "Brotsky",
105+
"firstname": "Daniel", "lastname": "Brotsky",
106106
"country": "US"}}],
107107
"user": "dbrotsky", "domain": "k.on-the-side.net"}
108108

@@ -117,7 +117,7 @@ def test_create_user_federatedid_username_mismatch():
117117
def test_update_user_federatedid():
118118
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
119119
user.update(first_name="Johnny", last_name="Danger")
120-
assert user.wire_dict() == {"do": [{"update": {"firstName": "Johnny", "lastName": "Danger"}}],
120+
assert user.wire_dict() == {"do": [{"update": {"firstname": "Johnny", "lastname": "Danger"}}],
121121
"user": "[email protected]"}
122122

123123

tests/test_live.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,19 @@ def test_list_groups(config):
7373
assert name in params["big_groups"]
7474
logging.info("Found %d groups.", len(groups.all_results()))
7575

76-
7776
def test_get_user(config):
7877
conn, params = config
7978
user_query = umapi_client.UserQuery(conn, params["test_user"]["email"])
8079
user = user_query.result()
8180
logging.info("User: %s", user)
8281
for k, v in six.iteritems(params["test_user"]):
8382
assert user[k].lower() == v.lower()
83+
84+
def test_rename_user(config):
85+
conn, params = config
86+
user = umapi_client.UserAction(id_type=params["test_user"]["type"],
87+
email=params["test_user"]["email"],
88+
username=params["test_user"]["username"])
89+
user.update(first_name="Rodney", last_name="Danger")
90+
user.update(first_name=params["test_user"]["firstname"], last_name=params["test_user"]["lastname"])
91+
assert (0, 1, 1) == conn.execute_single(user, immediate=True)

umapi_client/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def _execute_batch(self, actions):
327327
"""
328328
wire_form = [a.wire_dict() for a in actions]
329329
if self.test_mode:
330-
result = self.make_call("/action/%s?testOnly=true" % self.org_id, wire_form).json()
330+
result = self.make_call("/action/%s?testOnly=true" % self.org_id, wire_form)
331331
else:
332332
result = self.make_call("/action/%s" % self.org_id, wire_form)
333333
body = result.json()

umapi_client/functional.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,22 @@ def _validate(email=None, username=None, domain=None):
7171
def __init__(self, id_type=IdentityTypes.adobeID, email=None, username=None, domain=None, **kwargs):
7272
"""
7373
Create an Action for a user identified either by email or by username and domain.
74-
You can specify email and username in which case the email provides the domain and is remembered
75-
for use in later commands associated with this user.
74+
You should pretty much always use just email, unless the user has a Federated ID and his
75+
username is different from his email. In that case you can give either username and email
76+
(and we'll get the domain from his email) or the username and domain (in case you don't
77+
know or don't care about the user's email).
78+
Note that the identity type determines what you can do with this user. For example,
79+
create will create a user of the specified identity type. Similarly, each identity type restricts
80+
what fields can be updated. If you are specifying an existing user by email, and you are not
81+
sure what identity type the existing user is, and you are doing something (such as add_to_groups)
82+
that can be done with any identity type, then you can specify any type, and the type you specify
83+
will be used to break ties if there is both an AdobeID and an EnterpriseID or FederatedID user
84+
with that same email. Normally, we choose Enterprise ID or Federated ID *over* Adobe ID, but
85+
if you specify the type as Adobe ID then we will act on the Adobe ID user instead.
7686
:param id_type: IdentityTypes enum value (or the name of one), defaults to adobeID
77-
:param username: string, username in the Adobe domain (might be email)
78-
:param domain: string, required if the username is not an email address
87+
:param email: The user's email. Typically this is also the user's username.
88+
:param username: The username on the Adobe side. If it's the same as email, it's ignored.
89+
:param domain: string, needed only if you specified a username but NOT an email.
7990
:param kwargs: other key/value pairs for the action, such as requestID
8091
"""
8192
if str(id_type) in IdentityTypes.__members__:
@@ -150,8 +161,8 @@ def create(self, first_name=None, last_name=None, country=None, email=None,
150161
return self.insert(addAdobeID=dict(email=str(email), **create_params))
151162
else:
152163
# Federated and Enterprise allow specifying the name
153-
if first_name: create_params["firstName"] = str(first_name)
154-
if last_name: create_params["lastName"] = str(last_name)
164+
if first_name: create_params["firstname"] = str(first_name)
165+
if last_name: create_params["lastname"] = str(last_name)
155166
if self.id_type == IdentityTypes.enterpriseID:
156167
# Enterprise ID can default country, already has email on create
157168
create_params["country"] = str(country) if country else "UD"
@@ -181,7 +192,7 @@ def update(self, email=None, username=None, first_name=None, last_name=None, cou
181192
self._validate(email=username)
182193
updates = {}
183194
for k, v in six.iteritems(dict(email=email, username=username,
184-
firstName=first_name, lastName=last_name,
195+
firstname=first_name, lastname=last_name,
185196
country=country)):
186197
if v: updates[k] = str(v)
187198
return self.append(update=updates)

0 commit comments

Comments
 (0)