Skip to content

Commit 635f10c

Browse files
authored
Merge branch 'master' into patch-2
2 parents e80c4e6 + c38162e commit 635f10c

File tree

5 files changed

+28
-21
lines changed

5 files changed

+28
-21
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ language: python
22
python:
33
- '2.6'
44
- '2.7'
5-
- '3.2'
65
- '3.3'
76
- '3.4'
87
- '3.5'
8+
- '3.6'
99
install:
1010
- pip install -r test_requirements.txt
1111
- pip install -r requirements.txt

opentok/opentok.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def generate_token(self, session_id, role=Roles.publisher, expire_time=None, dat
130130
raise OpenTokException(u('Cannot generate token, expire_time is not in the future {0}').format(expire_time))
131131
if expire_time > now + (60*60*24*30): # 30 days
132132
raise OpenTokException(u('Cannot generate token, expire_time is not in the next 30 days {0}').format(expire_time))
133-
if (data is not None) and len(data) > 1000:
133+
if data and len(data) > 1000:
134134
raise OpenTokException(u('Cannot generate token, data must be less than 1000 characters').format(data))
135135

136136
# decode session id to verify api_key
@@ -150,9 +150,10 @@ def generate_token(self, session_id, role=Roles.publisher, expire_time=None, dat
150150
create_time = now,
151151
expire_time = expire_time,
152152
role = role.value,
153-
connection_data = (data or None),
154153
nonce = random.randint(0,999999)
155154
)
155+
if data:
156+
data_params['connection_data'] = data
156157
data_string = urlencode(data_params, True)
157158

158159
sig = self._sign_string(data_string, self.api_secret)
@@ -291,7 +292,7 @@ def session_url(self):
291292

292293
def archive_url(self, archive_id=None):
293294
"""For internal use."""
294-
url = self.api_url + '/v2/partner/' + self.api_key + '/archive'
295+
url = self.api_url + '/v2/project/' + self.api_key + '/archive'
295296
if archive_id:
296297
url = url + '/' + archive_id
297298
return url

tests/test_archive.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_stop_archive(self):
3535
u('outputMode'): OutputModes.composed.value,
3636
u('url'): None,
3737
})
38-
httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/v2/partner/{0}/archive/{1}/stop').format(self.api_key, archive_id),
38+
httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/v2/project/{0}/archive/{1}/stop').format(self.api_key, archive_id),
3939
body=textwrap.dedent(u("""\
4040
{
4141
"createdAt" : 1395183243556,
@@ -96,7 +96,7 @@ def test_delete_archive(self):
9696
u('outputMode'): OutputModes.composed.value,
9797
u('url'): None,
9898
})
99-
httpretty.register_uri(httpretty.DELETE, u('https://api.opentok.com/v2/partner/{0}/archive/{1}').format(self.api_key, archive_id),
99+
httpretty.register_uri(httpretty.DELETE, u('https://api.opentok.com/v2/project/{0}/archive/{1}').format(self.api_key, archive_id),
100100
body=u(''),
101101
status=204)
102102

tests/test_archive_api.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def setUp(self):
2020

2121
@httpretty.activate
2222
def test_start_archive(self):
23-
httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/v2/partner/{0}/archive').format(self.api_key),
23+
httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/v2/project/{0}/archive').format(self.api_key),
2424
body=textwrap.dedent(u("""\
2525
{
2626
"createdAt" : 1395183243556,
@@ -71,7 +71,7 @@ def test_start_archive(self):
7171

7272
@httpretty.activate
7373
def test_start_archive_with_name(self):
74-
httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/v2/partner/{0}/archive').format(self.api_key),
74+
httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/v2/project/{0}/archive').format(self.api_key),
7575
body=textwrap.dedent(u("""\
7676
{
7777
"createdAt" : 1395183243556,
@@ -120,7 +120,7 @@ def test_start_archive_with_name(self):
120120

121121
@httpretty.activate
122122
def test_start_voice_archive(self):
123-
httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/v2/partner/{0}/archive').format(self.api_key),
123+
httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/v2/project/{0}/archive').format(self.api_key),
124124
body=textwrap.dedent(u("""\
125125
{
126126
"createdAt" : 1395183243556,
@@ -171,7 +171,7 @@ def test_start_voice_archive(self):
171171

172172
@httpretty.activate
173173
def test_start_individual_archive(self):
174-
httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/v2/partner/{0}/archive').format(self.api_key),
174+
httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/v2/project/{0}/archive').format(self.api_key),
175175
body=textwrap.dedent(u("""\
176176
{
177177
"createdAt" : 1395183243556,
@@ -223,7 +223,7 @@ def test_start_individual_archive(self):
223223

224224
@httpretty.activate
225225
def test_start_composed_archive(self):
226-
httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/v2/partner/{0}/archive').format(self.api_key),
226+
httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/v2/project/{0}/archive').format(self.api_key),
227227
body=textwrap.dedent(u("""\
228228
{
229229
"createdAt" : 1395183243556,
@@ -276,7 +276,7 @@ def test_start_composed_archive(self):
276276
@httpretty.activate
277277
def test_stop_archive(self):
278278
archive_id = u('30b3ebf1-ba36-4f5b-8def-6f70d9986fe9')
279-
httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/v2/partner/{0}/archive/{1}/stop').format(self.api_key, archive_id),
279+
httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/v2/project/{0}/archive/{1}/stop').format(self.api_key, archive_id),
280280
body=textwrap.dedent(u("""\
281281
{
282282
"createdAt" : 1395183243000,
@@ -319,7 +319,7 @@ def test_stop_archive(self):
319319
@httpretty.activate
320320
def test_delete_archive(self):
321321
archive_id = u('30b3ebf1-ba36-4f5b-8def-6f70d9986fe9')
322-
httpretty.register_uri(httpretty.DELETE, u('https://api.opentok.com/v2/partner/{0}/archive/{1}').format(self.api_key, archive_id),
322+
httpretty.register_uri(httpretty.DELETE, u('https://api.opentok.com/v2/project/{0}/archive/{1}').format(self.api_key, archive_id),
323323
body=u(''),
324324
status=204)
325325

@@ -332,7 +332,7 @@ def test_delete_archive(self):
332332
@httpretty.activate
333333
def test_find_archive(self):
334334
archive_id = u('f6e7ee58-d6cf-4a59-896b-6d56b158ec71')
335-
httpretty.register_uri(httpretty.GET, u('https://api.opentok.com/v2/partner/{0}/archive/{1}').format(self.api_key, archive_id),
335+
httpretty.register_uri(httpretty.GET, u('https://api.opentok.com/v2/project/{0}/archive/{1}').format(self.api_key, archive_id),
336336
body=textwrap.dedent(u("""\
337337
{
338338
"createdAt" : 1395187836000,
@@ -374,7 +374,7 @@ def test_find_archive(self):
374374

375375
@httpretty.activate
376376
def test_find_archives(self):
377-
httpretty.register_uri(httpretty.GET, u('https://api.opentok.com/v2/partner/{0}/archive').format(self.api_key),
377+
httpretty.register_uri(httpretty.GET, u('https://api.opentok.com/v2/project/{0}/archive').format(self.api_key),
378378
body=textwrap.dedent(u("""\
379379
{
380380
"count" : 6,
@@ -479,7 +479,7 @@ def test_find_archives(self):
479479

480480
@httpretty.activate
481481
def test_find_archives_with_offset(self):
482-
httpretty.register_uri(httpretty.GET, u('https://api.opentok.com/v2/partner/{0}/archive').format(self.api_key),
482+
httpretty.register_uri(httpretty.GET, u('https://api.opentok.com/v2/project/{0}/archive').format(self.api_key),
483483
body=textwrap.dedent(u("""\
484484
{
485485
"count" : 6,
@@ -542,7 +542,7 @@ def test_find_archives_with_offset(self):
542542

543543
@httpretty.activate
544544
def test_find_archives_with_count(self):
545-
httpretty.register_uri(httpretty.GET, u('https://api.opentok.com/v2/partner/{0}/archive').format(self.api_key),
545+
httpretty.register_uri(httpretty.GET, u('https://api.opentok.com/v2/project/{0}/archive').format(self.api_key),
546546
body=textwrap.dedent(u("""\
547547
{
548548
"count" : 6,
@@ -592,7 +592,7 @@ def test_find_archives_with_count(self):
592592

593593
@httpretty.activate
594594
def test_find_archives_with_offset_and_count(self):
595-
httpretty.register_uri(httpretty.GET, u('https://api.opentok.com/v2/partner/{0}/archive').format(self.api_key),
595+
httpretty.register_uri(httpretty.GET, u('https://api.opentok.com/v2/project/{0}/archive').format(self.api_key),
596596
body=textwrap.dedent(u("""\
597597
{
598598
"count" : 6,
@@ -670,7 +670,7 @@ def test_find_archives_with_offset_and_count(self):
670670
@httpretty.activate
671671
def test_find_paused_archive(self):
672672
archive_id = u('f6e7ee58-d6cf-4a59-896b-6d56b158ec71')
673-
httpretty.register_uri(httpretty.GET, u('https://api.opentok.com/v2/partner/{0}/archive/{1}').format(self.api_key, archive_id),
673+
httpretty.register_uri(httpretty.GET, u('https://api.opentok.com/v2/project/{0}/archive/{1}').format(self.api_key, archive_id),
674674
body=textwrap.dedent(u("""\
675675
{
676676
"createdAt" : 1395187836000,
@@ -697,7 +697,7 @@ def test_find_paused_archive(self):
697697
@httpretty.activate
698698
def test_find_expired_archive(self):
699699
archive_id = u('f6e7ee58-d6cf-4a59-896b-6d56b158ec71')
700-
httpretty.register_uri(httpretty.GET, u('https://api.opentok.com/v2/partner/{0}/archive/{1}').format(self.api_key, archive_id),
700+
httpretty.register_uri(httpretty.GET, u('https://api.opentok.com/v2/project/{0}/archive/{1}').format(self.api_key, archive_id),
701701
body=textwrap.dedent(u("""\
702702
{
703703
"createdAt" : 1395187836000,
@@ -724,7 +724,7 @@ def test_find_expired_archive(self):
724724
@httpretty.activate
725725
def test_find_archive_with_unknown_properties(self):
726726
archive_id = u('f6e7ee58-d6cf-4a59-896b-6d56b158ec71')
727-
httpretty.register_uri(httpretty.GET, u('https://api.opentok.com/v2/partner/{0}/archive/{1}').format(self.api_key, archive_id),
727+
httpretty.register_uri(httpretty.GET, u('https://api.opentok.com/v2/project/{0}/archive/{1}').format(self.api_key, archive_id),
728728
body=textwrap.dedent(u("""\
729729
{
730730
"createdAt" : 1395187836000,

tests/test_token_generation.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ def test_generate_data_token(self):
6464
assert token_decoder(token)[u('connection_data')] == data
6565
assert token_signature_validator(token, self.api_secret)
6666

67+
def test_generate_no_data_token(self):
68+
token = self.opentok.generate_token(self.session_id)
69+
assert isinstance(token, text_type)
70+
assert u('connection_data') not in token_decoder(token)
71+
assert token_signature_validator(token, self.api_secret)
72+
6773
@raises(TypeError)
6874
def test_does_not_generate_token_without_params(self):
6975
token = self.opentok.generate_token()

0 commit comments

Comments
 (0)