|
| 1 | +""" |
| 2 | + Bandwidth |
| 3 | +
|
| 4 | + Bandwidth's Communication APIs # noqa: E501 |
| 5 | +
|
| 6 | + The version of the OpenAPI document: 1.0.0 |
| 7 | + |
| 8 | + Generated by: https://openapi-generator.tech |
| 9 | +""" |
| 10 | + |
| 11 | + |
| 12 | +from array import array |
| 13 | +import unittest |
| 14 | + |
| 15 | +import bandwidth |
| 16 | +from hamcrest import * |
| 17 | +from bandwidth.api import participants_api, sessions_api |
| 18 | +from bandwidth.exceptions import NotFoundException, UnauthorizedException |
| 19 | +from bandwidth.model.create_participant_request import CreateParticipantRequest |
| 20 | +from bandwidth.model.create_participant_response import CreateParticipantResponse |
| 21 | +from bandwidth.model.publish_permissions_enum import PublishPermissionsEnum |
| 22 | +from bandwidth.model.device_api_version_enum import DeviceApiVersionEnum |
| 23 | +from bandwidth.model.participant import Participant |
| 24 | +from bandwidth.model.session import Session |
| 25 | +from bandwidth.model.subscriptions import Subscriptions |
| 26 | +from bandwidth.model.participant_subscription import ParticipantSubscription |
| 27 | +from test.utils.env_variables import * |
| 28 | + |
| 29 | + |
| 30 | +class TestSessionsApi(unittest.TestCase): |
| 31 | + """SessionsApi unit test stubs""" |
| 32 | + |
| 33 | + def setUp(self): |
| 34 | + # API Client |
| 35 | + configuration = bandwidth.Configuration( |
| 36 | + username = BW_USERNAME, |
| 37 | + password = BW_PASSWORD |
| 38 | + ) |
| 39 | + api_client = bandwidth.ApiClient(configuration) |
| 40 | + self.sessions_api_instance = sessions_api.SessionsApi(api_client) |
| 41 | + self.participants_api_instance = participants_api.ParticipantsApi(api_client) |
| 42 | + self.account_id = BW_ACCOUNT_ID |
| 43 | + |
| 44 | + # Participant Properties |
| 45 | + self.callback_url = 'https://example.com/callback' |
| 46 | + self.publish_permissions = [ |
| 47 | + PublishPermissionsEnum('AUDIO'), |
| 48 | + PublishPermissionsEnum('VIDEO') |
| 49 | + ] |
| 50 | + self.participant_tag = 'python integration participant tag' |
| 51 | + self.device_api_version = DeviceApiVersionEnum('V3') |
| 52 | + self.participant_id = '' |
| 53 | + |
| 54 | + # Participant Request |
| 55 | + self.create_participant_request = CreateParticipantRequest( |
| 56 | + callback_url=self.callback_url, |
| 57 | + publish_permissions=self.publish_permissions, |
| 58 | + tag=self.participant_tag, |
| 59 | + device_api_version=self.device_api_version |
| 60 | + ) |
| 61 | + |
| 62 | + # Session Properties |
| 63 | + self.session_tag = 'python integration session tag' |
| 64 | + self.session_id = '' |
| 65 | + |
| 66 | + # Session Request |
| 67 | + self.session = Session( |
| 68 | + tag=self.session_tag |
| 69 | + ) |
| 70 | + |
| 71 | + self.stream_aliases = ['python integration alias'] |
| 72 | + |
| 73 | + def create_participant(self): |
| 74 | + """Test creating participant |
| 75 | + """ |
| 76 | + response = self.participants_api_instance.create_participant(self.account_id, create_participant_request=self.create_participant_request, _return_http_data_only=False) |
| 77 | + |
| 78 | + assert_that(response[1], equal_to(200)) |
| 79 | + |
| 80 | + assert_that(response[0], instance_of(CreateParticipantResponse)) |
| 81 | + assert_that(response[0], has_properties( |
| 82 | + 'participant', instance_of(Participant), |
| 83 | + 'participant', has_properties( |
| 84 | + 'device_api_version', self.device_api_version, |
| 85 | + 'id', instance_of(str), |
| 86 | + 'publish_permissions', contains_inanyorder( |
| 87 | + PublishPermissionsEnum('AUDIO'), |
| 88 | + PublishPermissionsEnum('VIDEO')), |
| 89 | + 'tag', self.participant_tag |
| 90 | + ), |
| 91 | + 'token', instance_of(str) |
| 92 | + )) |
| 93 | + |
| 94 | + self.participant_id = response[0].participant.id |
| 95 | + |
| 96 | + def delete_participant(self): |
| 97 | + """Test deleting participant |
| 98 | + """ |
| 99 | + response = self.participants_api_instance.delete_participant(self.account_id, self.participant_id, _return_http_data_only=False) |
| 100 | + |
| 101 | + assert_that(response[1], equal_to(204)) |
| 102 | + |
| 103 | + def get_participant(self): |
| 104 | + """Test getting participant |
| 105 | + """ |
| 106 | + response = self.participants_api_instance.get_participant(self.account_id, self.participant_id, _return_http_data_only=False) |
| 107 | + |
| 108 | + assert_that(response[1], equal_to(200)) |
| 109 | + assert_that(response[0], instance_of(Participant)) |
| 110 | + assert_that(response[0], has_properties( |
| 111 | + 'device_api_version', self.device_api_version, |
| 112 | + 'id', self.participant_id, |
| 113 | + 'publish_permissions', contains_inanyorder( |
| 114 | + PublishPermissionsEnum('AUDIO'), |
| 115 | + PublishPermissionsEnum('VIDEO')), |
| 116 | + 'sessions', [self.session_id], |
| 117 | + 'subscriptions', has_properties( |
| 118 | + 'participants', instance_of(list) |
| 119 | + ), |
| 120 | + 'tag', self.participant_tag |
| 121 | + )) |
| 122 | + |
| 123 | + def add_participant_to_session(self): |
| 124 | + """Test adding participant to session |
| 125 | + """ |
| 126 | + response = self.sessions_api_instance.add_participant_to_session(self.account_id, self.session_id, self.participant_id, _return_http_data_only=False) |
| 127 | + |
| 128 | + assert_that(response[1], equal_to(204)) |
| 129 | + |
| 130 | + |
| 131 | + def create_session(self): |
| 132 | + """Test creating session |
| 133 | + """ |
| 134 | + response = self.sessions_api_instance.create_session(self.account_id, session=self.session, _return_http_data_only=False) |
| 135 | + |
| 136 | + assert_that(response[1], equal_to(200)) |
| 137 | + |
| 138 | + assert_that(response[0], instance_of(Session)) |
| 139 | + assert_that(response[0], has_properties( |
| 140 | + 'id', instance_of(str), |
| 141 | + 'tag', self.session_tag, |
| 142 | + 'participant_ids', instance_of(array), |
| 143 | + 'participant_ids', empty() |
| 144 | + )) |
| 145 | + |
| 146 | + self.session_id = response[0].id |
| 147 | + |
| 148 | + def delete_session(self): |
| 149 | + """Test deleting session |
| 150 | + """ |
| 151 | + response = self.sessions_api_instance.delete_session(self.account_id, self.session_id, _return_http_data_only=False) |
| 152 | + |
| 153 | + assert_that(response[1], equal_to(204)) |
| 154 | + |
| 155 | + def get_participant_subscriptions(self): |
| 156 | + """Test getting participant subscriptions |
| 157 | + """ |
| 158 | + response = self.sessions_api_instance.get_participant_subscriptions(self.account_id, self.session_id, self.participant_id, _return_http_data_only=False) |
| 159 | + |
| 160 | + assert_that(response[1], equal_to(200)) |
| 161 | + |
| 162 | + assert_that(response[0], has_properties( |
| 163 | + 'participants', instance_of(list), |
| 164 | + 'session_id', self.session_id |
| 165 | + )) |
| 166 | + assert_that(response[0].participants[0], instance_of(ParticipantSubscription)) |
| 167 | + assert_that(response[0].participants[0], has_properties( |
| 168 | + 'participant_id', self.participant_id, |
| 169 | + 'stream_aliases', self.stream_aliases |
| 170 | + )) |
| 171 | + |
| 172 | + def get_session(self): |
| 173 | + """Test getting session |
| 174 | + """ |
| 175 | + response = self.sessions_api_instance.get_session(self.account_id, self.session_id, _return_http_data_only=False) |
| 176 | + |
| 177 | + assert_that(response[1], equal_to(200)) |
| 178 | + |
| 179 | + assert_that(response[0], has_properties( |
| 180 | + 'id', self.session_id, |
| 181 | + 'tag', self.session_tag, |
| 182 | + 'participant_ids', contains_exactly(self.participant_id) |
| 183 | + )) |
| 184 | + |
| 185 | + def list_session_participants(self): |
| 186 | + """Test listing session participants |
| 187 | + """ |
| 188 | + response = self.sessions_api_instance.list_session_participants(self.account_id, self.session_id, _return_http_data_only=False) |
| 189 | + |
| 190 | + assert_that(response[1], equal_to(200)) |
| 191 | + |
| 192 | + assert_that(response[0], instance_of(list)) |
| 193 | + assert_that(response[0][0], instance_of(Participant)) |
| 194 | + assert_that(response[0][0], has_properties( |
| 195 | + 'device_api_version', self.device_api_version, |
| 196 | + 'id', self.participant_id, |
| 197 | + 'publish_permissions', contains_inanyorder( |
| 198 | + PublishPermissionsEnum('AUDIO'), |
| 199 | + PublishPermissionsEnum('VIDEO')), |
| 200 | + 'sessions', [self.session_id], |
| 201 | + 'tag', self.participant_tag |
| 202 | + )) |
| 203 | + |
| 204 | + def remove_participant_from_session(self): |
| 205 | + """Test removing participant from session |
| 206 | + """ |
| 207 | + response = self.sessions_api_instance.remove_participant_from_session(self.account_id, self.session_id, self.participant_id, _return_http_data_only=False) |
| 208 | + |
| 209 | + assert_that(response[1], equal_to(204)) |
| 210 | + |
| 211 | + def update_participant_subscriptions(self): |
| 212 | + """Test updating participant subscriptions |
| 213 | + """ |
| 214 | + subscriptions = Subscriptions( |
| 215 | + session_id=self.session_id, |
| 216 | + participants=[ |
| 217 | + ParticipantSubscription( |
| 218 | + participant_id=self.participant_id, |
| 219 | + stream_aliases=self.stream_aliases, |
| 220 | + ) |
| 221 | + ], |
| 222 | + ) |
| 223 | + |
| 224 | + response = self.sessions_api_instance.update_participant_subscriptions(self.account_id, self.session_id, self.participant_id, subscriptions=subscriptions, _return_http_data_only=False) |
| 225 | + |
| 226 | + assert_that(response[1], equal_to(204)) |
| 227 | + |
| 228 | + def get_participant_unauthorized(self): |
| 229 | + """Test getting participant with unauthorized API client |
| 230 | + """ |
| 231 | + unauthorized_api_client = bandwidth.ApiClient() |
| 232 | + unauthorized_participants_api_instance = participants_api.ParticipantsApi(unauthorized_api_client) |
| 233 | + |
| 234 | + assert_that(calling(unauthorized_participants_api_instance.get_participant).with_args( |
| 235 | + self.account_id, self.participant_id, _return_http_data_only=False)), raises(UnauthorizedException) |
| 236 | + |
| 237 | + def get_participant_not_found(self): |
| 238 | + """Test getting nonexistent participant |
| 239 | + """ |
| 240 | + assert_that(calling(self.participants_api_instance.get_participant).with_args( |
| 241 | + self.account_id, self.participant_id)), raises(NotFoundException) |
| 242 | + |
| 243 | + def _steps(self) -> None: |
| 244 | + call_order = ['create_participant', 'create_session', 'add_participant_to_session', |
| 245 | + 'get_session', 'list_session_participants', 'update_participant_subscriptions', |
| 246 | + 'get_participant_subscriptions', 'get_participant', 'remove_participant_from_session', |
| 247 | + 'delete_session', 'delete_participant', 'get_participant_unauthorized', 'get_participant_not_found'] |
| 248 | + for name in call_order: |
| 249 | + yield name, getattr(self, name) |
| 250 | + |
| 251 | + def test_steps(self) -> None: |
| 252 | + """Test each function from _steps.call_order in specified order |
| 253 | + """ |
| 254 | + for name, step in self._steps(): |
| 255 | + step() |
| 256 | + |
| 257 | +if __name__ == '__main__': |
| 258 | + unittest.main() |
0 commit comments