11
11
from .validate_jwt import validate_jwt_header
12
12
13
13
14
- class OpenTokAudioStreamerLiteTest (unittest .TestCase ):
14
+ class OpenTokAudioConnectorLiteTest (unittest .TestCase ):
15
15
def setUp (self ):
16
16
self .api_key = u ("123456" )
17
17
self .api_secret = u ("1234567890abcdef1234567890abcdef1234567890" )
@@ -39,20 +39,15 @@ def test_connect_audio_to_websocket(self):
39
39
content_type = u ("application/json" ),
40
40
)
41
41
42
- websocket_options = {
43
- "uri" : "wss://service.com/ws-endpoint"
44
- }
42
+ websocket_options = {"uri" : "wss://service.com/ws-endpoint" }
45
43
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
55
46
)
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" )))
56
51
# non-deterministic json encoding. have to decode to test it properly
57
52
if PY2 :
58
53
body = json .loads (httpretty .last_request ().body )
@@ -61,9 +56,7 @@ def test_connect_audio_to_websocket(self):
61
56
62
57
expect (body ).to (have_key (u ("token" )))
63
58
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" )))
67
60
expect (websocket_audio_connection ).to (
68
61
have_property (u ("connectionId" ), u ("e9f8c166-6c67-440d-994a-04fb6dfed007" ))
69
62
)
@@ -81,21 +74,16 @@ def test_connect_audio_to_websocket_custom_options(self):
81
74
websocket_options = {
82
75
"uri" : "wss://service.com/ws-endpoint" ,
83
76
"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" },
87
78
}
88
79
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
98
82
)
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" )))
99
87
# non-deterministic json encoding. have to decode to test it properly
100
88
if PY2 :
101
89
body = json .loads (httpretty .last_request ().body )
@@ -104,9 +92,7 @@ def test_connect_audio_to_websocket_custom_options(self):
104
92
105
93
expect (body ).to (have_key (u ("token" )))
106
94
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" )))
110
96
expect (websocket_audio_connection ).to (
111
97
have_property (u ("connectionId" ), u ("e9f8c166-6c67-440d-994a-04fb6dfed007" ))
112
98
)
@@ -121,30 +107,27 @@ def test_connect_audio_to_websocket_media_mode_error(self):
121
107
content_type = u ("application/json" ),
122
108
)
123
109
124
- websocket_options = {
125
- "uri" : "wss://service.com/ws-endpoint"
126
- }
110
+ websocket_options = {"uri" : "wss://service.com/ws-endpoint" }
127
111
128
112
session_id = "session-where-mediaMode=relayed-was-selected"
129
113
130
114
with self .assertRaises (InvalidMediaModeError ) as context :
131
115
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 )
140
119
)
141
120
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
+
142
125
def test_connect_audio_to_websocket_invalid_options_type_error (self ):
143
126
websocket_options = "wss://service.com/ws-endpoint"
144
127
with self .assertRaises (InvalidWebSocketOptionsError ) as context :
145
128
self .opentok .connect_audio_to_websocket (self .session_id , self .token , websocket_options )
146
129
self .assertTrue ("Must pass WebSocket options as a dictionary." in str (context .exception ))
147
-
130
+
148
131
def test_connect_audio_to_websocket_missing_uri_error (self ):
149
132
websocket_options = {}
150
133
with self .assertRaises (InvalidWebSocketOptionsError ) as context :
0 commit comments