Skip to content

Commit f10085b

Browse files
committed
Correct test_update_person() and update_person() per API docs
**The Cisco Spark API docs state:** “Include all details for the person. This action expects all user details to be present in the request. A common approach is to first GET the person's details, make changes, then PUT both the changed and unchanged values.” Update the test case to reflect this recommendation. Given the simple, stateless and atomic wrapping of the API calls that this package (ciscosparkapi) provides; don’t modify the package code to provide this functionality. Such stateful automations can be made in the more feature-rich ciscosparksdk package.
1 parent 3f1e52d commit f10085b

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

tests/api/test_people.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,14 @@ def create_person(api, emails, **person_attributes):
4545

4646

4747
def update_person(api, person, **person_attributes):
48-
return api.people.update(person.id, **person_attributes)
48+
# Get a copy of the person's current attributes
49+
new_attributes = person._json.copy()
50+
51+
# Merge in attribute updates
52+
for attribute, value in person_attributes.items():
53+
new_attributes[attribute] = value
54+
55+
return api.people.update(person.id, **new_attributes)
4956

5057

5158
def delete_person(api, person):
@@ -150,24 +157,16 @@ def test_create_person(self, test_people):
150157
person = test_people["not_a_member"]
151158
assert is_valid_person(person)
152159

153-
# TODO: Investigate update person API not working
154-
# def test_update_person(self, api, temp_person, roles_dict, licenses_dict,
155-
# get_new_email_address):
156-
# # Note: Not testing updating orgId
157-
# updated_attributes = {
158-
# "emails": [get_new_email_address()],
159-
# "displayName": temp_person.displayName + " Updated",
160-
# "firstName": temp_person.firstName + " Updated",
161-
# "lastName": temp_person.lastName + " Updated",
162-
# "avatar": TEST_FILE_URL,
163-
# "roles": [roles_dict["Read-only administrator"].id],
164-
# "licenses": [licenses_dict["Messaging"].id,
165-
# licenses_dict["Meeting 25 party"].id],
166-
# }
167-
# updated_person = update_person(api, temp_person, **updated_attributes)
168-
# assert is_valid_person(updated_person)
169-
# for attribute, value in updated_attributes:
170-
# assert getattr(updated_person, attribute, default=None) == value
160+
def test_update_person(self, api, temp_person):
161+
update_attributes = {
162+
"displayName": temp_person.displayName + " Updated",
163+
"firstName": temp_person.firstName + " Updated",
164+
"lastName": temp_person.lastName + " Updated",
165+
}
166+
updated_person = update_person(api, temp_person, **update_attributes)
167+
assert is_valid_person(updated_person)
168+
for attribute, value in update_attributes.items():
169+
assert getattr(updated_person, attribute) == value
171170

172171
def test_get_my_details(self, me):
173172
assert is_valid_person(me)

0 commit comments

Comments
 (0)