Skip to content

Commit 8da39ce

Browse files
committed
Refactor Test Suite
Reafactor the existing Ïtest suite to include the name and package structure changes.
1 parent db8907c commit 8da39ce

16 files changed

+580
-260
lines changed

tests/api/__init__.py

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,158 @@
11
# -*- coding: utf-8 -*-
2+
"""WebexTeamsAPI tests.
3+
4+
Copyright (c) 2016-2018 Cisco and/or its affiliates.
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
"""
24+
25+
import os
26+
27+
import pytest
28+
29+
import webexteamssdk
30+
from tests.environment import WEBEX_TEAMS_ACCESS_TOKEN
31+
from webexteamssdk.api.access_tokens import AccessTokensAPI
32+
from webexteamssdk.api.events import EventsAPI
33+
from webexteamssdk.api.licenses import LicensesAPI
34+
from webexteamssdk.api.memberships import MembershipsAPI
35+
from webexteamssdk.api.messages import MessagesAPI
36+
from webexteamssdk.api.organizations import OrganizationsAPI
37+
from webexteamssdk.api.people import PeopleAPI
38+
from webexteamssdk.api.roles import RolesAPI
39+
from webexteamssdk.api.rooms import RoomsAPI
40+
from webexteamssdk.api.team_memberships import TeamMembershipsAPI
41+
from webexteamssdk.api.teams import TeamsAPI
42+
from webexteamssdk.api.webhooks import WebhooksAPI
43+
from webexteamssdk.config import (
44+
ACCESS_TOKEN_ENVIRONMENT_VARIABLE, DEFAULT_BASE_URL,
45+
DEFAULT_SINGLE_REQUEST_TIMEOUT, DEFAULT_WAIT_ON_RATE_LIMIT,
46+
)
47+
48+
49+
# Fixtures
50+
51+
@pytest.fixture(scope="session")
52+
def access_token():
53+
return WEBEX_TEAMS_ACCESS_TOKEN
54+
55+
56+
@pytest.fixture
57+
def unset_access_token(access_token):
58+
del os.environ[ACCESS_TOKEN_ENVIRONMENT_VARIABLE]
59+
yield None
60+
os.environ[ACCESS_TOKEN_ENVIRONMENT_VARIABLE] = access_token
61+
62+
63+
@pytest.fixture(scope="session")
64+
def api():
65+
return webexteamssdk.WebexTeamsAPI()
66+
67+
68+
# Tests
69+
70+
class TestWebexTeamsAPI:
71+
"""Test the WebexTeamsAPI class code."""
72+
73+
# Test creating WebexTeamsAPI objects
74+
75+
@pytest.mark.usefixtures("unset_access_token")
76+
def test_creating_a_new_webexteamssdk_object_without_an_access_token(self):
77+
with pytest.raises(webexteamssdk.AccessTokenError):
78+
webexteamssdk.WebexTeamsAPI()
79+
80+
@pytest.mark.usefixtures("unset_access_token")
81+
def test_creating_a_new_webexteamssdk_object_via_access_token_argument(self, access_token):
82+
connection_object = webexteamssdk.WebexTeamsAPI(access_token=access_token)
83+
assert isinstance(connection_object, webexteamssdk.WebexTeamsAPI)
84+
85+
def test_creating_a_new_webexteamssdk_object_via_environment_varable(self):
86+
connection_object = webexteamssdk.WebexTeamsAPI()
87+
assert isinstance(connection_object, webexteamssdk.WebexTeamsAPI)
88+
89+
def test_default_base_url(self):
90+
connection_object = webexteamssdk.WebexTeamsAPI()
91+
assert connection_object.base_url == DEFAULT_BASE_URL
92+
93+
def test_custom_base_url(self):
94+
custom_url = "https://custom.domain.com/v1/"
95+
connection_object = webexteamssdk.WebexTeamsAPI(base_url=custom_url)
96+
assert connection_object.base_url == custom_url
97+
98+
def test_default_single_request_timeout(self):
99+
connection_object = webexteamssdk.WebexTeamsAPI()
100+
assert connection_object.single_request_timeout == \
101+
DEFAULT_SINGLE_REQUEST_TIMEOUT
102+
103+
def test_custom_single_request_timeout(self):
104+
custom_timeout = 10
105+
connection_object = webexteamssdk.WebexTeamsAPI(
106+
single_request_timeout=custom_timeout
107+
)
108+
assert connection_object.single_request_timeout == custom_timeout
109+
110+
def test_default_wait_on_rate_limit(self):
111+
connection_object = webexteamssdk.WebexTeamsAPI()
112+
assert connection_object.wait_on_rate_limit == \
113+
DEFAULT_WAIT_ON_RATE_LIMIT
114+
115+
def test_non_default_wait_on_rate_limit(self):
116+
connection_object = webexteamssdk.WebexTeamsAPI(
117+
wait_on_rate_limit=not DEFAULT_WAIT_ON_RATE_LIMIT
118+
)
119+
assert connection_object.wait_on_rate_limit != \
120+
DEFAULT_WAIT_ON_RATE_LIMIT
121+
122+
# Test creation of component API objects
123+
124+
def test_access_tokens_api_object_creation(self, api):
125+
assert isinstance(api.access_tokens, AccessTokensAPI)
126+
127+
def test_events_api_object_creation(self, api):
128+
assert isinstance(api.events, EventsAPI)
129+
130+
def test_licenses_api_object_creation(self, api):
131+
assert isinstance(api.licenses, LicensesAPI)
132+
133+
def test_memberships_api_object_creation(self, api):
134+
assert isinstance(api.memberships, MembershipsAPI)
135+
136+
def test_messages_api_object_creation(self, api):
137+
assert isinstance(api.messages, MessagesAPI)
138+
139+
def test_organizations_api_object_creation(self, api):
140+
assert isinstance(api.organizations, OrganizationsAPI)
141+
142+
def test_people_api_object_creation(self, api):
143+
assert isinstance(api.people, PeopleAPI)
144+
145+
def test_roles_api_object_creation(self, api):
146+
assert isinstance(api.roles, RolesAPI)
147+
148+
def test_rooms_api_object_creation(self, api):
149+
assert isinstance(api.rooms, RoomsAPI)
150+
151+
def test_team_memberships_api_object_creation(self, api):
152+
assert isinstance(api.team_memberships, TeamMembershipsAPI)
153+
154+
def test_teams_api_object_creation(self, api):
155+
assert isinstance(api.teams, TeamsAPI)
156+
157+
def test_webhooks_api_object_creation(self, api):
158+
assert isinstance(api.webhooks, WebhooksAPI)

