1
- from lib2to3 .pgen2 import token
2
1
import unittest
3
2
import textwrap
4
3
import httpretty
5
4
import json
5
+ import requests
6
6
from sure import expect
7
7
8
8
from six import u , PY2 , PY3
9
9
from expects import *
10
- from opentok import Client , Render , __version__
10
+ from opentok import Client , Render , RenderList , __version__
11
11
from .validate_jwt import validate_jwt_header
12
12
13
13
@@ -78,4 +78,139 @@ def test_start_render(self):
78
78
expect (render ).to (have_property (u ("resolution" ), u ("1280x720" )))
79
79
expect (render ).to (have_property (u ("status" ), u ("started" )))
80
80
expect (render ).to (have_property (u ("streamId" ), u ("e32445b743678c98230f238" )))
81
-
81
+
82
+
83
+ @httpretty .activate
84
+ def test_get_render_status (self ):
85
+ httpretty .register_uri (
86
+ httpretty .GET ,
87
+ u ("https://api.opentok.com/v2/project/{0}/render/{1}" ).format (self .api_key , self .render_id ),
88
+ body = textwrap .dedent (
89
+ u (
90
+ """\
91
+ {
92
+ "id": "80abaf0d-25a3-4efc-968f-6268d620668d",
93
+ "sessionId": "2_MX4xMDBfjE0Mzc2NzY1NDgwMTJ-TjMzfn4",
94
+ "projectId": "e2343f23456g34709d2443a234",
95
+ "createdAt": 1437676551000,
96
+ "updatedAt": 1437676551000,
97
+ "url": "https://webapp.customer.com",
98
+ "resolution": "1280x720",
99
+ "status": "failed",
100
+ "reason":"Could not load URL"
101
+ }
102
+ """
103
+ )
104
+ ),
105
+ status = 200 ,
106
+ content_type = u ("application/json" ),
107
+ )
108
+
109
+ render = self .opentok .get_render_status (self .render_id )
110
+
111
+ validate_jwt_header (self , httpretty .last_request ().headers [u ("x-opentok-auth" )])
112
+ expect (httpretty .last_request ().headers [u ("user-agent" )]).to (
113
+ contain (u ("OpenTok-Python-SDK/" ) + __version__ )
114
+ )
115
+ expect (httpretty .last_request ().headers [u ("content-type" )]).to (
116
+ equal (u ("application/json" ))
117
+
118
+ )
119
+
120
+ expect (render ).to (be_a (Render ))
121
+ expect (render ).to (
122
+ have_property (u ("id" ), u ("80abaf0d-25a3-4efc-968f-6268d620668d" ))
123
+ )
124
+ expect (render ).to (
125
+ have_property (u ("sessionId" ), u ("2_MX4xMDBfjE0Mzc2NzY1NDgwMTJ-TjMzfn4" ))
126
+ )
127
+ expect (render ).to (have_property (u ("projectId" ), u ("e2343f23456g34709d2443a234" )))
128
+ expect (render ).to (have_property (u ("createdAt" ), 1437676551000 ))
129
+ expect (render ).to (have_property (u ("updatedAt" ), 1437676551000 ))
130
+ expect (render ).to (have_property (u ("resolution" ), u ("1280x720" )))
131
+ expect (render ).to (have_property (u ("status" ), u ("failed" )))
132
+ expect (render ).to (have_property (u ("reason" ), u ("Could not load URL" )))
133
+
134
+ @httpretty .activate
135
+ def test_stop_render (self ):
136
+ httpretty .register_uri (
137
+ httpretty .DELETE ,
138
+ u ("https://api.opentok.com/v2/project/{0}/render/{1}" ).format (self .api_key , self .render_id ),
139
+ body = "" ,
140
+ status = 200 ,
141
+ )
142
+
143
+ response = self .opentok .stop_render (self .render_id )
144
+
145
+ validate_jwt_header (self , httpretty .last_request ().headers [u ("x-opentok-auth" )])
146
+ expect (httpretty .last_request ().headers [u ("user-agent" )]).to (
147
+ contain (u ("OpenTok-Python-SDK/" ) + __version__ )
148
+ )
149
+
150
+ assert isinstance (response , requests .Response )
151
+ assert response .status_code == 200
152
+
153
+ @httpretty .activate
154
+ def test_list_renders (self ):
155
+ httpretty .register_uri (
156
+ httpretty .GET ,
157
+ u ("https://api.opentok.com/v2/project/{0}/render" ).format (self .api_key ),
158
+ body = textwrap .dedent (
159
+ u (
160
+ """\
161
+ {
162
+ "count":2,
163
+ "items":[
164
+ {
165
+ "id":"80abaf0d-25a3-4efc-968f-6268d620668d",
166
+ "sessionId":"1_MX4yNzA4NjYxMn5-MTU0NzA4MDUyMTEzNn5sOXU5ZnlWYXplRnZGblV4RUo3dXJpZk1-fg",
167
+ "projectId":"27086612",
168
+ "createdAt":1547080532099,
169
+ "updatedAt":1547080532099,
170
+ "url": "https://webapp.customer.com",
171
+ "resolution": "1280x720",
172
+ "status": "started",
173
+ "streamId": "d2334b35690a92f78945"
174
+ },
175
+ {
176
+ "id":"d95f6496-df6e-4f49-86d6-832e00303602",
177
+ "sessionId":"2_MX4yNzA4NjYxMn5-MTU0NzA4MDUwMDc2MH5STWRiSE1jZjVoV3lBQU9nN2JuNElUV3V-fg",
178
+ "projectId":"27086612",
179
+ "createdAt":1547080511760,
180
+ "updatedAt":1547080518965,
181
+ "url": "https://webapp2.customer.com",
182
+ "resolution": "1280x720",
183
+ "status":"stopped",
184
+ "streamId": "d2334b35690a92f78945",
185
+ "reason":"Maximum duration exceeded"
186
+ }
187
+ ]
188
+ }
189
+ """
190
+ )
191
+ ),
192
+ status = 200 ,
193
+ content_type = u ("application/json" ),
194
+ )
195
+
196
+ render_list = self .opentok .list_renders ()
197
+ validate_jwt_header (self , httpretty .last_request ().headers [u ("x-opentok-auth" )])
198
+ expect (httpretty .last_request ().headers [u ("user-agent" )]).to (
199
+ contain (u ("OpenTok-Python-SDK/" ) + __version__ )
200
+ )
201
+
202
+ expect (render_list ).to (be_a (RenderList ))
203
+ expect (render_list ).to (have_property (u ("count" ), 2 ))
204
+ expect (render_list ).to (have_property (u ("items" )))
205
+ expect (render_list .items [0 ]).to (have_property (u ("sessionId" ), u ("1_MX4yNzA4NjYxMn5-MTU0NzA4MDUyMTEzNn5sOXU5ZnlWYXplRnZGblV4RUo3dXJpZk1-fg" )))
206
+ expect (render_list .items [0 ]).to (have_property (u ("createdAt" ), u (1547080532099 )))
207
+ expect (render_list .items [0 ]).to (have_property (u ("url" ), u ("https://webapp.customer.com" )))
208
+ expect (render_list .items [0 ]).to (have_property (u ("status" ), u ("started" )))
209
+ expect (render_list .items [0 ]).to (have_property (u ("streamId" ), u ("d2334b35690a92f78945" )))
210
+ expect (render_list .items [1 ]).to (have_property (u ("sessionId" ), u ("2_MX4yNzA4NjYxMn5-MTU0NzA4MDUwMDc2MH5STWRiSE1jZjVoV3lBQU9nN2JuNElUV3V-fg" )))
211
+ expect (render_list .items [1 ]).to (have_property (u ("createdAt" ), u (1547080511760 )))
212
+ expect (render_list .items [1 ]).to (have_property (u ("updatedAt" ), u (1547080518965 )))
213
+ expect (render_list .items [1 ]).to (have_property (u ("url" ), u ("https://webapp2.customer.com" )))
214
+ expect (render_list .items [1 ]).to (have_property (u ("status" ), u ("stopped" )))
215
+ expect (render_list .items [1 ]).to (have_property (u ("streamId" ), u ("d2334b35690a92f78945" )))
216
+ expect (render_list .items [1 ]).to (have_property (u ("reason" ), u ("Maximum duration exceeded" )))
0 commit comments