Skip to content

Commit 81f21a0

Browse files
ckoegelajrice6713
andauthored
DX-2690, DX-2693 webrtc_api Integration Tests (#101)
* DX-2690, DX-2693 `webrtc_api` Integration Tests * revert files * push what i have rn * most of happy path done * happy path done * add notFound and unauthorized exception assertions * add docstrings * Update test/integration/test_webrtc_api.py Co-authored-by: AJ Rice <[email protected]> * use env_vars util * fix gitignore Co-authored-by: AJ Rice <[email protected]>
1 parent d257d1a commit 81f21a0

File tree

4 files changed

+263
-14
lines changed

4 files changed

+263
-14
lines changed

bandwidth.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4429,9 +4429,6 @@
44294429
"subscriptions": {
44304430
"type": "object",
44314431
"readOnly": true,
4432-
"required": [
4433-
"sessionId"
4434-
],
44354432
"properties": {
44364433
"sessionId": {
44374434
"type": "string",

bandwidth/model/subscriptions.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,9 @@ def discriminator():
109109

110110
@classmethod
111111
@convert_js_args_to_python_args
112-
def _from_openapi_data(cls, session_id, *args, **kwargs): # noqa: E501
112+
def _from_openapi_data(cls, *args, **kwargs): # noqa: E501
113113
"""Subscriptions - a model defined in OpenAPI
114114
115-
Args:
116-
session_id (str): Session the subscriptions are associated with. If this is the only field, the subscriber will be subscribed to all participants in the session (including any participants that are later added to the session). Upon creation of a Participant, returns as an empty object.
117-
118115
Keyword Args:
119116
_check_type (bool): if True, values for parameters in openapi_types
120117
will be type checked and a TypeError will be
@@ -146,6 +143,7 @@ def _from_openapi_data(cls, session_id, *args, **kwargs): # noqa: E501
146143
Animal class but this time we won't travel
147144
through its discriminator because we passed in
148145
_visited_composed_classes = (Animal,)
146+
session_id (str): Session the subscriptions are associated with. If this is the only field, the subscriber will be subscribed to all participants in the session (including any participants that are later added to the session). Upon creation of a Participant, returns as an empty object.. [optional] # noqa: E501
149147
participants ([ParticipantSubscription]): (optional) A list of participants in the session that will be subscribed to. Returns empty if used during the creation of a Participant. . [optional] # noqa: E501
150148
"""
151149

@@ -178,7 +176,6 @@ def _from_openapi_data(cls, session_id, *args, **kwargs): # noqa: E501
178176
self._configuration = _configuration
179177
self._visited_composed_classes = _visited_composed_classes + (self.__class__,)
180178

181-
self.session_id = session_id
182179
for var_name, var_value in kwargs.items():
183180
if var_name not in self.attribute_map and \
184181
self._configuration is not None and \
@@ -199,12 +196,9 @@ def _from_openapi_data(cls, session_id, *args, **kwargs): # noqa: E501
199196
])
200197

201198
@convert_js_args_to_python_args
202-
def __init__(self, session_id, *args, **kwargs): # noqa: E501
199+
def __init__(self, *args, **kwargs): # noqa: E501
203200
"""Subscriptions - a model defined in OpenAPI
204201
205-
Args:
206-
session_id (str): Session the subscriptions are associated with. If this is the only field, the subscriber will be subscribed to all participants in the session (including any participants that are later added to the session). Upon creation of a Participant, returns as an empty object.
207-
208202
Keyword Args:
209203
_check_type (bool): if True, values for parameters in openapi_types
210204
will be type checked and a TypeError will be
@@ -236,6 +230,7 @@ def __init__(self, session_id, *args, **kwargs): # noqa: E501
236230
Animal class but this time we won't travel
237231
through its discriminator because we passed in
238232
_visited_composed_classes = (Animal,)
233+
session_id (str): Session the subscriptions are associated with. If this is the only field, the subscriber will be subscribed to all participants in the session (including any participants that are later added to the session). Upon creation of a Participant, returns as an empty object.. [optional] # noqa: E501
239234
participants ([ParticipantSubscription]): (optional) A list of participants in the session that will be subscribed to. Returns empty if used during the creation of a Participant. . [optional] # noqa: E501
240235
"""
241236

@@ -266,7 +261,6 @@ def __init__(self, session_id, *args, **kwargs): # noqa: E501
266261
self._configuration = _configuration
267262
self._visited_composed_classes = _visited_composed_classes + (self.__class__,)
268263

269-
self.session_id = session_id
270264
for var_name, var_value in kwargs.items():
271265
if var_name not in self.attribute_map and \
272266
self._configuration is not None and \

docs/Subscriptions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
## Properties
55
Name | Type | Description | Notes
66
------------ | ------------- | ------------- | -------------
7-
**session_id** | **str** | Session the subscriptions are associated with. If this is the only field, the subscriber will be subscribed to all participants in the session (including any participants that are later added to the session). Upon creation of a Participant, returns as an empty object. |
7+
**session_id** | **str** | Session the subscriptions are associated with. If this is the only field, the subscriber will be subscribed to all participants in the session (including any participants that are later added to the session). Upon creation of a Participant, returns as an empty object. | [optional]
88
**participants** | [**[ParticipantSubscription]**](ParticipantSubscription.md) | (optional) A list of participants in the session that will be subscribed to. Returns empty if used during the creation of a Participant. | [optional]
99
**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional]
1010

Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
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

Comments
 (0)