@@ -56,52 +56,52 @@ def update_person(api, person, **person_attributes):
56
56
57
57
58
58
def delete_person (api , person ):
59
- # Temporarily disabling test account deletion to workon account
60
- # capabilities issues.
61
- # TODO: Enable test account clean-up.
62
- # api.people.delete(person.id)
63
- pass
64
-
65
-
66
- def get_new_test_person (api , get_new_email_address , licenses_dict ):
67
- person_email = get_new_email_address ()
68
- person = get_person_by_email (api , person_email )
69
- if person :
70
- return person
71
- else :
72
- emails = [person_email ]
73
- display_name = "ciscosparkapi"
74
- first_name = "ciscosparkapi"
75
- last_name = "ciscosparkapi"
76
- licenses = [licenses_dict ["Messaging" ].id ]
77
- person = create_person (api , emails ,
78
- displayName = display_name ,
79
- firstName = first_name ,
80
- lastName = last_name ,
81
- licenses = licenses )
82
- assert is_valid_person (person )
83
- 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 ()
67
+
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
84
87
88
+ return inner_function
85
89
86
- # Helper Classes
87
90
88
- class TestPeople (object ):
91
+ class PeopleManager (object ):
89
92
"""Creates, tracks and manages test accounts 'people' used by the tests."""
90
93
91
- def __init__ (self , api , get_new_email_address , licenses_dict ):
92
- super (TestPeople , self ).__init__ ()
94
+ def __init__ (self , api , get_new_test_person ):
95
+ super (PeopleManager , self ).__init__ ()
93
96
self ._api = api
94
- self ._get_new_email_address = get_new_email_address
95
- self ._licenses_dict = licenses_dict
97
+ self ._get_new_test_person = get_new_test_person
96
98
self .test_people = {}
97
99
98
100
def __getitem__ (self , item ):
99
101
if self .test_people .get (item ):
100
102
return self .test_people [item ]
101
103
else :
102
- new_test_person = get_new_test_person (self ._api ,
103
- self ._get_new_email_address ,
104
- self ._licenses_dict )
104
+ new_test_person = self ._get_new_test_person ()
105
105
self .test_people [item ] = new_test_person
106
106
return new_test_person
107
107
@@ -118,26 +118,18 @@ def __iter__(self):
118
118
def __del__ (self ):
119
119
for person in self .test_people .values ():
120
120
delete_person (self ._api , person )
121
- pass
122
-
123
-
124
- # pytest Fixtures
125
-
126
- @pytest .fixture (scope = "session" )
127
- def me (api ):
128
- return api .people .me ()
129
121
130
122
131
123
@pytest .fixture (scope = "session" )
132
- def test_people (api , get_new_email_address , licenses_dict ):
133
- 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 )
134
126
yield test_people
135
127
del test_people
136
128
137
129
138
130
@pytest .fixture ()
139
- def temp_person (api , get_new_email_address , licenses_dict ):
140
- 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 ()
141
133
yield person
142
134
delete_person (api , person )
143
135
0 commit comments