Fix tests

This commit is contained in:
Joseph Schorr 2015-01-09 17:11:51 -05:00
parent 6d604a656a
commit 0d2c42ad03
3 changed files with 53 additions and 41 deletions

View file

@ -195,5 +195,3 @@ class DefaultConfig(object):
# Services that should not be shown in the logs view.
SYSTEM_SERVICE_BLACKLIST = ['tutumdocker', 'dockerfilebuild']
DEBUGGING = True

View file

@ -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,6 +29,7 @@ class TestSuperUserRegistryStatus(ApiTestCase):
class TestSuperUserConfigFile(ApiTestCase):
def test_get_non_superuser(self):
with ConfigForTesting():
# No user.
self.getResponse(SuperUserConfigFile, params=dict(filename='ssl.cert'), expected_code=403)
@ -35,15 +38,18 @@ class TestSuperUserConfigFile(ApiTestCase):
self.getResponse(SuperUserConfigFile, params=dict(filename='ssl.cert'), expected_code=403)
def test_get_superuser_invalid_filename(self):
with ConfigForTesting():
self.login(ADMIN_ACCESS_USER)
self.getResponse(SuperUserConfigFile, params=dict(filename='somefile'), expected_code=404)
def test_get_superuser(self):
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):
with ConfigForTesting():
# No user.
self.postResponse(SuperUserConfigFile, params=dict(filename='ssl.cert'), expected_code=403)
@ -52,16 +58,19 @@ class TestSuperUserConfigFile(ApiTestCase):
self.postResponse(SuperUserConfigFile, params=dict(filename='ssl.cert'), expected_code=403)
def test_post_superuser_invalid_filename(self):
with ConfigForTesting():
self.login(ADMIN_ACCESS_USER)
self.postResponse(SuperUserConfigFile, params=dict(filename='somefile'), expected_code=404)
def test_post_superuser(self):
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):
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)
@ -100,6 +109,7 @@ class TestSuperUserCreateInitialSuperUser(ApiTestCase):
class TestSuperUserConfigValidate(ApiTestCase):
def test_nonsuperuser_noconfig(self):
with ConfigForTesting():
self.login(ADMIN_ACCESS_USER)
result = self.postJsonResponse(SuperUserConfigValidate, params=dict(service='someservice'),
data=dict(config={}))
@ -128,6 +138,7 @@ class TestSuperUserConfigValidate(ApiTestCase):
class TestSuperUserConfig(ApiTestCase):
def test_get_non_superuser(self):
with ConfigForTesting():
# No user.
self.getResponse(SuperUserConfig, expected_code=401)
@ -136,6 +147,7 @@ class TestSuperUserConfig(ApiTestCase):
self.getResponse(SuperUserConfig, expected_code=403)
def test_get_superuser(self):
with ConfigForTesting():
self.login(ADMIN_ACCESS_USER)
json = self.getJsonResponse(SuperUserConfig)

View file

@ -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 = {}