|
1 | 1 | """Base class for Shotgun API tests.""" |
| 2 | +import os |
2 | 3 | import re |
3 | 4 | import unittest |
4 | 5 | from ConfigParser import ConfigParser |
@@ -285,29 +286,34 @@ def setUp(self): |
285 | 286 | class SgTestConfig(object): |
286 | 287 | '''Reads test config and holds values''' |
287 | 288 | def __init__(self): |
288 | | - self.mock = True |
289 | | - self.server_url = None |
290 | | - self.script_name = None |
291 | | - self.api_key = None |
292 | | - self.http_proxy = None |
293 | | - self.session_uuid = None |
294 | | - self.project_name = None |
295 | | - self.human_name = None |
296 | | - self.human_login = None |
297 | | - self.human_password = None |
298 | | - self.asset_code = None |
299 | | - self.version_code = None |
300 | | - self.shot_code = None |
301 | | - self.task_content = None |
302 | 289 |
|
| 290 | + for key in self.config_keys(): |
| 291 | + |
| 292 | + # Look for any environment variables that match our test |
| 293 | + # configuration naming of "SG_{KEY}". Default is None. |
| 294 | + value = os.environ.get('SG_%s' % (str(key).upper())) |
| 295 | + if key in ['mock']: |
| 296 | + value = (value == None) or (str(value).lower() in ['true','1']) |
| 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 | + ] |
303 | 306 |
|
304 | 307 | def read_config(self, config_path): |
305 | 308 | config_parser = ConfigParser() |
306 | 309 | config_parser.read(config_path) |
307 | 310 | for section in config_parser.sections(): |
308 | 311 | for option in config_parser.options(section): |
309 | | - value = config_parser.get(section, option) |
310 | | - 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) |
311 | 317 |
|
312 | 318 |
|
313 | 319 | def _find_or_create_entity(sg, entity_type, data, identifyiers=None): |
|
0 commit comments