Skip to content

Commit 97a720e

Browse files
committed
added test for start_render method
1 parent cb7a066 commit 97a720e

File tree

3 files changed

+30
-144
lines changed

3 files changed

+30
-144
lines changed

opentok/endpoints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,10 @@ def get_broadcast_stream(self, broadcast_id=None):
201201

202202
return url
203203

204-
205204
def get_render_url(self, render_id: str = None):
206205
"Returns URLs for working with the Render API."""
207206
url = self.api_url + "/v2/project/" + self.api_key + "/render"
208207
if render_id:
209208
url += "/" + render_id
209+
210210
return url

opentok/opentok.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1640,7 +1640,7 @@ def start_render(self, session_id, opentok_token, url, max_duration=7200, resolu
16401640
)
16411641

16421642
if response and response.status_code == 202:
1643-
return Render(self, response.json())
1643+
return Render(response.json())
16441644
elif response.status_code == 400:
16451645
"""
16461646
The HTTP response has a 400 status code in the following cases:

tests/test_render.py

Lines changed: 28 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from lib2to3.pgen2 import token
12
import unittest
23
import textwrap
34
import httpretty
@@ -6,84 +7,49 @@
67

78
from six import u, PY2, PY3
89
from expects import *
9-
from opentok import Client, Render, __version__,
10+
from opentok import Client, Render, __version__
1011
from .validate_jwt import validate_jwt_header
1112

1213

13-
class OpenTokBroadcastTest(unittest.TestCase):
14+
class OpenTokRenderTest(unittest.TestCase):
1415
def setUp(self):
1516
self.api_key = u("123456")
1617
self.api_secret = u("1234567890abcdef1234567890abcdef1234567890")
1718
self.opentok = Client(self.api_key, self.api_secret)
1819
self.session_id = u("2_MX4xMDBfjE0Mzc2NzY1NDgwMTJ-TjMzfn4")
19-
self.stream1 = "kjhk-09898-kjn"
20-
self.stream2 = "jnn-99kjk-88734r"
20+
self.token = u("1234-5678-9012")
21+
self.render_id = u("80abaf0d-25a3-4efc-968f-6268d620668d")
2122

2223
@httpretty.activate
23-
def test_start_broadcast(self):
24-
"""
25-
Test start_broadcast() method
26-
"""
24+
def test_start_render(self):
2725
httpretty.register_uri(
2826
httpretty.POST,
29-
u("https://api.opentok.com/v2/project/{0}/broadcast").format(self.api_key),
27+
u("https://api.opentok.com/v2/project/{0}/render").format(self.api_key),
3028
body=textwrap.dedent(
3129
u(
3230
"""\
3331
{
34-
"id": "1748b7070a81464c9759c46ad10d3734",
32+
"id": "1248e7070b81464c9789f46ad10e7764",
3533
"sessionId": "2_MX4xMDBfjE0Mzc2NzY1NDgwMTJ-TjMzfn4",
36-
"projectId": 100,
34+
"projectId": "e2343f23456g34709d2443a234",
3735
"createdAt": 1437676551000,
3836
"updatedAt": 1437676551000,
39-
"resolution": "640x480",
37+
"url": "https://webapp.customer.com",
38+
"resolution": "1280x720",
4039
"status": "started",
41-
"broadcastUrls": {
42-
"hls" : "http://server/fakepath/playlist.m3u8",
43-
"rtmp": {
44-
"foo": {
45-
"serverUrl": "rtmp://myfooserver/myfooapp",
46-
"streamName": "myfoostream"
47-
},
48-
"bar": {
49-
"serverUrl": "rtmp://mybarserver/mybarapp",
50-
"streamName": "mybarstream"
51-
}
52-
}
53-
}
40+
"streamId": "e32445b743678c98230f238"
5441
}
5542
"""
5643
)
5744
),
58-
status=200,
45+
status=202,
5946
content_type=u("application/json"),
6047
)
6148

62-
options = {
63-
"layout": {
64-
"type": "custom",
65-
"stylesheet": "the layout stylesheet (only used with type == custom)",
66-
},
67-
"maxDuration": 5400,
68-
"outputs": {
69-
"hls": {},
70-
"rtmp": [
71-
{
72-
"id": "foo",
73-
"serverUrl": "rtmp://myfooserver/myfooapp",
74-
"streamName": "myfoostream",
75-
},
76-
{
77-
"id": "bar",
78-
"serverUrl": "rtmp://mybarserver/mybarapp",
79-
"streamName": "mybarstream",
80-
},
81-
],
82-
},
83-
"resolution": "640x480",
84-
}
49+
url = "https://webapp.customer.com"
8550

86-
broadcast = self.opentok.start_broadcast(self.session_id, options)
51+
render = self.opentok.start_render(self.session_id, self.token, url)
52+
8753
validate_jwt_header(self, httpretty.last_request().headers[u("x-opentok-auth")])
8854
expect(httpretty.last_request().headers[u("user-agent")]).to(
8955
contain(u("OpenTok-Python-SDK/") + __version__)
@@ -98,98 +64,18 @@ def test_start_broadcast(self):
9864
if PY3:
9965
body = json.loads(httpretty.last_request().body.decode("utf-8"))
10066

101-
expect(body).to(have_key(u("layout")))
102-
expect(broadcast).to(be_an(Broadcast))
103-
expect(broadcast).to(
104-
have_property(u("id"), u("1748b7070a81464c9759c46ad10d3734"))
105-
)
106-
expect(broadcast).to(
107-
have_property(u("sessionId"), u("2_MX4xMDBfjE0Mzc2NzY1NDgwMTJ-TjMzfn4"))
108-
)
109-
expect(broadcast).to(have_property(u("projectId"), 100))
110-
expect(broadcast).to(have_property(u("createdAt"), 1437676551000))
111-
expect(broadcast).to(have_property(u("updatedAt"), 1437676551000))
112-
expect(broadcast).to(have_property(u("resolution"), u("640x480")))
113-
expect(broadcast).to(have_property(u("status"), u("started")))
114-
expect(list(broadcast.broadcastUrls)).to(have_length(2))
115-
expect(list(broadcast.broadcastUrls["rtmp"])).to(have_length(2))
116-
117-
@httpretty.activate
118-
def test_start_broadcast_only_one_rtmp(self):
119-
"""
120-
Test start_broadcast() method with only one rtmp
121-
"""
122-
httpretty.register_uri(
123-
httpretty.POST,
124-
u("https://api.opentok.com/v2/project/{0}/broadcast").format(self.api_key),
125-
body=textwrap.dedent(
126-
u(
127-
"""\
128-
{
129-
"id": "1748b7070a81464c9759c46ad10d3734",
130-
"sessionId": "2_MX4xMDBfjE0Mzc2NzY1NDgwMTJ-TjMzfn4",
131-
"projectId": 100,
132-
"createdAt": 1437676551000,
133-
"updatedAt": 1437676551000,
134-
"resolution": "640x480",
135-
"status": "started",
136-
"broadcastUrls": {
137-
"hls" : "http://server/fakepath/playlist.m3u8",
138-
"rtmp": {
139-
"foo": {
140-
"serverUrl": "rtmp://myfooserver/myfooapp",
141-
"streamName": "myfoostream"
142-
},
143-
"bar": {
144-
"serverUrl": "rtmp://mybarserver/mybarapp",
145-
"streamName": "mybarstream"
146-
}
147-
}
148-
}
149-
}
150-
"""
151-
)
152-
),
153-
status=200,
154-
content_type=u("application/json"),
155-
)
156-
157-
options = {
158-
"sessionId": "2_MX4xMDBfjE0Mzc2NzY1NDgwMTJ",
159-
"layout": {
160-
"type": "custom",
161-
"stylesheet": "the layout stylesheet (only used with type == custom)",
162-
},
163-
"maxDuration": 5400,
164-
"outputs": {
165-
"rtmp": {
166-
"id": "my-id",
167-
"serverUrl": "rtmp://myserver/myapp",
168-
"streamName": "my-stream-name",
169-
}
170-
},
171-
"resolution": "640x480",
172-
}
173-
174-
broadcast = self.opentok.start_broadcast(self.session_id, options)
175-
validate_jwt_header(self, httpretty.last_request().headers[u("x-opentok-auth")])
176-
expect(httpretty.last_request().headers[u("user-agent")]).to(
177-
contain(u("OpenTok-Python-SDK/") + __version__)
178-
)
179-
expect(httpretty.last_request().headers[u("content-type")]).to(
180-
equal(u("application/json"))
181-
)
182-
expect(broadcast).to(be_an(Broadcast))
183-
expect(broadcast).to(
184-
have_property(u("id"), u("1748b7070a81464c9759c46ad10d3734"))
67+
expect(body).to(have_key(u("token")))
68+
expect(render).to(be_a(Render))
69+
expect(render).to(
70+
have_property(u("id"), u("1248e7070b81464c9789f46ad10e7764"))
18571
)
186-
expect(broadcast).to(
72+
expect(render).to(
18773
have_property(u("sessionId"), u("2_MX4xMDBfjE0Mzc2NzY1NDgwMTJ-TjMzfn4"))
18874
)
189-
expect(broadcast).to(have_property(u("projectId"), 100))
190-
expect(broadcast).to(have_property(u("createdAt"), 1437676551000))
191-
expect(broadcast).to(have_property(u("updatedAt"), 1437676551000))
192-
expect(broadcast).to(have_property(u("resolution"), u("640x480")))
193-
expect(broadcast).to(have_property(u("status"), u("started")))
194-
expect(list(broadcast.broadcastUrls)).to(have_length(2))
195-
expect(list(broadcast.broadcastUrls["rtmp"])).to(have_length(2))
75+
expect(render).to(have_property(u("projectId"), u("e2343f23456g34709d2443a234")))
76+
expect(render).to(have_property(u("createdAt"), 1437676551000))
77+
expect(render).to(have_property(u("updatedAt"), 1437676551000))
78+
expect(render).to(have_property(u("resolution"), u("1280x720")))
79+
expect(render).to(have_property(u("status"), u("started")))
80+
expect(render).to(have_property(u("streamId"), u("e32445b743678c98230f238")))
81+

0 commit comments

Comments
 (0)