File tree 2 files changed +25
-5
lines changed
2 files changed +25
-5
lines changed Original file line number Diff line number Diff line change 1
1
import unittest
2
2
import os
3
3
from zencoder import Zencoder
4
+ import zencoder
4
5
5
6
class TestZencoder (unittest .TestCase ):
6
7
def setUp (self ):
@@ -34,6 +35,16 @@ def test_set_api_edge_version(self):
34
35
zc = Zencoder (api_version = 'edge' )
35
36
self .assertEquals (zc .base_url , 'https://app.zencoder.com/api/' )
36
37
38
+ def test_set_base_url (self ):
39
+ os .environ ['ZENCODER_API_KEY' ] = 'abcd123'
40
+ zc = Zencoder (base_url = 'https://localhost:800/foo/' )
41
+ self .assertEquals (zc .base_url , 'https://localhost:800/foo/' )
42
+
43
+ def test_set_base_url_and_version_fails (self ):
44
+ os .environ ['ZENCODER_API_KEY' ] = 'abcd123'
45
+ with self .assertRaises (zencoder .core .ZencoderError ):
46
+ zc = Zencoder (base_url = 'https://localhost:800/foo/' , api_version = 'v3' )
47
+
37
48
def test_set_timeout (self ):
38
49
api_key = 'testapikey'
39
50
zc = Zencoder (api_key = api_key , timeout = 999 )
Original file line number Diff line number Diff line change @@ -158,17 +158,26 @@ class Zencoder(object):
158
158
def __init__ (self ,
159
159
api_key = None ,
160
160
api_version = None ,
161
+ base_url = None ,
161
162
timeout = None ,
162
163
test = False ,
163
164
proxies = None ,
164
165
cert = None ,
165
166
verify = True ):
166
- if not api_version :
167
- api_version = 'v2'
168
167
169
- self .base_url = 'https://app.zencoder.com/api/'
170
- if not api_version == 'edge' :
171
- self .base_url = self .base_url + '%s/' % api_version
168
+ if base_url and api_version :
169
+ raise ZencoderError ('Cannot set both `base_url` and `api_version`.' )
170
+
171
+ if base_url :
172
+ self .base_url = base_url
173
+ else :
174
+ self .base_url = 'https://app.zencoder.com/api/'
175
+
176
+ if not api_version :
177
+ api_version = 'v2'
178
+
179
+ if api_version != 'edge' :
180
+ self .base_url = '{0}{1}/' .format (self .base_url , api_version )
172
181
173
182
if not api_key :
174
183
try :
You can’t perform that action at this time.
0 commit comments