Skip to content

Commit 577ff33

Browse files
committed
Initial TeamsAPI tests
1 parent 9bbbd0e commit 577ff33

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

tests/api/test_teams.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"""pytest Team functions, fixtures and tests."""
44

55

6+
import itertools
7+
68
import pytest
79

810
import ciscosparkapi
@@ -15,14 +17,105 @@ def create_team(api, name):
1517
return api.teams.create(name)
1618

1719

20+
def get_team_details_by_id(self, api, team_id):
21+
team = api.teams.get(team_id)
22+
return team
23+
24+
1825
def delete_team(api, team):
1926
api.teams.delete(team.id)
2027

2128

29+
def is_valid_team(obj):
30+
return isinstance(obj, ciscosparkapi.Team) and obj.id is not None
31+
32+
33+
def are_valid_teams(iterable):
34+
return all([is_valid_team(obj) for obj in iterable])
35+
36+
37+
def team_exists(api, team):
38+
try:
39+
get_team_details_by_id(api, team.id)
40+
except ciscosparkapi.SparkApiError:
41+
return False
42+
else:
43+
return True
44+
45+
46+
2247
# pytest Fixtures
2348

2449
@pytest.fixture(scope="session")
2550
def team(api):
2651
team = create_team(api, create_string("Team"))
2752
yield team
2853
delete_team(api, team)
54+
55+
56+
@pytest.fixture(scope="session")
57+
def teams_list(api, team):
58+
return list(api.teams.list())
59+
60+
61+
@pytest.fixture
62+
def temp_team(api):
63+
team = create_team(api, create_string("Team"))
64+
65+
yield team
66+
67+
if team_exists(api, team):
68+
delete_team(api, team)
69+
70+
71+
@pytest.fixture
72+
def add_teams(api):
73+
teams = []
74+
75+
def inner(num_teams):
76+
for i in range(num_teams):
77+
teams.append(create_team(api, create_string("Additional Team")))
78+
return teams
79+
80+
yield inner
81+
82+
for team in teams:
83+
delete_team(api, team)
84+
85+
86+
# Tests
87+
88+
class TestTeamsAPI(object):
89+
"""Test TeamsAPI methods."""
90+
91+
def test_create_team(self, team):
92+
assert is_valid_team(team)
93+
94+
def test_get_team_details(self, api, team):
95+
team = get_team_details_by_id(team.id)
96+
assert is_valid_team(team)
97+
98+
def test_update_team_name(self, api, team):
99+
new_name = create_string("Updated Team")
100+
team = api.teams.update(team.id, name=new_name)
101+
assert is_valid_team(team)
102+
assert team.title == new_name
103+
104+
def test_delete_team(self, api, temp_team):
105+
api.teams.delete(temp_team.id)
106+
assert not team_exists(api, temp_team)
107+
108+
def test_list_teams(self, api, teams_list):
109+
assert len(teams_list) > 0
110+
assert are_valid_teams(teams_list)
111+
112+
def test_list_teams_with_paging(self, api, teams_list, add_teams):
113+
page_size = 1
114+
pages = 3
115+
num_teams = pages * page_size
116+
if len(teams_list) < num_teams:
117+
add_teams(num_teams - len(teams_list))
118+
teams = api.teams.list(max=page_size)
119+
teams_list = list(itertools.islice(teams, num_teams))
120+
assert len(teams_list) == num_teams
121+
assert are_valid_teams(teams_list)

0 commit comments

Comments
 (0)