diff --git a/config.py b/config.py index 2748b77ad..e6f06a60e 100644 --- a/config.py +++ b/config.py @@ -194,6 +194,4 @@ class DefaultConfig(object): SYSTEM_SERVICES_PATH = "conf/init/" # Services that should not be shown in the logs view. - SYSTEM_SERVICE_BLACKLIST = ['tutumdocker', 'dockerfilebuild'] - - DEBUGGING = True \ No newline at end of file + SYSTEM_SERVICE_BLACKLIST = ['tutumdocker', 'dockerfilebuild'] \ No newline at end of file diff --git a/test/test_suconfig_api.py b/test/test_suconfig_api.py index 9cf72f573..a8f74483b 100644 --- a/test/test_suconfig_api.py +++ b/test/test_suconfig_api.py @@ -8,12 +8,14 @@ import unittest class ConfigForTesting(object): + def __enter__(self): CONFIG_PROVIDER.reset_for_test() return CONFIG_PROVIDER def __exit__(self, type, value, traceback): - pass + CONFIG_PROVIDER.reset_for_test() + class TestSuperUserRegistryStatus(ApiTestCase): def test_registry_status(self): @@ -27,44 +29,51 @@ class TestSuperUserRegistryStatus(ApiTestCase): class TestSuperUserConfigFile(ApiTestCase): def test_get_non_superuser(self): - # No user. - self.getResponse(SuperUserConfigFile, params=dict(filename='ssl.cert'), expected_code=403) + with ConfigForTesting(): + # No user. + self.getResponse(SuperUserConfigFile, params=dict(filename='ssl.cert'), expected_code=403) - # Non-superuser. - self.login(READ_ACCESS_USER) - self.getResponse(SuperUserConfigFile, params=dict(filename='ssl.cert'), expected_code=403) + # Non-superuser. + self.login(READ_ACCESS_USER) + self.getResponse(SuperUserConfigFile, params=dict(filename='ssl.cert'), expected_code=403) def test_get_superuser_invalid_filename(self): - self.login(ADMIN_ACCESS_USER) - self.getResponse(SuperUserConfigFile, params=dict(filename='somefile'), expected_code=404) + with ConfigForTesting(): + self.login(ADMIN_ACCESS_USER) + self.getResponse(SuperUserConfigFile, params=dict(filename='somefile'), expected_code=404) def test_get_superuser(self): - self.login(ADMIN_ACCESS_USER) - result = self.getJsonResponse(SuperUserConfigFile, params=dict(filename='ssl.cert')) - self.assertFalse(result['exists']) + with ConfigForTesting(): + self.login(ADMIN_ACCESS_USER) + result = self.getJsonResponse(SuperUserConfigFile, params=dict(filename='ssl.cert')) + self.assertFalse(result['exists']) def test_post_non_superuser(self): - # No user. - self.postResponse(SuperUserConfigFile, params=dict(filename='ssl.cert'), expected_code=403) + with ConfigForTesting(): + # No user. + self.postResponse(SuperUserConfigFile, params=dict(filename='ssl.cert'), expected_code=403) - # Non-superuser. - self.login(READ_ACCESS_USER) - self.postResponse(SuperUserConfigFile, params=dict(filename='ssl.cert'), expected_code=403) + # Non-superuser. + self.login(READ_ACCESS_USER) + self.postResponse(SuperUserConfigFile, params=dict(filename='ssl.cert'), expected_code=403) def test_post_superuser_invalid_filename(self): - self.login(ADMIN_ACCESS_USER) - self.postResponse(SuperUserConfigFile, params=dict(filename='somefile'), expected_code=404) + with ConfigForTesting(): + self.login(ADMIN_ACCESS_USER) + self.postResponse(SuperUserConfigFile, params=dict(filename='somefile'), expected_code=404) def test_post_superuser(self): - self.login(ADMIN_ACCESS_USER) - self.postResponse(SuperUserConfigFile, params=dict(filename='ssl.cert'), expected_code=400) + with ConfigForTesting(): + self.login(ADMIN_ACCESS_USER) + self.postResponse(SuperUserConfigFile, params=dict(filename='ssl.cert'), expected_code=400) class TestSuperUserCreateInitialSuperUser(ApiTestCase): def test_no_config_file(self): - # If there is no config.yaml, then this method should security fail. - data = dict(username='cooluser', password='password', email='fake@example.com') - self.postResponse(SuperUserCreateInitialSuperUser, data=data, expected_code=403) + with ConfigForTesting(): + # If there is no config.yaml, then this method should security fail. + data = dict(username='cooluser', password='password', email='fake@example.com') + self.postResponse(SuperUserCreateInitialSuperUser, data=data, expected_code=403) def test_config_file_with_db_users(self): with ConfigForTesting(): @@ -100,11 +109,12 @@ class TestSuperUserCreateInitialSuperUser(ApiTestCase): class TestSuperUserConfigValidate(ApiTestCase): def test_nonsuperuser_noconfig(self): - self.login(ADMIN_ACCESS_USER) - result = self.postJsonResponse(SuperUserConfigValidate, params=dict(service='someservice'), - data=dict(config={})) + with ConfigForTesting(): + self.login(ADMIN_ACCESS_USER) + result = self.postJsonResponse(SuperUserConfigValidate, params=dict(service='someservice'), + data=dict(config={})) - self.assertFalse(result['status']) + self.assertFalse(result['status']) def test_nonsuperuser_config(self): @@ -128,20 +138,22 @@ class TestSuperUserConfigValidate(ApiTestCase): class TestSuperUserConfig(ApiTestCase): def test_get_non_superuser(self): - # No user. - self.getResponse(SuperUserConfig, expected_code=401) + with ConfigForTesting(): + # No user. + self.getResponse(SuperUserConfig, expected_code=401) - # Non-superuser. - self.login(READ_ACCESS_USER) - self.getResponse(SuperUserConfig, expected_code=403) + # Non-superuser. + self.login(READ_ACCESS_USER) + self.getResponse(SuperUserConfig, expected_code=403) def test_get_superuser(self): - self.login(ADMIN_ACCESS_USER) - json = self.getJsonResponse(SuperUserConfig) + with ConfigForTesting(): + self.login(ADMIN_ACCESS_USER) + json = self.getJsonResponse(SuperUserConfig) - # Note: We expect the config to be none because a config.yaml should never be checked into - # the directory. - self.assertIsNone(json['config']) + # Note: We expect the config to be none because a config.yaml should never be checked into + # the directory. + self.assertIsNone(json['config']) def test_put(self): with ConfigForTesting() as config: diff --git a/util/config/provider.py b/util/config/provider.py index c4ddbc97c..7d135d40f 100644 --- a/util/config/provider.py +++ b/util/config/provider.py @@ -110,9 +110,10 @@ class TestConfigProvider(BaseProvider): the real file system. """ def __init__(self): self.files = {} + self._config = None def update_app_config(self, app_config): - pass + self._config = app_config def get_yaml(self): if not 'config.yaml' in self.files: @@ -136,4 +137,5 @@ class TestConfigProvider(BaseProvider): self.files[filename] = '' def reset_for_test(self): + self._config['SUPER_USERS'] = ['devtable'] self.files = {}