@@ -45,56 +45,63 @@ def create_person(api, emails, **person_attributes):
4545
4646
4747def 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
5158def delete_person (api , person ):
52- # Temporarily disabling test account deletion to workon account
53- # capabilities issues.
54- # TODO: Enable test account clean-up.
55- # api.people.delete(person.id)
56- pass
57-
58-
59- def get_new_test_person (api , get_new_email_address , licenses_dict ):
60- person_email = get_new_email_address ()
61- person = get_person_by_email (api , person_email )
62- if person :
63- return person
64- else :
65- emails = [person_email ]
66- display_name = "ciscosparkapi"
67- first_name = "ciscosparkapi"
68- last_name = "ciscosparkapi"
69- licenses = [licenses_dict ["Messaging" ].id ]
70- person = create_person (api , emails ,
71- displayName = display_name ,
72- firstName = first_name ,
73- lastName = last_name ,
74- licenses = licenses )
75- assert is_valid_person (person )
76- return person
59+ api .people .delete (person .id )
60+
61+
62+ # pytest Fixtures
63+
64+ @pytest .fixture (scope = "session" )
65+ def me (api ):
66+ return api .people .me ()
7767
68+ @pytest .fixture (scope = "session" )
69+ def get_new_test_person (api , get_new_email_address , me , licenses_dict ):
70+
71+ def inner_function ():
72+ person_email = get_new_email_address ()
73+ person = get_person_by_email (api , person_email )
74+ if person :
75+ return person
76+ else :
77+ person = create_person (api ,
78+ emails = [person_email ],
79+ displayName = "ciscosparkapi" ,
80+ firstName = "ciscosparkapi" ,
81+ lastName = "ciscosparkapi" ,
82+ orgId = me .orgId ,
83+ licenses = [licenses_dict ["Messaging" ].id ],
84+ )
85+ assert is_valid_person (person )
86+ return person
7887
79- # Helper Classes
88+ return inner_function
8089
81- class TestPeople (object ):
90+
91+ class PeopleManager (object ):
8292 """Creates, tracks and manages test accounts 'people' used by the tests."""
8393
84- def __init__ (self , api , get_new_email_address , licenses_dict ):
85- super (TestPeople , self ).__init__ ()
94+ def __init__ (self , api , get_new_test_person ):
95+ super (PeopleManager , self ).__init__ ()
8696 self ._api = api
87- self ._get_new_email_address = get_new_email_address
88- self ._licenses_dict = licenses_dict
97+ self ._get_new_test_person = get_new_test_person
8998 self .test_people = {}
9099
91100 def __getitem__ (self , item ):
92101 if self .test_people .get (item ):
93102 return self .test_people [item ]
94103 else :
95- new_test_person = get_new_test_person (self ._api ,
96- self ._get_new_email_address ,
97- self ._licenses_dict )
104+ new_test_person = self ._get_new_test_person ()
98105 self .test_people [item ] = new_test_person
99106 return new_test_person
100107
@@ -111,26 +118,18 @@ def __iter__(self):
111118 def __del__ (self ):
112119 for person in self .test_people .values ():
113120 delete_person (self ._api , person )
114- pass
115-
116-
117- # pytest Fixtures
118-
119- @pytest .fixture (scope = "session" )
120- def me (api ):
121- return api .people .me ()
122121
123122
124123@pytest .fixture (scope = "session" )
125- def test_people (api , get_new_email_address , licenses_dict ):
126- test_people = TestPeople (api , get_new_email_address , licenses_dict )
124+ def test_people (api , get_new_test_person ):
125+ test_people = PeopleManager (api , get_new_test_person )
127126 yield test_people
128127 del test_people
129128
130129
131130@pytest .fixture ()
132- def temp_person (api , get_new_email_address , licenses_dict ):
133- person = get_new_test_person (api , get_new_email_address , licenses_dict )
131+ def temp_person (api , get_new_test_person ):
132+ person = get_new_test_person ()
134133 yield person
135134 delete_person (api , person )
136135
@@ -150,24 +149,16 @@ def test_create_person(self, test_people):
150149 person = test_people ["not_a_member" ]
151150 assert is_valid_person (person )
152151
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
152+ def test_update_person (self , api , temp_person ):
153+ update_attributes = {
154+ "displayName" : temp_person .displayName + " Updated" ,
155+ "firstName" : temp_person .firstName + " Updated" ,
156+ "lastName" : temp_person .lastName + " Updated" ,
157+ }
158+ updated_person = update_person (api , temp_person , ** update_attributes )
159+ assert is_valid_person (updated_person )
160+ for attribute , value in update_attributes .items ():
161+ assert getattr (updated_person , attribute ) == value
171162
172163 def test_get_my_details (self , me ):
173164 assert is_valid_person (me )
0 commit comments