|
12 | 12 |
|
13 | 13 |
|
14 | 14 | class OpenTokAudioConnectorLiteTest(unittest.TestCase):
|
| 15 | + @httpretty.activate |
| 16 | + def test_connect_audio_to_websocket_with_bidirectional(self): |
| 17 | + httpretty.register_uri( |
| 18 | + httpretty.POST, |
| 19 | + u(f"https://api.opentok.com/v2/project/{self.api_key}/connect"), |
| 20 | + body=self.response_body, |
| 21 | + status=200, |
| 22 | + content_type=u("application/json"), |
| 23 | + ) |
| 24 | + |
| 25 | + websocket_options = {"uri": "wss://service.com/ws-endpoint", "bidirectional": True} |
| 26 | + |
| 27 | + websocket_audio_connection = self.opentok.connect_audio_to_websocket( |
| 28 | + self.session_id, self.token, websocket_options |
| 29 | + ) |
| 30 | + |
| 31 | + validate_jwt_header(self, httpretty.last_request().headers[u("x-opentok-auth")]) |
| 32 | + expect(httpretty.last_request().headers[u("user-agent")]).to(contain(u("OpenTok-Python-SDK/") + __version__)) |
| 33 | + expect(httpretty.last_request().headers[u("content-type")]).to(equal(u("application/json"))) |
| 34 | + if PY2: |
| 35 | + body = json.loads(httpretty.last_request().body) |
| 36 | + if PY3: |
| 37 | + body = json.loads(httpretty.last_request().body.decode("utf-8")) |
| 38 | + |
| 39 | + expect(body).to(have_key(u("token"))) |
| 40 | + expect(body["websocket"]).to(have_key("bidirectional")) |
| 41 | + expect(body["websocket"]["bidirectional"]).to(be_true) |
| 42 | + expect(websocket_audio_connection).to(be_a(WebSocketAudioConnection)) |
| 43 | + expect(websocket_audio_connection).to(have_property(u("id"), u("b0a5a8c7-dc38-459f-a48d-a7f2008da853"))) |
| 44 | + expect(websocket_audio_connection).to(have_property(u("connectionId"), u("e9f8c166-6c67-440d-994a-04fb6dfed007"))) |
| 45 | + # The bidirectional property should be present (None if not in response, True if in response) |
| 46 | + expect(hasattr(websocket_audio_connection, "bidirectional")).to(be_true) |
15 | 47 | def setUp(self):
|
16 | 48 | self.api_key = u("123456")
|
17 | 49 | self.api_secret = u("1234567890abcdef1234567890abcdef1234567890")
|
|
0 commit comments