Skip to content

Commit 1839137

Browse files
committed
Update test suite to use new accounts
Tests have been failing because Spark is unable to "sideboard" the testing user accounts that are rapidly created (invited) but never logged into. Create a new Spark organization for the ciscosparkapi package testing, and provision the users that are regularly used by the test suite. Also, change the `temp_person` fixture to create users using random e-mail addresses created in a relatively large random range.
1 parent 6dd2f5a commit 1839137

File tree

2 files changed

+59
-19
lines changed

2 files changed

+59
-19
lines changed

tests/api/test_people.py

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@
1717

1818
# Helper Functions
1919

20-
def is_valid_person(obj):
21-
return isinstance(obj, ciscosparkapi.Person) and obj.id is not None
22-
23-
24-
def are_valid_people(iterable):
25-
return all([is_valid_person(obj) for obj in iterable])
20+
def create_person(api, emails, **person_attributes):
21+
return api.people.create(emails, **person_attributes)
2622

2723

2824
def get_person_by_id(api, id):
@@ -44,10 +40,6 @@ def get_person_by_email(api, email):
4440
return None
4541

4642

47-
def create_person(api, emails, **person_attributes):
48-
return api.people.create(emails, **person_attributes)
49-
50-
5143
def update_person(api, person, **person_attributes):
5244
# Get a copy of the person's current attributes
5345
new_attributes = person.json_data
@@ -63,14 +55,31 @@ def delete_person(api, person):
6355
api.people.delete(person.id)
6456

6557

58+
def is_valid_person(obj):
59+
return isinstance(obj, ciscosparkapi.Person) and obj.id is not None
60+
61+
62+
def are_valid_people(iterable):
63+
return all([is_valid_person(obj) for obj in iterable])
64+
65+
66+
def person_exists(api, person):
67+
try:
68+
get_person_by_id(api, person.id)
69+
except ciscosparkapi.SparkApiError:
70+
return False
71+
else:
72+
return True
73+
74+
6675
# pytest Fixtures
6776

6877
@pytest.fixture(scope="session")
6978
def me(api):
7079
return api.people.me()
7180

7281
@pytest.fixture(scope="session")
73-
def get_new_test_person(api, get_new_email_address, me, licenses_dict):
82+
def get_test_person(api, get_new_email_address, me, licenses_dict):
7483

7584
def inner_function():
7685
person_email = get_new_email_address()
@@ -95,10 +104,10 @@ def inner_function():
95104
class PeopleManager(object):
96105
"""Creates, tracks and manages test accounts 'people' used by the tests."""
97106

98-
def __init__(self, api, get_new_test_person):
107+
def __init__(self, api, get_test_person):
99108
super(PeopleManager, self).__init__()
100109
self._api = api
101-
self._get_new_test_person = get_new_test_person
110+
self._get_new_test_person = get_test_person
102111
self.test_people = {}
103112

104113
def __getitem__(self, item):
@@ -133,17 +142,37 @@ def __del__(self):
133142

134143

135144
@pytest.fixture(scope="session")
136-
def test_people(api, get_new_test_person):
137-
test_people = PeopleManager(api, get_new_test_person)
145+
def test_people(api, get_test_person):
146+
test_people = PeopleManager(api, get_test_person)
138147
yield test_people
139148
del test_people
140149

141150

142151
@pytest.fixture()
143-
def temp_person(api, get_new_test_person):
144-
person = get_new_test_person()
152+
def temp_person(api, get_random_email_address, me, licenses_dict):
153+
# Get an e-mail address not currently used on Cisco Spark
154+
person_email = None
155+
person = True
156+
while person:
157+
person_email = get_random_email_address()
158+
person = get_person_by_email(api, person_email)
159+
160+
# Create the person
161+
person = create_person(
162+
api,
163+
emails=[person_email],
164+
displayName="ciscosparkapi",
165+
firstName="ciscosparkapi",
166+
lastName="ciscosparkapi",
167+
orgId=me.orgId,
168+
licenses=[licenses_dict["Messaging"].id],
169+
)
170+
assert is_valid_person(person)
171+
145172
yield person
146-
delete_person(api, person)
173+
174+
if person_exists(api, person):
175+
delete_person(api, person)
147176

148177

149178
@pytest.fixture()

tests/conftest.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44

55
import os
6+
import random
67
import string
78
import tempfile
89

@@ -32,6 +33,7 @@
3233

3334

3435
TEST_DOMAIN = "cmlccie.com"
36+
TEST_ID_START = 91
3537
TEST_FILE_URL = "https://developer.ciscospark.com/images/[email protected]"
3638

3739

@@ -40,7 +42,7 @@
4042

4143
# Helper Functions
4244
def new_email_generator():
43-
i = 50
45+
i = TEST_ID_START
4446
while True:
4547
email_address = email_template.substitute(number=i)
4648
i += 1
@@ -75,3 +77,12 @@ def inner_function():
7577
return next(generator)
7678

7779
return inner_function
80+
81+
82+
@pytest.fixture()
83+
def get_random_email_address():
84+
def inner_function():
85+
i = random.randint(1000, 9999)
86+
return email_template.substitute(number=i)
87+
88+
return inner_function

0 commit comments

Comments
 (0)