33"""pytest People functions, fixtures and tests."""
44
55
6+ import itertools
7+
68import pytest
79
810import ciscosparkapi
@@ -22,8 +24,12 @@ def get_person_by_id(api, id):
2224 return api .people .get (id )
2325
2426
27+ def list_people (api , ** search_attribute ):
28+ return list (api .people .list (** search_attribute ))
29+
30+
2531def get_person_by_email (api , email ):
26- list_of_people = list (api . people . list ( email = email ) )
32+ list_of_people = list_people (api , email = email )
2733 if list_of_people :
2834 # If found, there should only be one Spark account associated with an
2935 # single e-mail address.
@@ -37,6 +43,10 @@ def create_person(api, emails, **person_attributes):
3743 return api .people .create (emails , ** person_attributes )
3844
3945
46+ def update_person (api , person , ** person_attributes ):
47+ return api .people .update (person .id , ** person_attributes )
48+
49+
4050def delete_person (api , person ):
4151 api .people .delete (person .id )
4252
@@ -83,11 +93,15 @@ def __getitem__(self, item):
8393 self .test_people [item ] = new_test_person
8494 return new_test_person
8595
96+ @property
8697 def list (self ):
8798 return self .test_people .values ()
8899
100+ def len (self ):
101+ return len (self .list )
102+
89103 def __iter__ (self ):
90- return iter (self .list () )
104+ return iter (self .list )
91105
92106 def __del__ (self ):
93107 for person in self .test_people .values ():
@@ -104,14 +118,14 @@ def me(api):
104118
105119@pytest .fixture (scope = "session" )
106120def test_people (api , get_new_email_address , licenses_dict ):
107- test_people = TestPeople ()
121+ test_people = TestPeople (api , get_new_email_address , licenses_dict )
108122 yield test_people
109- del ( test_people )
123+ del test_people
110124
111125
112126@pytest .fixture ()
113127def temp_person (api , get_new_email_address , licenses_dict ):
114- person = get_new_test_person (api , get_new_email_address , licenses_dict )
128+ person = get_new_test_person (api , get_new_email_address , licenses_dict )
115129 yield person
116130 delete_person (api , person )
117131
@@ -120,3 +134,58 @@ def temp_person(api, get_new_email_address, licenses_dict):
120134def people_in_group_room (api , group_room_memberships ):
121135 return [get_person_by_id (api , membership .personId )
122136 for membership in group_room_memberships ]
137+
138+
139+ # Tests
140+
141+ class TestPeopleAPI (object ):
142+ """Test PeopleAPI methods."""
143+
144+ def test_create_person (self , test_people ):
145+ person = test_people ["not_a_member" ]
146+ assert is_valid_person (person )
147+
148+ def test_update_person (self , api , test_people ):
149+ person = test_people ["not_a_member" ]
150+ # TODO: Verify attributes that can be updated
151+ updated_attributes = {
152+ "displayName" : person .displayName + " Updated" ,
153+ "firstName" : person .firstName + " Updated" ,
154+ "lastName" : person .lastName + " Updated" ,
155+ }
156+ updated_person = update_person (api , person , ** updated_attributes )
157+ assert is_valid_person (updated_person )
158+ for attribute , value in updated_attributes :
159+ assert getattr (updated_person , attribute , default = None ) == value
160+
161+ def test_get_my_details (self , me ):
162+ assert is_valid_person (me )
163+
164+ def test_get_person_details (self , api , test_people ):
165+ person_id = test_people ["not_a_member" ].id
166+ person = get_person_by_id (api , person_id )
167+ assert is_valid_person (person )
168+
169+ def test_list_people_by_email (self , api , test_people ):
170+ email = test_people ["not_a_member" ].emails [0 ]
171+ list_of_people = list_people (api , email = email )
172+ assert len (list_of_people ) >= 1
173+ assert are_valid_people (list_of_people )
174+
175+ def test_list_people_by_display_name (self , api , test_people ):
176+ display_name = test_people ["not_a_member" ].displayName
177+ list_of_people = list_people (api , displayName = display_name )
178+ assert len (list_of_people ) >= 1
179+ assert are_valid_people (list_of_people )
180+
181+ def test_list_people_with_paging (self , api , test_people ,
182+ additional_group_room_memberships ):
183+ page_size = 1
184+ pages = 3
185+ num_people = pages * page_size
186+ assert len (test_people ) >= num_people
187+ display_name = test_people ["not_a_member" ].displayName
188+ people = api .people .list (displayName = display_name , max = page_size )
189+ people_list = list (itertools .islice (people , num_people ))
190+ assert len (people_list ) == num_people
191+ assert are_valid_people (people_list )
0 commit comments