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,7 @@ 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
+ expect (httpretty .last_request ().body ).to .equal (b ('archiveMode=manual& p2p.preference=enabled' ))
28
28
expect (session ).to .be .a (Session )
29
29
expect (session ).to .have .property (u ('session_id' )).being .equal (u ('1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg' ))
30
30
expect (session ).to .have .property (u ('media_mode' )).being .equal (MediaModes .relayed )
@@ -41,7 +41,7 @@ def test_create_routed_session(self):
41
41
42
42
expect (httpretty .last_request ().headers [u ('x-tb-partner-auth' )]).to .equal (self .api_key + u (':' )+ self .api_secret )
43
43
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' ))
44
+ expect (httpretty .last_request ().body ).to .equal (b ('archiveMode=manual& p2p.preference=disabled' ))
45
45
expect (session ).to .be .a (Session )
46
46
expect (session ).to .have .property (u ('session_id' )).being .equal (u ('1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg' ))
47
47
expect (session ).to .have .property (u ('media_mode' )).being .equal (MediaModes .routed )
@@ -87,5 +87,47 @@ def test_create_routed_session_with_location_hint(self):
87
87
expect (session ).to .have .property (u ('media_mode' )).being .equal (MediaModes .routed )
88
88
expect (session ).to .have .property (u ('location' )).being .equal (u ('12.34.56.78' ))
89
89
90
+ @httpretty .activate
91
+ def test_create_manual_archive_mode_session (self ):
92
+ httpretty .register_uri (httpretty .POST , u ('https://api.opentok.com/session/create' ),
93
+ 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>' ),
94
+ status = 200 ,
95
+ content_type = u ('text/xml' ))
96
+
97
+ session = self .opentok .create_session (media_mode = MediaModes .routed , archive_mode = ArchiveModes .manual )
98
+
99
+ expect (httpretty .last_request ().headers [u ('x-tb-partner-auth' )]).to .equal (self .api_key + u (':' )+ self .api_secret )
100
+ expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
101
+ expect (httpretty .last_request ().body ).to .equal (b ('archiveMode=manual&p2p.preference=disabled' ))
102
+ expect (session ).to .be .a (Session )
103
+ expect (session ).to .have .property (u ('session_id' )).being .equal (u ('1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg' ))
104
+ expect (session ).to .have .property (u ('media_mode' )).being .equal (MediaModes .routed )
105
+ expect (session ).to .have .property (u ('archive_mode' )).being .equal (ArchiveModes .manual )
106
+
107
+ @httpretty .activate
108
+ def test_create_always_archive_mode_session (self ):
109
+ httpretty .register_uri (httpretty .POST , u ('https://api.opentok.com/session/create' ),
110
+ 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>' ),
111
+ status = 200 ,
112
+ content_type = u ('text/xml' ))
113
+
114
+ session = self .opentok .create_session (media_mode = MediaModes .routed , archive_mode = ArchiveModes .always )
115
+
116
+ expect (httpretty .last_request ().headers [u ('x-tb-partner-auth' )]).to .equal (self .api_key + u (':' )+ self .api_secret )
117
+ expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
118
+ expect (httpretty .last_request ().body ).to .equal (b ('archiveMode=always&p2p.preference=disabled' ))
119
+ expect (session ).to .be .a (Session )
120
+ expect (session ).to .have .property (u ('session_id' )).being .equal (u ('1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg' ))
121
+ expect (session ).to .have .property (u ('media_mode' )).being .equal (MediaModes .routed )
122
+ expect (session ).to .have .property (u ('archive_mode' )).being .equal (ArchiveModes .always )
123
+
124
+ @httpretty .activate
125
+ def test_complains_about_always_archive_mode_and_relayed_session (self ):
126
+ httpretty .register_uri (httpretty .POST , u ('https://api.opentok.com/session/create' ),
127
+ 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>' ),
128
+ status = 200 ,
129
+ content_type = u ('text/xml' ))
130
+ self .assertRaises (OpenTokException , self .opentok .create_session , media_mode = MediaModes .relayed , archive_mode = ArchiveModes .always )
131
+
90
132
# TODO: all the cases that throw exceptions
91
133
# TODO: custom api_url requests
0 commit comments