1
+ from lib2to3 .pgen2 import token
1
2
import unittest
2
3
import textwrap
3
4
import httpretty
6
7
7
8
from six import u , PY2 , PY3
8
9
from expects import *
9
- from opentok import Client , Render , __version__ ,
10
+ from opentok import Client , Render , __version__
10
11
from .validate_jwt import validate_jwt_header
11
12
12
13
13
- class OpenTokBroadcastTest (unittest .TestCase ):
14
+ class OpenTokRenderTest (unittest .TestCase ):
14
15
def setUp (self ):
15
16
self .api_key = u ("123456" )
16
17
self .api_secret = u ("1234567890abcdef1234567890abcdef1234567890" )
17
18
self .opentok = Client (self .api_key , self .api_secret )
18
19
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" )
21
22
22
23
@httpretty .activate
23
- def test_start_broadcast (self ):
24
- """
25
- Test start_broadcast() method
26
- """
24
+ def test_start_render (self ):
27
25
httpretty .register_uri (
28
26
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 ),
30
28
body = textwrap .dedent (
31
29
u (
32
30
"""\
33
31
{
34
- "id": "1748b7070a81464c9759c46ad10d3734 ",
32
+ "id": "1248e7070b81464c9789f46ad10e7764 ",
35
33
"sessionId": "2_MX4xMDBfjE0Mzc2NzY1NDgwMTJ-TjMzfn4",
36
- "projectId": 100 ,
34
+ "projectId": "e2343f23456g34709d2443a234" ,
37
35
"createdAt": 1437676551000,
38
36
"updatedAt": 1437676551000,
39
- "resolution": "640x480",
37
+ "url": "https://webapp.customer.com",
38
+ "resolution": "1280x720",
40
39
"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"
54
41
}
55
42
"""
56
43
)
57
44
),
58
- status = 200 ,
45
+ status = 202 ,
59
46
content_type = u ("application/json" ),
60
47
)
61
48
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"
85
50
86
- broadcast = self .opentok .start_broadcast (self .session_id , options )
51
+ render = self .opentok .start_render (self .session_id , self .token , url )
52
+
87
53
validate_jwt_header (self , httpretty .last_request ().headers [u ("x-opentok-auth" )])
88
54
expect (httpretty .last_request ().headers [u ("user-agent" )]).to (
89
55
contain (u ("OpenTok-Python-SDK/" ) + __version__ )
@@ -98,98 +64,18 @@ def test_start_broadcast(self):
98
64
if PY3 :
99
65
body = json .loads (httpretty .last_request ().body .decode ("utf-8" ))
100
66
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" ))
185
71
)
186
- expect (broadcast ).to (
72
+ expect (render ).to (
187
73
have_property (u ("sessionId" ), u ("2_MX4xMDBfjE0Mzc2NzY1NDgwMTJ-TjMzfn4" ))
188
74
)
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