@@ -56,52 +56,52 @@ def update_person(api, person, **person_attributes):
5656
5757
5858def 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
8487
88+ return inner_function
8589
86- # Helper Classes
8790
88- class TestPeople (object ):
91+ class PeopleManager (object ):
8992 """Creates, tracks and manages test accounts 'people' used by the tests."""
9093
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__ ()
9396 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
9698 self .test_people = {}
9799
98100 def __getitem__ (self , item ):
99101 if self .test_people .get (item ):
100102 return self .test_people [item ]
101103 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 ()
105105 self .test_people [item ] = new_test_person
106106 return new_test_person
107107
@@ -118,26 +118,18 @@ def __iter__(self):
118118 def __del__ (self ):
119119 for person in self .test_people .values ():
120120 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 ()
129121
130122
131123@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 )
134126 yield test_people
135127 del test_people
136128
137129
138130@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 ()
141133 yield person
142134 delete_person (api , person )
143135
0 commit comments