2
2
from six import text_type , u , b , PY2 , PY3
3
3
from six .moves .urllib .parse import parse_qs
4
4
from nose .tools import raises
5
- from sure import expect
5
+ from expects import *
6
6
import httpretty
7
7
from .validate_jwt import validate_jwt_header
8
8
@@ -24,14 +24,14 @@ def test_create_default_session(self):
24
24
session = self .opentok .create_session ()
25
25
26
26
validate_jwt_header (self , httpretty .last_request ().headers [u ('x-opentok-auth' )])
27
- expect (httpretty .last_request ().headers [u ('user-agent' )]).to . contain (u ('OpenTok-Python-SDK/' )+ __version__ )
27
+ expect (httpretty .last_request ().headers [u ('user-agent' )]).to ( contain (u ('OpenTok-Python-SDK/' )+ __version__ ) )
28
28
body = parse_qs (httpretty .last_request ().body )
29
- expect (body ).to . have . key ( b ('p2p.preference' )). being . equal ( [b ('enabled' )])
30
- expect (body ).to . have . key ( b ('archiveMode' )). being . equal ( [b ('manual' )])
31
- expect (session ).to . be . a ( Session )
32
- expect (session ).to . have . property ( u ('session_id' )). being . equal ( u ('1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg' ))
33
- expect (session ).to . have . property ( u ('media_mode' )). being . equal ( MediaModes .relayed )
34
- expect (session ).to . have . property ( u ('location' )). being . equal ( None )
29
+ expect (body ).to ( have_key ( b ('p2p.preference' ), [b ('enabled' )]) )
30
+ expect (body ).to ( have_key ( b ('archiveMode' ), [b ('manual' )]) )
31
+ expect (session ).to ( be_a ( Session ) )
32
+ expect (session ).to ( have_property ( u ('session_id' ), u ('1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg' ) ))
33
+ expect (session ).to ( have_property ( u ('media_mode' ), MediaModes .relayed ) )
34
+ expect (session ).to ( have_property ( u ('location' ), None ) )
35
35
36
36
@httpretty .activate
37
37
def test_create_routed_session (self ):
@@ -43,14 +43,14 @@ def test_create_routed_session(self):
43
43
session = self .opentok .create_session (media_mode = MediaModes .routed )
44
44
45
45
validate_jwt_header (self , httpretty .last_request ().headers [u ('x-opentok-auth' )])
46
- expect (httpretty .last_request ().headers [u ('user-agent' )]).to . contain (u ('OpenTok-Python-SDK/' )+ __version__ )
46
+ expect (httpretty .last_request ().headers [u ('user-agent' )]).to ( contain (u ('OpenTok-Python-SDK/' )+ __version__ ) )
47
47
body = parse_qs (httpretty .last_request ().body )
48
- expect (body ).to . have . key ( b ('p2p.preference' )). being . equal ( [b ('disabled' )])
49
- expect (body ).to . have . key ( b ('archiveMode' )). being . equal ( [b ('manual' )])
50
- expect (session ).to . be . a ( Session )
51
- expect (session ).to . have . property ( u ('session_id' )). being . equal ( u ('1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg' ))
52
- expect (session ).to . have . property ( u ('media_mode' )). being . equal ( MediaModes .routed )
53
- expect (session ).to . have . property ( u ('location' )). being . equal ( None )
48
+ expect (body ).to ( have_key ( b ('p2p.preference' ), [b ('disabled' )]) )
49
+ expect (body ).to ( have_key ( b ('archiveMode' ), [b ('manual' )]) )
50
+ expect (session ).to ( be_a ( Session ) )
51
+ expect (session ).to ( have_property ( u ('session_id' ), u ('1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg' ) ))
52
+ expect (session ).to ( have_property ( u ('media_mode' ), MediaModes .routed ) )
53
+ expect (session ).to ( have_property ( u ('location' ), None ) )
54
54
55
55
@httpretty .activate
56
56
def test_create_session_with_location_hint (self ):
@@ -62,15 +62,15 @@ def test_create_session_with_location_hint(self):
62
62
session = self .opentok .create_session (location = '12.34.56.78' )
63
63
64
64
validate_jwt_header (self , httpretty .last_request ().headers [u ('x-opentok-auth' )])
65
- expect (httpretty .last_request ().headers [u ('user-agent' )]).to . contain (u ('OpenTok-Python-SDK/' )+ __version__ )
65
+ expect (httpretty .last_request ().headers [u ('user-agent' )]).to ( contain (u ('OpenTok-Python-SDK/' )+ __version__ ) )
66
66
# ordering of keys is non-deterministic, must parse the body to see if it is correct
67
67
body = parse_qs (httpretty .last_request ().body )
68
- expect (body ).to . have . key ( b ('location' )). being . equal ( [b ('12.34.56.78' )])
69
- expect (body ).to . have . key ( b ('p2p.preference' )). being . equal ( [b ('enabled' )])
70
- expect (session ).to . be . a ( Session )
71
- expect (session ).to . have . property ( u ('session_id' )). being . equal ( u ('1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg' ))
72
- expect (session ).to . have . property ( u ('media_mode' )). being . equal ( MediaModes .relayed )
73
- expect (session ).to . have . property ( u ('location' )). being . equal ( u ('12.34.56.78' ))
68
+ expect (body ).to ( have_key ( b ('location' ), [b ('12.34.56.78' )]) )
69
+ expect (body ).to ( have_key ( b ('p2p.preference' ), [b ('enabled' )]) )
70
+ expect (session ).to ( be_a ( Session ) )
71
+ expect (session ).to ( have_property ( u ('session_id' ), u ('1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg' ) ))
72
+ expect (session ).to ( have_property ( u ('media_mode' ), MediaModes .relayed ) )
73
+ expect (session ).to ( have_property ( u ('location' ), u ('12.34.56.78' ) ))
74
74
75
75
@httpretty .activate
76
76
def test_create_routed_session_with_location_hint (self ):
@@ -82,15 +82,15 @@ def test_create_routed_session_with_location_hint(self):
82
82
session = self .opentok .create_session (location = '12.34.56.78' , media_mode = MediaModes .routed )
83
83
84
84
validate_jwt_header (self , httpretty .last_request ().headers [u ('x-opentok-auth' )])
85
- expect (httpretty .last_request ().headers [u ('user-agent' )]).to . contain (u ('OpenTok-Python-SDK/' )+ __version__ )
85
+ expect (httpretty .last_request ().headers [u ('user-agent' )]).to ( contain (u ('OpenTok-Python-SDK/' )+ __version__ ) )
86
86
# ordering of keys is non-deterministic, must parse the body to see if it is correct
87
87
body = parse_qs (httpretty .last_request ().body )
88
- expect (body ).to . have . key ( b ('location' )). being . equal ( [b ('12.34.56.78' )])
89
- expect (body ).to . have . key ( b ('p2p.preference' )). being . equal ( [b ('disabled' )])
90
- expect (session ).to . be . a ( Session )
91
- expect (session ).to . have . property ( u ('session_id' )). being . equal ( u ('1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg' ))
92
- expect (session ).to . have . property ( u ('media_mode' )). being . equal ( MediaModes .routed )
93
- expect (session ).to . have . property ( u ('location' )). being . equal ( u ('12.34.56.78' ))
88
+ expect (body ).to ( have_key ( b ('location' ), [b ('12.34.56.78' )]) )
89
+ expect (body ).to ( have_key ( b ('p2p.preference' ), [b ('disabled' )]) )
90
+ expect (session ).to ( be_a ( Session ) )
91
+ expect (session ).to ( have_property ( u ('session_id' ), u ('1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg' ) ))
92
+ expect (session ).to ( have_property ( u ('media_mode' ), MediaModes .routed ) )
93
+ expect (session ).to ( have_property ( u ('location' ), u ('12.34.56.78' ) ))
94
94
95
95
@httpretty .activate
96
96
def test_create_manual_archive_mode_session (self ):
@@ -102,14 +102,14 @@ def test_create_manual_archive_mode_session(self):
102
102
session = self .opentok .create_session (media_mode = MediaModes .routed , archive_mode = ArchiveModes .manual )
103
103
104
104
validate_jwt_header (self , httpretty .last_request ().headers [u ('x-opentok-auth' )])
105
- expect (httpretty .last_request ().headers [u ('user-agent' )]).to . contain (u ('OpenTok-Python-SDK/' )+ __version__ )
105
+ expect (httpretty .last_request ().headers [u ('user-agent' )]).to ( contain (u ('OpenTok-Python-SDK/' )+ __version__ ) )
106
106
body = parse_qs (httpretty .last_request ().body )
107
- expect (body ).to . have . key ( b ('p2p.preference' )). being . equal ( [b ('disabled' )])
108
- expect (body ).to . have . key ( b ('archiveMode' )). being . equal ( [b ('manual' )])
109
- expect (session ).to . be . a ( Session )
110
- expect (session ).to . have . property ( u ('session_id' )). being . equal ( u ('1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg' ))
111
- expect (session ).to . have . property ( u ('media_mode' )). being . equal ( MediaModes .routed )
112
- expect (session ).to . have . property ( u ('archive_mode' )). being . equal ( ArchiveModes .manual )
107
+ expect (body ).to ( have_key ( b ('p2p.preference' ), [b ('disabled' )]) )
108
+ expect (body ).to ( have_key ( b ('archiveMode' ), [b ('manual' )]) )
109
+ expect (session ).to ( be_a ( Session ) )
110
+ expect (session ).to ( have_property ( u ('session_id' ), u ('1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg' ) ))
111
+ expect (session ).to ( have_property ( u ('media_mode' ), MediaModes .routed ) )
112
+ expect (session ).to ( have_property ( u ('archive_mode' ), ArchiveModes .manual ) )
113
113
114
114
@httpretty .activate
115
115
def test_create_always_archive_mode_session (self ):
@@ -121,14 +121,14 @@ def test_create_always_archive_mode_session(self):
121
121
session = self .opentok .create_session (media_mode = MediaModes .routed , archive_mode = ArchiveModes .always )
122
122
123
123
validate_jwt_header (self , httpretty .last_request ().headers [u ('x-opentok-auth' )])
124
- expect (httpretty .last_request ().headers [u ('user-agent' )]).to . contain (u ('OpenTok-Python-SDK/' )+ __version__ )
124
+ expect (httpretty .last_request ().headers [u ('user-agent' )]).to ( contain (u ('OpenTok-Python-SDK/' )+ __version__ ) )
125
125
body = parse_qs (httpretty .last_request ().body )
126
- expect (body ).to . have . key ( b ('p2p.preference' )). being . equal ( [b ('disabled' )])
127
- expect (body ).to . have . key ( b ('archiveMode' )). being . equal ( [b ('always' )])
128
- expect (session ).to . be . a ( Session )
129
- expect (session ).to . have . property ( u ('session_id' )). being . equal ( u ('1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg' ))
130
- expect (session ).to . have . property ( u ('media_mode' )). being . equal ( MediaModes .routed )
131
- expect (session ).to . have . property ( u ('archive_mode' )). being . equal ( ArchiveModes .always )
126
+ expect (body ).to ( have_key ( b ('p2p.preference' ), [b ('disabled' )]) )
127
+ expect (body ).to ( have_key ( b ('archiveMode' ), [b ('always' )]) )
128
+ expect (session ).to ( be_a ( Session ) )
129
+ expect (session ).to ( have_property ( u ('session_id' ), u ('1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg' ) ))
130
+ expect (session ).to ( have_property ( u ('media_mode' ), MediaModes .routed ) )
131
+ expect (session ).to ( have_property ( u ('archive_mode' ), ArchiveModes .always ) )
132
132
133
133
@httpretty .activate
134
134
def test_complains_about_always_archive_mode_and_relayed_session (self ):
0 commit comments