|
1 | 1 | # -*- 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) |
0 commit comments