File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -279,18 +279,40 @@ def client_from_file(file_path='.ox3rc', env=None):
279279
280280 # Load required parameters.
281281 try :
282- for key in required_params :
283- client_params [key ] = cp .get (env , key )
282+ for param in required_params :
283+ client_params [param ] = cp .get (env , param )
284284 except ConfigParser .NoOptionError :
285- err_msg = "Missing required option: '%s'" % key
285+ err_msg = "Missing required option: '%s'" % param
286286 raise Exception (err_msg )
287287
288- # TODO: Add support for optional parameters.
289-
290288 client = Client (
291289 domain = client_params ['domain' ],
292290 realm = client_params ['realm' ],
293291 consumer_key = client_params ['consumer_key' ],
294292 consumer_secret = client_params ['consumer_secret' ])
295293
294+ # Load optional parameters.
295+ optional_params = [
296+ 'callback_url' ,
297+ 'scheme' ,
298+ 'request_token_url' ,
299+ 'access_token_url' ,
300+ 'authorization_url' ,
301+ 'api_path' ,
302+ 'email' ,
303+ 'password' ]
304+
305+ for param in optional_params :
306+ try :
307+ prop = param
308+
309+ # Prefix private properties with '_'.
310+ if prop in ['email' , 'password' ]:
311+ prop = '_%s' % prop
312+
313+ client .__dict__ [prop ] = cp .get (env , param )
314+
315+ except ConfigParser .NoOptionError :
316+ pass
317+
296318 return client
Original file line number Diff line number Diff line change @@ -59,3 +59,42 @@ def test_missing_required_option_raises_error(self):
5959 ox3apiclient .client_from_file ,
6060 file_path ,
6161 'missing-required-option' )
62+
63+ def test_loads_optional_options (self ):
64+ file_path = os .path .join (os .path .dirname (__file__ ), 'ox3rctest' )
65+ ox = ox3apiclient .client_from_file (
66+ file_path = file_path ,
67+ env = 'optional-options' )
68+
69+ test_values = [
70+ 'domain' ,
71+ 'realm' ,
72+ 'consumer_secret' ,
73+ 'consumer_key' ,
74+ 'callback_url' ,
75+ 'scheme' ,
76+ 'request_token_url' ,
77+ 'access_token_url' ,
78+ 'authorization_url' ,
79+ 'api_path' ,
80+ 'email' ,
81+ 'password' ]
82+
83+ loaded_values = [
84+ ox .domain ,
85+ ox .realm ,
86+ ox .consumer_key ,
87+ ox .consumer_secret ,
88+ ox .callback_url ,
89+ ox .scheme ,
90+ ox .request_token_url ,
91+ ox .access_token_url ,
92+ ox .authorization_url ,
93+ ox .api_path ,
94+ ox ._email ,
95+ ox ._password ]
96+
97+ test_values .sort ()
98+ loaded_values .sort ()
99+
100+ self .assertEqual (loaded_values , test_values )
Original file line number Diff line number Diff line change 33 prod
44 dev
55 missing-required-option
6+ optional-options
67
78[prod]
89email: email
@@ -26,3 +27,17 @@ password: password
2627domain: domain
2728realm: realm
2829consumer_key: consumer_key
30+
31+ [optional-options]
32+ email: email
33+ password: password
34+ domain: domain
35+ realm: realm
36+ consumer_key: consumer_key
37+ consumer_secret: consumer_secret
38+ scheme: scheme
39+ request_token_url: request_token_url
40+ access_token_url: access_token_url
41+ authorization_url: authorization_url
42+ api_path: api_path
43+ callback_url = callback_url
You can’t perform that action at this time.
0 commit comments