tests/api/test_events.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
# -*- coding: utf-8 -*-
2-
"""pytest Messages functions, fixtures and tests."""
2+
"""pytest Messages functions, fixtures and tests.
33
4+
Copyright (c) 2016-2018 Cisco and/or its affiliates.
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
"""
424

525
import itertools
626

@@ -9,12 +29,6 @@
929
import webexteamssdk
1030

1131

12-
__author__ = "Chris Lunsford"
13-
__author_email__ = "[email protected]"
14-
__copyright__ = "Copyright (c) 2016-2018 Cisco and/or its affiliates."
15-
__license__ = "MIT"
16-
17-
1832
# Helper Functions
1933

2034
def is_valid_event(obj):

tests/api/test_licenses.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
# -*- coding: utf-8 -*-
2-
"""pytest Licenses API wrapper tests and fixtures."""
2+
"""pytest Licenses API wrapper tests and fixtures.
33
4+
Copyright (c) 2016-2018 Cisco and/or its affiliates.
45
5-
import pytest
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
612
7-
import webexteamssdk
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
815
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
"""
924

10-
__author__ = "Chris Lunsford"
11-
__author_email__ = "[email protected]"
12-
__copyright__ = "Copyright (c) 2016-2018 Cisco and/or its affiliates."
13-
__license__ = "MIT"
25+
import pytest
26+
27+
import webexteamssdk
1428

1529

1630
# Helper Functions

tests/api/test_memberships.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
# -*- coding: utf-8 -*-
2-
"""pytest Memberships functions, fixtures and tests."""
2+
"""pytest Memberships functions, fixtures and tests.
33
4+
Copyright (c) 2016-2018 Cisco and/or its affiliates.
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
"""
424

525
import itertools
626

@@ -9,12 +29,6 @@
929
import webexteamssdk
1030

1131

12-
__author__ = "Chris Lunsford"
13-
__author_email__ = "[email protected]"
14-
__copyright__ = "Copyright (c) 2016-2018 Cisco and/or its affiliates."
15-
__license__ = "MIT"
16-
17-
1832
# Helper Functions
1933

2034
def add_person_to_room_by_email(api, room, person, isModerator=False):

tests/api/test_messages.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,36 @@
11
# -*- coding: utf-8 -*-
2-
"""pytest Messages functions, fixtures and tests."""
2+
"""pytest Messages functions, fixtures and tests.
33
4+
Copyright (c) 2016-2018 Cisco and/or its affiliates.
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
"""
424

525
import itertools
626

727
import pytest
828

929
import webexteamssdk
10-
from tests.conftest import TEST_FILE_URL
30+
from tests.environment import WEBEX_TEAMS_TEST_FILE_URL
1131
from tests.utils import create_string
1232

1333

14-
__author__ = "Chris Lunsford"
15-
__author_email__ = "[email protected]"
16-
__copyright__ = "Copyright (c) 2016-2018 Cisco and/or its affiliates."
17-
__license__ = "MIT"
18-
19-
2034
# Helper Functions
2135

2236
def create_message(api, **message_attributes):
@@ -122,7 +136,7 @@ def group_room_markdown_message(group_room, send_group_room_message, me,
122136
def group_room_file_by_URL_message(group_room, send_group_room_message):
123137
text = "File posted via URL"
124138
return send_group_room_message(group_room.id, text=text,
125-
files=[TEST_FILE_URL])
139+
files=[WEBEX_TEAMS_TEST_FILE_URL])
126140

127141

128142
@pytest.fixture(scope="session")

tests/api/test_organizations.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
# -*- coding: utf-8 -*-
2-
"""pytest Organizations API wrapper tests and fixtures."""
2+
"""pytest Organizations API wrapper tests and fixtures.
33
4+
Copyright (c) 2016-2018 Cisco and/or its affiliates.
45
5-
import pytest
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
612
7-
import webexteamssdk
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
815
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
"""
924

10-
__author__ = "Chris Lunsford"
11-
__author_email__ = "[email protected]"
12-
__copyright__ = "Copyright (c) 2016-2018 Cisco and/or its affiliates."
13-
__license__ = "MIT"
25+
import pytest
26+
27+
import webexteamssdk
1428

1529

1630
# Helper Functions

0 commit comments

Comments
 (0)