Fix tests
This commit is contained in:
parent
6d604a656a
commit
0d2c42ad03
3 changed files with 53 additions and 41 deletions
|
@ -194,6 +194,4 @@ class DefaultConfig(object):
|
||||||
SYSTEM_SERVICES_PATH = "conf/init/"
|
SYSTEM_SERVICES_PATH = "conf/init/"
|
||||||
|
|
||||||
# Services that should not be shown in the logs view.
|
# Services that should not be shown in the logs view.
|
||||||
SYSTEM_SERVICE_BLACKLIST = ['tutumdocker', 'dockerfilebuild']
|
SYSTEM_SERVICE_BLACKLIST = ['tutumdocker', 'dockerfilebuild']
|
||||||
|
|
||||||
DEBUGGING = True
|
|
|
@ -8,12 +8,14 @@ import unittest
|
||||||
|
|
||||||
|
|
||||||
class ConfigForTesting(object):
|
class ConfigForTesting(object):
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
CONFIG_PROVIDER.reset_for_test()
|
CONFIG_PROVIDER.reset_for_test()
|
||||||
return CONFIG_PROVIDER
|
return CONFIG_PROVIDER
|
||||||
|
|
||||||
def __exit__(self, type, value, traceback):
|
def __exit__(self, type, value, traceback):
|
||||||
pass
|
CONFIG_PROVIDER.reset_for_test()
|
||||||
|
|
||||||
|
|
||||||
class TestSuperUserRegistryStatus(ApiTestCase):
|
class TestSuperUserRegistryStatus(ApiTestCase):
|
||||||
def test_registry_status(self):
|
def test_registry_status(self):
|
||||||
|
@ -27,44 +29,51 @@ class TestSuperUserRegistryStatus(ApiTestCase):
|
||||||
|
|
||||||
class TestSuperUserConfigFile(ApiTestCase):
|
class TestSuperUserConfigFile(ApiTestCase):
|
||||||
def test_get_non_superuser(self):
|
def test_get_non_superuser(self):
|
||||||
# No user.
|
with ConfigForTesting():
|
||||||
self.getResponse(SuperUserConfigFile, params=dict(filename='ssl.cert'), expected_code=403)
|
# No user.
|
||||||
|
self.getResponse(SuperUserConfigFile, params=dict(filename='ssl.cert'), expected_code=403)
|
||||||
|
|
||||||
# Non-superuser.
|
# Non-superuser.
|
||||||
self.login(READ_ACCESS_USER)
|
self.login(READ_ACCESS_USER)
|
||||||
self.getResponse(SuperUserConfigFile, params=dict(filename='ssl.cert'), expected_code=403)
|
self.getResponse(SuperUserConfigFile, params=dict(filename='ssl.cert'), expected_code=403)
|
||||||
|
|
||||||
def test_get_superuser_invalid_filename(self):
|
def test_get_superuser_invalid_filename(self):
|
||||||
self.login(ADMIN_ACCESS_USER)
|
with ConfigForTesting():
|
||||||
self.getResponse(SuperUserConfigFile, params=dict(filename='somefile'), expected_code=404)
|
self.login(ADMIN_ACCESS_USER)
|
||||||
|
self.getResponse(SuperUserConfigFile, params=dict(filename='somefile'), expected_code=404)
|
||||||
|
|
||||||
def test_get_superuser(self):
|
def test_get_superuser(self):
|
||||||
self.login(ADMIN_ACCESS_USER)
|
with ConfigForTesting():
|
||||||
result = self.getJsonResponse(SuperUserConfigFile, params=dict(filename='ssl.cert'))
|
self.login(ADMIN_ACCESS_USER)
|
||||||
self.assertFalse(result['exists'])
|
result = self.getJsonResponse(SuperUserConfigFile, params=dict(filename='ssl.cert'))
|
||||||
|
self.assertFalse(result['exists'])
|
||||||
|
|
||||||
def test_post_non_superuser(self):
|
def test_post_non_superuser(self):
|
||||||
# No user.
|
with ConfigForTesting():
|
||||||
self.postResponse(SuperUserConfigFile, params=dict(filename='ssl.cert'), expected_code=403)
|
# No user.
|
||||||
|
self.postResponse(SuperUserConfigFile, params=dict(filename='ssl.cert'), expected_code=403)
|
||||||
|
|
||||||
# Non-superuser.
|
# Non-superuser.
|
||||||
self.login(READ_ACCESS_USER)
|
self.login(READ_ACCESS_USER)
|
||||||
self.postResponse(SuperUserConfigFile, params=dict(filename='ssl.cert'), expected_code=403)
|
self.postResponse(SuperUserConfigFile, params=dict(filename='ssl.cert'), expected_code=403)
|
||||||
|
|
||||||
def test_post_superuser_invalid_filename(self):
|
def test_post_superuser_invalid_filename(self):
|
||||||
self.login(ADMIN_ACCESS_USER)
|
with ConfigForTesting():
|
||||||
self.postResponse(SuperUserConfigFile, params=dict(filename='somefile'), expected_code=404)
|
self.login(ADMIN_ACCESS_USER)
|
||||||
|
self.postResponse(SuperUserConfigFile, params=dict(filename='somefile'), expected_code=404)
|
||||||
|
|
||||||
def test_post_superuser(self):
|
def test_post_superuser(self):
|
||||||
self.login(ADMIN_ACCESS_USER)
|
with ConfigForTesting():
|
||||||
self.postResponse(SuperUserConfigFile, params=dict(filename='ssl.cert'), expected_code=400)
|
self.login(ADMIN_ACCESS_USER)
|
||||||
|
self.postResponse(SuperUserConfigFile, params=dict(filename='ssl.cert'), expected_code=400)
|
||||||
|
|
||||||
|
|
||||||
class TestSuperUserCreateInitialSuperUser(ApiTestCase):
|
class TestSuperUserCreateInitialSuperUser(ApiTestCase):
|
||||||
def test_no_config_file(self):
|
def test_no_config_file(self):
|
||||||
# If there is no config.yaml, then this method should security fail.
|
with ConfigForTesting():
|
||||||
data = dict(username='cooluser', password='password', email='fake@example.com')
|
# If there is no config.yaml, then this method should security fail.
|
||||||
self.postResponse(SuperUserCreateInitialSuperUser, data=data, expected_code=403)
|
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):
|
def test_config_file_with_db_users(self):
|
||||||
with ConfigForTesting():
|
with ConfigForTesting():
|
||||||
|
@ -100,11 +109,12 @@ class TestSuperUserCreateInitialSuperUser(ApiTestCase):
|
||||||
|
|
||||||
class TestSuperUserConfigValidate(ApiTestCase):
|
class TestSuperUserConfigValidate(ApiTestCase):
|
||||||
def test_nonsuperuser_noconfig(self):
|
def test_nonsuperuser_noconfig(self):
|
||||||
self.login(ADMIN_ACCESS_USER)
|
with ConfigForTesting():
|
||||||
result = self.postJsonResponse(SuperUserConfigValidate, params=dict(service='someservice'),
|
self.login(ADMIN_ACCESS_USER)
|
||||||
data=dict(config={}))
|
result = self.postJsonResponse(SuperUserConfigValidate, params=dict(service='someservice'),
|
||||||
|
data=dict(config={}))
|
||||||
|
|
||||||
self.assertFalse(result['status'])
|
self.assertFalse(result['status'])
|
||||||
|
|
||||||
|
|
||||||
def test_nonsuperuser_config(self):
|
def test_nonsuperuser_config(self):
|
||||||
|
@ -128,20 +138,22 @@ class TestSuperUserConfigValidate(ApiTestCase):
|
||||||
|
|
||||||
class TestSuperUserConfig(ApiTestCase):
|
class TestSuperUserConfig(ApiTestCase):
|
||||||
def test_get_non_superuser(self):
|
def test_get_non_superuser(self):
|
||||||
# No user.
|
with ConfigForTesting():
|
||||||
self.getResponse(SuperUserConfig, expected_code=401)
|
# No user.
|
||||||
|
self.getResponse(SuperUserConfig, expected_code=401)
|
||||||
|
|
||||||
# Non-superuser.
|
# Non-superuser.
|
||||||
self.login(READ_ACCESS_USER)
|
self.login(READ_ACCESS_USER)
|
||||||
self.getResponse(SuperUserConfig, expected_code=403)
|
self.getResponse(SuperUserConfig, expected_code=403)
|
||||||
|
|
||||||
def test_get_superuser(self):
|
def test_get_superuser(self):
|
||||||
self.login(ADMIN_ACCESS_USER)
|
with ConfigForTesting():
|
||||||
json = self.getJsonResponse(SuperUserConfig)
|
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
|
# Note: We expect the config to be none because a config.yaml should never be checked into
|
||||||
# the directory.
|
# the directory.
|
||||||
self.assertIsNone(json['config'])
|
self.assertIsNone(json['config'])
|
||||||
|
|
||||||
def test_put(self):
|
def test_put(self):
|
||||||
with ConfigForTesting() as config:
|
with ConfigForTesting() as config:
|
||||||
|
|
|
@ -110,9 +110,10 @@ class TestConfigProvider(BaseProvider):
|
||||||
the real file system. """
|
the real file system. """
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.files = {}
|
self.files = {}
|
||||||
|
self._config = None
|
||||||
|
|
||||||
def update_app_config(self, app_config):
|
def update_app_config(self, app_config):
|
||||||
pass
|
self._config = app_config
|
||||||
|
|
||||||
def get_yaml(self):
|
def get_yaml(self):
|
||||||
if not 'config.yaml' in self.files:
|
if not 'config.yaml' in self.files:
|
||||||
|
@ -136,4 +137,5 @@ class TestConfigProvider(BaseProvider):
|
||||||
self.files[filename] = ''
|
self.files[filename] = ''
|
||||||
|
|
||||||
def reset_for_test(self):
|
def reset_for_test(self):
|
||||||
|
self._config['SUPER_USERS'] = ['devtable']
|
||||||
self.files = {}
|
self.files = {}
|
||||||
|
|
Reference in a new issue