|
9 | 9 | import pytz
|
10 | 10 | from .validate_jwt import validate_jwt_header
|
11 | 11 |
|
12 |
| -from opentok import OpenTok, Archive, ArchiveList, OutputModes, __version__ |
| 12 | +from opentok import OpenTok, Archive, ArchiveList, OutputModes, OpenTokException, __version__ |
13 | 13 |
|
14 | 14 | class OpenTokArchiveApiTest(unittest.TestCase):
|
15 | 15 | def setUp(self):
|
@@ -118,6 +118,119 @@ def test_start_archive_with_name(self):
|
118 | 118 | expect(archive).to(have_property(u('duration'), equal(0)))
|
119 | 119 | expect(archive).to(have_property(u('url'), equal(None)))
|
120 | 120 |
|
| 121 | + @httpretty.activate |
| 122 | + def test_start_archive_with_640x480_resolution(self): |
| 123 | + httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/v2/project/{0}/archive').format(self.api_key), |
| 124 | + body=textwrap.dedent(u("""\ |
| 125 | + { |
| 126 | + "createdAt" : 1395183243556, |
| 127 | + "duration" : 0, |
| 128 | + "id" : "30b3ebf1-ba36-4f5b-8def-6f70d9986fe9", |
| 129 | + "name" : "ARCHIVE NAME", |
| 130 | + "partnerId" : 123456, |
| 131 | + "reason" : "", |
| 132 | + "sessionId" : "SESSIONID", |
| 133 | + "size" : 0, |
| 134 | + "status" : "started", |
| 135 | + "hasAudio": true, |
| 136 | + "hasVideo": true, |
| 137 | + "outputMode": "composed", |
| 138 | + "url" : null, |
| 139 | + "resolution": "640x480" |
| 140 | + }""")), |
| 141 | + status=200, |
| 142 | + content_type=u('application/json')) |
| 143 | + |
| 144 | + archive = self.opentok.start_archive(self.session_id, resolution="640x480") |
| 145 | + |
| 146 | + validate_jwt_header(self, httpretty.last_request().headers[u('x-opentok-auth')]) |
| 147 | + expect(httpretty.last_request().headers[u('user-agent')]).to(contain(u('OpenTok-Python-SDK/')+__version__)) |
| 148 | + expect(httpretty.last_request().headers[u('content-type')]).to(equal(u('application/json'))) |
| 149 | + # non-deterministic json encoding. have to decode to test it properly |
| 150 | + if PY2: |
| 151 | + body = json.loads(httpretty.last_request().body) |
| 152 | + if PY3: |
| 153 | + body = json.loads(httpretty.last_request().body.decode('utf-8')) |
| 154 | + expect(body).to(have_key(u('sessionId'), u('SESSIONID'))) |
| 155 | + expect(body).to(have_key(u('resolution'), u('640x480'))) |
| 156 | + expect(archive).to(be_an(Archive)) |
| 157 | + expect(archive).to(have_property(u('id'), u('30b3ebf1-ba36-4f5b-8def-6f70d9986fe9'))) |
| 158 | + expect(archive).to(have_property(u('resolution'), "640x480")) |
| 159 | + expect(archive).to(have_property(u('status'), u('started'))) |
| 160 | + expect(archive).to(have_property(u('session_id'), u('SESSIONID'))) |
| 161 | + expect(archive).to(have_property(u('partner_id'), 123456)) |
| 162 | + if PY2: |
| 163 | + created_at = datetime.datetime.fromtimestamp(1395183243, pytz.UTC) |
| 164 | + if PY3: |
| 165 | + created_at = datetime.datetime.fromtimestamp(1395183243, datetime.timezone.utc) |
| 166 | + expect(archive).to(have_property(u('created_at'), equal(created_at))) |
| 167 | + expect(archive).to(have_property(u('size'), equal(0))) |
| 168 | + expect(archive).to(have_property(u('duration'), equal(0))) |
| 169 | + expect(archive).to(have_property(u('url'), equal(None))) |
| 170 | + |
| 171 | + @httpretty.activate |
| 172 | + def test_start_archive_with_1280x720_resolution(self): |
| 173 | + httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/v2/project/{0}/archive').format(self.api_key), |
| 174 | + body=textwrap.dedent(u("""\ |
| 175 | + { |
| 176 | + "createdAt" : 1395183243556, |
| 177 | + "duration" : 0, |
| 178 | + "id" : "30b3ebf1-ba36-4f5b-8def-6f70d9986fe9", |
| 179 | + "name" : "ARCHIVE NAME", |
| 180 | + "partnerId" : 123456, |
| 181 | + "reason" : "", |
| 182 | + "sessionId" : "SESSIONID", |
| 183 | + "size" : 0, |
| 184 | + "status" : "started", |
| 185 | + "hasAudio": true, |
| 186 | + "hasVideo": true, |
| 187 | + "outputMode": "composed", |
| 188 | + "url" : null, |
| 189 | + "resolution": "1280x720" |
| 190 | + }""")), |
| 191 | + status=200, |
| 192 | + content_type=u('application/json')) |
| 193 | + |
| 194 | + archive = self.opentok.start_archive(self.session_id, resolution="1280x720") |
| 195 | + |
| 196 | + validate_jwt_header(self, httpretty.last_request().headers[u('x-opentok-auth')]) |
| 197 | + expect(httpretty.last_request().headers[u('user-agent')]).to(contain(u('OpenTok-Python-SDK/')+__version__)) |
| 198 | + expect(httpretty.last_request().headers[u('content-type')]).to(equal(u('application/json'))) |
| 199 | + # non-deterministic json encoding. have to decode to test it properly |
| 200 | + if PY2: |
| 201 | + body = json.loads(httpretty.last_request().body) |
| 202 | + if PY3: |
| 203 | + body = json.loads(httpretty.last_request().body.decode('utf-8')) |
| 204 | + expect(body).to(have_key(u('sessionId'), u('SESSIONID'))) |
| 205 | + expect(body).to(have_key(u('resolution'), u('1280x720'))) |
| 206 | + expect(archive).to(be_an(Archive)) |
| 207 | + expect(archive).to(have_property(u('id'), u('30b3ebf1-ba36-4f5b-8def-6f70d9986fe9'))) |
| 208 | + expect(archive).to(have_property(u('resolution'), "1280x720")) |
| 209 | + expect(archive).to(have_property(u('status'), u('started'))) |
| 210 | + expect(archive).to(have_property(u('session_id'), u('SESSIONID'))) |
| 211 | + expect(archive).to(have_property(u('partner_id'), 123456)) |
| 212 | + if PY2: |
| 213 | + created_at = datetime.datetime.fromtimestamp(1395183243, pytz.UTC) |
| 214 | + if PY3: |
| 215 | + created_at = datetime.datetime.fromtimestamp(1395183243, datetime.timezone.utc) |
| 216 | + expect(archive).to(have_property(u('created_at'), equal(created_at))) |
| 217 | + expect(archive).to(have_property(u('size'), equal(0))) |
| 218 | + expect(archive).to(have_property(u('duration'), equal(0))) |
| 219 | + expect(archive).to(have_property(u('url'), equal(None))) |
| 220 | + |
| 221 | + def test_start_archive_individual_and_resolution_throws_error(self): |
| 222 | + self.assertRaises(OpenTokException, |
| 223 | + self.opentok.start_archive, |
| 224 | + session_id=self.session_id, |
| 225 | + output_mode=OutputModes.individual, |
| 226 | + resolution="640x480") |
| 227 | + |
| 228 | + self.assertRaises(OpenTokException, |
| 229 | + self.opentok.start_archive, |
| 230 | + session_id=self.session_id, |
| 231 | + output_mode=OutputModes.individual, |
| 232 | + resolution="1280x720") |
| 233 | + |
121 | 234 | @httpretty.activate
|
122 | 235 | def test_start_voice_archive(self):
|
123 | 236 | httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/v2/project/{0}/archive').format(self.api_key),
|
|
0 commit comments