Skip to content

Commit 1434c22

Browse files
committed
adds tests for archive methods
1 parent 50ea4fe commit 1434c22

File tree

2 files changed

+100
-1
lines changed

2 files changed

+100
-1
lines changed

opentok/archives.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ def __init__(self, sdk, values):
2828
self.url = values.get('url')
2929

3030
def stop(self):
31-
self.sdk.stop_archive(self.id)
31+
temp_archive = self.sdk.stop_archive(self.id)
32+
for k,v in iteritems(temp_archive.attrs()):
33+
setattr(self, k, v)
3234

3335
def delete(self):
3436
self.sdk.delete_archive(self.id)
37+
# TODO: invalidate this object
3538

3639
def attrs(self):
3740
return dict((k, v) for k, v in iteritems(self.__dict__) if k is not "sdk")

tests/test_archive.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import unittest
2+
from six import text_type, u, b, PY2, PY3
3+
from nose.tools import raises
4+
from sure import expect
5+
import httpretty
6+
import textwrap
7+
import json
8+
import datetime
9+
import pytz
10+
11+
from opentok import OpenTok, Archive, ArchiveList, __version__
12+
13+
class OpenTokArchiveApiTest(unittest.TestCase):
14+
def setUp(self):
15+
self.api_key = u('123456')
16+
self.api_secret = u('1234567890abcdef1234567890abcdef1234567890')
17+
self.opentok = OpenTok(self.api_key, self.api_secret)
18+
19+
@httpretty.activate
20+
def test_stop_archive(self):
21+
archive_id = u('ARCHIVEID')
22+
archive = Archive(self.opentok, {
23+
u('createdAt'): 1395183243556,
24+
u('duration'): 0,
25+
u('id'): archive_id,
26+
u('name'): u(''),
27+
u('partnerId'): 123456,
28+
u('reason'): u(''),
29+
u('sessionId'): u('SESSIONID'),
30+
u('size'): 0,
31+
u('status'): u('started'),
32+
u('url'): None,
33+
})
34+
httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/v2/partner/{0}/archive/{1}/stop').format(self.api_key, archive_id),
35+
body=textwrap.dedent(u("""\
36+
{
37+
"createdAt" : 1395183243556,
38+
"duration" : 0,
39+
"id" : "ARCHIVEID",
40+
"name" : "",
41+
"partnerId" : 123456,
42+
"reason" : "",
43+
"sessionId" : "SESSIONID",
44+
"size" : 0,
45+
"status" : "stopped",
46+
"url" : null
47+
}""")),
48+
status=200,
49+
content_type=u('application/json'))
50+
51+
archive.stop()
52+
53+
expect(httpretty.last_request().headers[u('x-tb-partner-auth')]).to.equal(self.api_key+u(':')+self.api_secret)
54+
expect(httpretty.last_request().headers[u('user-agent')]).to.contain(u('OpenTok-Python-SDK/')+__version__)
55+
expect(httpretty.last_request().headers[u('content-type')]).to.equal(u('application/json'))
56+
expect(archive).to.be.an(Archive)
57+
expect(archive).to.have.property(u('id')).being.equal(archive_id)
58+
expect(archive).to.have.property(u('name')).being.equal(u(''))
59+
expect(archive).to.have.property(u('status')).being.equal(u('stopped'))
60+
expect(archive).to.have.property(u('session_id')).being.equal(u('SESSIONID'))
61+
expect(archive).to.have.property(u('partner_id')).being.equal(123456)
62+
if PY2:
63+
created_at = datetime.datetime.fromtimestamp(1395183243, pytz.UTC)
64+
if PY3:
65+
created_at = datetime.datetime.fromtimestamp(1395183243, datetime.timezone.utc)
66+
expect(archive).to.have.property(u('created_at')).being.equal(created_at)
67+
expect(archive).to.have.property(u('size')).being.equal(0)
68+
expect(archive).to.have.property(u('duration')).being.equal(0)
69+
expect(archive).to.have.property(u('url')).being.equal(None)
70+
71+
@httpretty.activate
72+
def test_delete_archive(self):
73+
archive_id = u('ARCHIVEID')
74+
archive = Archive(self.opentok, {
75+
u('createdAt'): 1395183243556,
76+
u('duration'): 0,
77+
u('id'): archive_id,
78+
u('name'): u(''),
79+
u('partnerId'): 123456,
80+
u('reason'): u(''),
81+
u('sessionId'): u('SESSIONID'),
82+
u('size'): 0,
83+
u('status'): u('available'),
84+
u('url'): None,
85+
})
86+
httpretty.register_uri(httpretty.DELETE, u('https://api.opentok.com/v2/partner/{0}/archive/{1}').format(self.api_key, archive_id),
87+
body=u(''),
88+
status=204)
89+
90+
archive.delete()
91+
92+
expect(httpretty.last_request().headers[u('x-tb-partner-auth')]).to.equal(self.api_key+u(':')+self.api_secret)
93+
expect(httpretty.last_request().headers[u('user-agent')]).to.contain(u('OpenTok-Python-SDK/')+__version__)
94+
expect(httpretty.last_request().headers[u('content-type')]).to.equal(u('application/json'))
95+
# TODO: test that the object is invalidated
96+

0 commit comments

Comments
 (0)