5
5
from sure import expect
6
6
import httpretty
7
7
8
- from opentok import OpenTok , Session , MediaModes , OpenTokException , __version__
8
+ from opentok import OpenTok , Session , MediaModes , ArchiveModes , OpenTokException , __version__
9
9
10
10
class OpenTokSessionCreationTest (unittest .TestCase ):
11
11
def setUp (self ):
@@ -24,7 +24,9 @@ def test_create_default_session(self):
24
24
25
25
expect (httpretty .last_request ().headers [u ('x-tb-partner-auth' )]).to .equal (self .api_key + u (':' )+ self .api_secret )
26
26
expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
27
- expect (httpretty .last_request ().body ).to .equal (b ('p2p.preference=enabled' ))
27
+ body = parse_qs (httpretty .last_request ().body )
28
+ expect (body ).to .have .key (b ('p2p.preference' )).being .equal ([b ('enabled' )])
29
+ expect (body ).to .have .key (b ('archiveMode' )).being .equal ([b ('manual' )])
28
30
expect (session ).to .be .a (Session )
29
31
expect (session ).to .have .property (u ('session_id' )).being .equal (u ('1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg' ))
30
32
expect (session ).to .have .property (u ('media_mode' )).being .equal (MediaModes .relayed )
@@ -41,7 +43,9 @@ def test_create_routed_session(self):
41
43
42
44
expect (httpretty .last_request ().headers [u ('x-tb-partner-auth' )]).to .equal (self .api_key + u (':' )+ self .api_secret )
43
45
expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
44
- expect (httpretty .last_request ().body ).to .equal (b ('p2p.preference=disabled' ))
46
+ body = parse_qs (httpretty .last_request ().body )
47
+ expect (body ).to .have .key (b ('p2p.preference' )).being .equal ([b ('disabled' )])
48
+ expect (body ).to .have .key (b ('archiveMode' )).being .equal ([b ('manual' )])
45
49
expect (session ).to .be .a (Session )
46
50
expect (session ).to .have .property (u ('session_id' )).being .equal (u ('1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg' ))
47
51
expect (session ).to .have .property (u ('media_mode' )).being .equal (MediaModes .routed )
@@ -87,5 +91,51 @@ def test_create_routed_session_with_location_hint(self):
87
91
expect (session ).to .have .property (u ('media_mode' )).being .equal (MediaModes .routed )
88
92
expect (session ).to .have .property (u ('location' )).being .equal (u ('12.34.56.78' ))
89
93
94
+ @httpretty .activate
95
+ def test_create_manual_archive_mode_session (self ):
96
+ httpretty .register_uri (httpretty .POST , u ('https://api.opentok.com/session/create' ),
97
+ body = u ('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><sessions><Session><session_id>1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg</session_id><partner_id>123456</partner_id><create_dt>Mon Mar 17 00:41:31 PDT 2014</create_dt></Session></sessions>' ),
98
+ status = 200 ,
99
+ content_type = u ('text/xml' ))
100
+
101
+ session = self .opentok .create_session (media_mode = MediaModes .routed , archive_mode = ArchiveModes .manual )
102
+
103
+ expect (httpretty .last_request ().headers [u ('x-tb-partner-auth' )]).to .equal (self .api_key + u (':' )+ self .api_secret )
104
+ expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
105
+ body = parse_qs (httpretty .last_request ().body )
106
+ expect (body ).to .have .key (b ('p2p.preference' )).being .equal ([b ('disabled' )])
107
+ expect (body ).to .have .key (b ('archiveMode' )).being .equal ([b ('manual' )])
108
+ expect (session ).to .be .a (Session )
109
+ expect (session ).to .have .property (u ('session_id' )).being .equal (u ('1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg' ))
110
+ expect (session ).to .have .property (u ('media_mode' )).being .equal (MediaModes .routed )
111
+ expect (session ).to .have .property (u ('archive_mode' )).being .equal (ArchiveModes .manual )
112
+
113
+ @httpretty .activate
114
+ def test_create_always_archive_mode_session (self ):
115
+ httpretty .register_uri (httpretty .POST , u ('https://api.opentok.com/session/create' ),
116
+ body = u ('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><sessions><Session><session_id>1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg</session_id><partner_id>123456</partner_id><create_dt>Mon Mar 17 00:41:31 PDT 2014</create_dt></Session></sessions>' ),
117
+ status = 200 ,
118
+ content_type = u ('text/xml' ))
119
+
120
+ session = self .opentok .create_session (media_mode = MediaModes .routed , archive_mode = ArchiveModes .always )
121
+
122
+ expect (httpretty .last_request ().headers [u ('x-tb-partner-auth' )]).to .equal (self .api_key + u (':' )+ self .api_secret )
123
+ expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
124
+ body = parse_qs (httpretty .last_request ().body )
125
+ expect (body ).to .have .key (b ('p2p.preference' )).being .equal ([b ('disabled' )])
126
+ expect (body ).to .have .key (b ('archiveMode' )).being .equal ([b ('always' )])
127
+ expect (session ).to .be .a (Session )
128
+ expect (session ).to .have .property (u ('session_id' )).being .equal (u ('1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg' ))
129
+ expect (session ).to .have .property (u ('media_mode' )).being .equal (MediaModes .routed )
130
+ expect (session ).to .have .property (u ('archive_mode' )).being .equal (ArchiveModes .always )
131
+
132
+ @httpretty .activate
133
+ def test_complains_about_always_archive_mode_and_relayed_session (self ):
134
+ httpretty .register_uri (httpretty .POST , u ('https://api.opentok.com/session/create' ),
135
+ body = u ('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><sessions><Session><session_id>1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg</session_id><partner_id>123456</partner_id><create_dt>Mon Mar 17 00:41:31 PDT 2014</create_dt></Session></sessions>' ),
136
+ status = 200 ,
137
+ content_type = u ('text/xml' ))
138
+ self .assertRaises (OpenTokException , self .opentok .create_session , media_mode = MediaModes .relayed , archive_mode = ArchiveModes .always )
139
+
90
140
# TODO: all the cases that throw exceptions
91
141
# TODO: custom api_url requests
0 commit comments