Skip to content

Commit 01ae5ce

Browse files
author
Neil Grey
committed
For #34500 : Updating base to be clearer about env vars, changing nosetests call so config will be correctly picked up, applying manne's feedback
1 parent 399d602 commit 01ae5ce

4 files changed

Lines changed: 26 additions & 21 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ install:
88
before_script:
99
- cp ./tests/example_config ./tests/config
1010
# command to run tests
11-
script: nosetests -w tests/
11+
script: nosetests -v
1212
notifications:
1313
email:
1414
- api@shotgunsoftware.com

shotgun_api3/shotgun.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ def __init__(self,
409409
else:
410410
self.__ca_certs = os.environ.get('SHOTGUN_API_CACERTS')
411411

412-
self.base_url = (base_url or "")
412+
self.base_url = (base_url or "").lower()
413413
self.config.scheme, self.config.server, api_base, _, _ = \
414414
urlparse.urlsplit(self.base_url)
415415
if self.config.scheme not in ("http", "https"):
@@ -422,7 +422,7 @@ def __init__(self,
422422
# if the service contains user information strip it out
423423
# copied from the xmlrpclib which turned the user:password into
424424
# and auth header
425-
auth, self.config.server = urllib.splituser(self.config.server)
425+
auth, self.config.server = urllib.splituser(urlparse.urlsplit(base_url).netloc)
426426
if auth:
427427
auth = base64.encodestring(urllib.unquote(auth))
428428
self.config.authorization = "Basic " + auth.strip()

tests/base.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -286,29 +286,34 @@ def setUp(self):
286286
class SgTestConfig(object):
287287
'''Reads test config and holds values'''
288288
def __init__(self):
289-
self.mock = True
290-
self.server_url = None
291-
self.script_name = None
292-
self.api_key = None
293-
self.http_proxy = None
294-
self.session_uuid = None
295-
self.project_name = None
296-
self.human_name = None
297-
self.human_login = None
298-
self.human_password = None
299-
self.asset_code = None
300-
self.version_code = None
301-
self.shot_code = None
302-
self.task_content = None
289+
290+
for key in self.config_keys():
291+
value = None
292+
if key in ['mock']:
293+
value = True
294+
# Look for any environment variables that match our test
295+
# configuration naming of "SG_{KEY}". Default is None.
296+
value = os.environ.get('SG_{0}'.format(str(key).upper()))
297+
setattr(self, key, value)
298+
299+
def config_keys(self):
300+
return [
301+
'api_key', 'asset_code', 'http_proxy', 'human_login', 'human_name',
302+
'human_password', 'mock', 'project_name', 'script_name',
303+
'server_url', 'session_uuid', 'shot_code', 'task_content',
304+
'version_code'
305+
]
303306

304307
def read_config(self, config_path):
305308
config_parser = ConfigParser()
306309
config_parser.read(config_path)
307310
for section in config_parser.sections():
308311
for option in config_parser.options(section):
309-
value = (os.environ.get('SG_{0}'.format(str(option).upper())) or
310-
config_parser.get(section, option))
311-
setattr(self, option, value)
312+
# We only care about the configuration file if an environment
313+
# variable has not already been set
314+
if not getattr(self, option, None):
315+
value = config_parser.get(section, option)
316+
setattr(self, option, value)
312317

313318

314319
def _find_or_create_entity(sg, entity_type, data, identifyiers=None):

tests/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def test_rpc_error(self):
240240

241241
try:
242242
self.sg.info()
243-
except api.Fault as e:
243+
except api.Fault, e:
244244
self.assertEqual("Go BANG", str(e))
245245

246246
def test_call_rpc(self):

0 commit comments

Comments
 (0)