diff --git a/config_app/config_test/test_suconfig_api.py b/config_app/config_test/test_suconfig_api.py index af85fb4d8..408b96a8b 100644 --- a/config_app/config_test/test_suconfig_api.py +++ b/config_app/config_test/test_suconfig_api.py @@ -1,4 +1,5 @@ import unittest +import mock from data.database import User from data import model @@ -28,11 +29,40 @@ class FreshConfigProvider(object): class TestSuperUserRegistryStatus(ApiTestCase): - def test_registry_status(self): + def test_registry_status_no_config(self): with FreshConfigProvider(): json = self.getJsonResponse(SuperUserRegistryStatus) self.assertEquals('config-db', json['status']) + @mock.patch("config_app.config_endpoints.api.suconfig.database_is_valid", mock.Mock(return_value=False)) + def test_registry_status_no_database(self): + with FreshConfigProvider(): + config_provider.save_config({'key': 'value'}) + json = self.getJsonResponse(SuperUserRegistryStatus) + self.assertEquals('setup-db', json['status']) + + @mock.patch("config_app.config_endpoints.api.suconfig.database_is_valid", mock.Mock(return_value=True)) + def test_registry_status_db_has_superuser(self): + with FreshConfigProvider(): + config_provider.save_config({'key': 'value'}) + json = self.getJsonResponse(SuperUserRegistryStatus) + self.assertEquals('config', json['status']) + + @mock.patch("config_app.config_endpoints.api.suconfig.database_is_valid", mock.Mock(return_value=True)) + @mock.patch("config_app.config_endpoints.api.suconfig.database_has_users", mock.Mock(return_value=False)) + def test_registry_status_db_no_superuser(self): + with FreshConfigProvider(): + config_provider.save_config({'key': 'value'}) + json = self.getJsonResponse(SuperUserRegistryStatus) + self.assertEquals('create-superuser', json['status']) + + @mock.patch("config_app.config_endpoints.api.suconfig.database_is_valid", mock.Mock(return_value=True)) + @mock.patch("config_app.config_endpoints.api.suconfig.database_has_users", mock.Mock(return_value=True)) + def test_registry_status_setup_complete(self): + with FreshConfigProvider(): + config_provider.save_config({'key': 'value', 'SETUP_COMPLETE': True}) + json = self.getJsonResponse(SuperUserRegistryStatus) + self.assertEquals('config', json['status']) class TestSuperUserConfigFile(ApiTestCase): def test_get_superuser_invalid_filename(self):