3
3
"""pytest People functions, fixtures and tests."""
4
4
5
5
6
+ import itertools
7
+
6
8
import pytest
7
9
8
10
import ciscosparkapi
@@ -22,8 +24,12 @@ def get_person_by_id(api, id):
22
24
return api .people .get (id )
23
25
24
26
27
+ def list_people (api , ** search_attribute ):
28
+ return list (api .people .list (** search_attribute ))
29
+
30
+
25
31
def 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 )
27
33
if list_of_people :
28
34
# If found, there should only be one Spark account associated with an
29
35
# single e-mail address.
@@ -37,6 +43,10 @@ def create_person(api, emails, **person_attributes):
37
43
return api .people .create (emails , ** person_attributes )
38
44
39
45
46
+ def update_person (api , person , ** person_attributes ):
47
+ return api .people .update (person .id , ** person_attributes )
48
+
49
+
40
50
def delete_person (api , person ):
41
51
api .people .delete (person .id )
42
52
@@ -83,11 +93,15 @@ def __getitem__(self, item):
83
93
self .test_people [item ] = new_test_person
84
94
return new_test_person
85
95
96
+ @property
86
97
def list (self ):
87
98
return self .test_people .values ()
88
99
100
+ def len (self ):
101
+ return len (self .list )
102
+
89
103
def __iter__ (self ):
90
- return iter (self .list () )
104
+ return iter (self .list )
91
105
92
106
def __del__ (self ):
93
107
for person in self .test_people .values ():
@@ -104,14 +118,14 @@ def me(api):
104
118
105
119
@pytest .fixture (scope = "session" )
106
120
def test_people (api , get_new_email_address , licenses_dict ):
107
- test_people = TestPeople ()
121
+ test_people = TestPeople (api , get_new_email_address , licenses_dict )
108
122
yield test_people
109
- del ( test_people )
123
+ del test_people
110
124
111
125
112
126
@pytest .fixture ()
113
127
def 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 )
115
129
yield person
116
130
delete_person (api , person )
117
131
@@ -120,3 +134,58 @@ def temp_person(api, get_new_email_address, licenses_dict):
120
134
def people_in_group_room (api , group_room_memberships ):
121
135
return [get_person_by_id (api , membership .personId )
122
136
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