1111from .validate_jwt import validate_jwt_header
1212
1313
14- class OpenTokAudioStreamerLiteTest (unittest .TestCase ):
14+ class OpenTokAudioConnectorLiteTest (unittest .TestCase ):
1515 def setUp (self ):
1616 self .api_key = u ("123456" )
1717 self .api_secret = u ("1234567890abcdef1234567890abcdef1234567890" )
@@ -39,20 +39,15 @@ def test_connect_audio_to_websocket(self):
3939 content_type = u ("application/json" ),
4040 )
4141
42- websocket_options = {
43- "uri" : "wss://service.com/ws-endpoint"
44- }
42+ websocket_options = {"uri" : "wss://service.com/ws-endpoint" }
4543
46- websocket_audio_connection = self .opentok .connect_audio_to_websocket (self .session_id , self .token , websocket_options )
47-
48- validate_jwt_header (self , httpretty .last_request ().headers [u ("x-opentok-auth" )])
49- expect (httpretty .last_request ().headers [u ("user-agent" )]).to (
50- contain (u ("OpenTok-Python-SDK/" ) + __version__ )
51- )
52- expect (httpretty .last_request ().headers [u ("content-type" )]).to (
53- equal (u ("application/json" ))
54-
44+ websocket_audio_connection = self .opentok .connect_audio_to_websocket (
45+ self .session_id , self .token , websocket_options
5546 )
47+
48+ validate_jwt_header (self , httpretty .last_request ().headers [u ("x-opentok-auth" )])
49+ expect (httpretty .last_request ().headers [u ("user-agent" )]).to (contain (u ("OpenTok-Python-SDK/" ) + __version__ ))
50+ expect (httpretty .last_request ().headers [u ("content-type" )]).to (equal (u ("application/json" )))
5651 # non-deterministic json encoding. have to decode to test it properly
5752 if PY2 :
5853 body = json .loads (httpretty .last_request ().body )
@@ -61,9 +56,7 @@ def test_connect_audio_to_websocket(self):
6156
6257 expect (body ).to (have_key (u ("token" )))
6358 expect (websocket_audio_connection ).to (be_a (WebSocketAudioConnection ))
64- expect (websocket_audio_connection ).to (
65- have_property (u ("id" ), u ("b0a5a8c7-dc38-459f-a48d-a7f2008da853" ))
66- )
59+ expect (websocket_audio_connection ).to (have_property (u ("id" ), u ("b0a5a8c7-dc38-459f-a48d-a7f2008da853" )))
6760 expect (websocket_audio_connection ).to (
6861 have_property (u ("connectionId" ), u ("e9f8c166-6c67-440d-994a-04fb6dfed007" ))
6962 )
@@ -81,21 +74,16 @@ def test_connect_audio_to_websocket_custom_options(self):
8174 websocket_options = {
8275 "uri" : "wss://service.com/ws-endpoint" ,
8376 "streams" : ["stream-id-1" , "stream-id-2" ],
84- "headers" : {
85- "WebSocketHeader" : "Sent via Audio Connector API"
86- }
77+ "headers" : {"WebSocketHeader" : "Sent via Audio Connector API" },
8778 }
8879
89- websocket_audio_connection = self .opentok .connect_audio_to_websocket (self .session_id , self .token , websocket_options )
90-
91- validate_jwt_header (self , httpretty .last_request ().headers [u ("x-opentok-auth" )])
92- expect (httpretty .last_request ().headers [u ("user-agent" )]).to (
93- contain (u ("OpenTok-Python-SDK/" ) + __version__ )
94- )
95- expect (httpretty .last_request ().headers [u ("content-type" )]).to (
96- equal (u ("application/json" ))
97-
80+ websocket_audio_connection = self .opentok .connect_audio_to_websocket (
81+ self .session_id , self .token , websocket_options
9882 )
83+
84+ validate_jwt_header (self , httpretty .last_request ().headers [u ("x-opentok-auth" )])
85+ expect (httpretty .last_request ().headers [u ("user-agent" )]).to (contain (u ("OpenTok-Python-SDK/" ) + __version__ ))
86+ expect (httpretty .last_request ().headers [u ("content-type" )]).to (equal (u ("application/json" )))
9987 # non-deterministic json encoding. have to decode to test it properly
10088 if PY2 :
10189 body = json .loads (httpretty .last_request ().body )
@@ -104,9 +92,7 @@ def test_connect_audio_to_websocket_custom_options(self):
10492
10593 expect (body ).to (have_key (u ("token" )))
10694 expect (websocket_audio_connection ).to (be_a (WebSocketAudioConnection ))
107- expect (websocket_audio_connection ).to (
108- have_property (u ("id" ), u ("b0a5a8c7-dc38-459f-a48d-a7f2008da853" ))
109- )
95+ expect (websocket_audio_connection ).to (have_property (u ("id" ), u ("b0a5a8c7-dc38-459f-a48d-a7f2008da853" )))
11096 expect (websocket_audio_connection ).to (
11197 have_property (u ("connectionId" ), u ("e9f8c166-6c67-440d-994a-04fb6dfed007" ))
11298 )
@@ -121,30 +107,27 @@ def test_connect_audio_to_websocket_media_mode_error(self):
121107 content_type = u ("application/json" ),
122108 )
123109
124- websocket_options = {
125- "uri" : "wss://service.com/ws-endpoint"
126- }
110+ websocket_options = {"uri" : "wss://service.com/ws-endpoint" }
127111
128112 session_id = "session-where-mediaMode=relayed-was-selected"
129113
130114 with self .assertRaises (InvalidMediaModeError ) as context :
131115 self .opentok .connect_audio_to_websocket (session_id , self .token , websocket_options )
132- self .assertTrue ("Only routed sessions are allowed to initiate Audio Connector WebSocket connections." in str (context .exception ))
133-
134- validate_jwt_header (self , httpretty .last_request ().headers [u ("x-opentok-auth" )])
135- expect (httpretty .last_request ().headers [u ("user-agent" )]).to (
136- contain (u ("OpenTok-Python-SDK/" ) + __version__ )
137- )
138- expect (httpretty .last_request ().headers [u ("content-type" )]).to (
139- equal (u ("application/json" ))
116+ self .assertTrue (
117+ "Only routed sessions are allowed to initiate Audio Connector WebSocket connections."
118+ in str (context .exception )
140119 )
141120
121+ validate_jwt_header (self , httpretty .last_request ().headers [u ("x-opentok-auth" )])
122+ expect (httpretty .last_request ().headers [u ("user-agent" )]).to (contain (u ("OpenTok-Python-SDK/" ) + __version__ ))
123+ expect (httpretty .last_request ().headers [u ("content-type" )]).to (equal (u ("application/json" )))
124+
142125 def test_connect_audio_to_websocket_invalid_options_type_error (self ):
143126 websocket_options = "wss://service.com/ws-endpoint"
144127 with self .assertRaises (InvalidWebSocketOptionsError ) as context :
145128 self .opentok .connect_audio_to_websocket (self .session_id , self .token , websocket_options )
146129 self .assertTrue ("Must pass WebSocket options as a dictionary." in str (context .exception ))
147-
130+
148131 def test_connect_audio_to_websocket_missing_uri_error (self ):
149132 websocket_options = {}
150133 with self .assertRaises (InvalidWebSocketOptionsError ) as context :
0 commit comments