def test_no_use_key(): cfg = get_config() cfg.database = { 'database': conn['database_name'], 'server': conn['host'], 'username': conn['username'], 'password': conn['password'] } with pytest.raises(DatabaseConnectionError): api = PotionApplication(cfg)
def test_dummy_postgres_connection_fails(): cfg = get_config() cfg.database = { 'use':'postgres', 'database': conn['database_name'], 'server': conn['host'], 'username': conn['username'], 'password': conn['password'] } with pytest.raises(DatabaseConnectionError): api = PotionApplication(cfg)
def test_default_log(make_client): cfg = get_config() cfg.logging = {} logger = _get_logger(cfg) # start falcon API api = PotionApplication(cfg) assert api.logging_level == 'WARNING' # since level is 'warning', should NOT show startup INFO log assert logger.is_empty() _error_logged_to_db(make_client, api, logger) delete_all()
def test_log_level_info(make_client): cfg = get_config() cfg.logging = {'level': 'INFO'} logger = _get_logger(cfg) # start falcon API api = PotionApplication(cfg) assert api.logging_level == 'INFO' # since level is 'info', should show startup INFO log assert not logger.is_empty() all_logs = query_to_dict(logger.get_all()) assert type(all_logs) == dict assert all_logs['msg'] == 'STARTUP: Logging configured successfully' assert all_logs['level'] == 'INFO' _error_logged_to_db(make_client, api, logger) delete_all()
def create_custom_auth_setup_api(auth_value): cfg = get_config() cfg.authentication = auth_value return PotionApplication(cfg)
class CustomWorker(SyncWorker): def handle_quit(self, sig, frame): self.app.application.stop(sig) super().handle_quit(sig, frame) def run(self): self.app.application.start() super().run() class GunicornApplication(BaseApplication): def __init__(self, app, options=None): self.options = options or {} self.application = app super().__init__() def load_config(self): for key, value in self.options.items(): self.cfg.set(key.lower(), value) def load(self): return self.application cfg = aumbry.load(aumbry.FILE, PotionConfig, {'CONFIG_FILE_PATH': './config/config.yml'}) app = PotionApplication(cfg) guinicorn_app = GunicornApplication(app, cfg.gunicorn) guinicorn_app.run()
def test_no_db_in_config(): cfg = get_config() del cfg.database with pytest.raises(DatabaseConnectionError): api = PotionApplication(cfg)
def test_empty_db_in_config(): cfg = get_config() cfg.database = {} with pytest.raises(DatabaseConnectionError): api = PotionApplication(cfg)
def test_unsupported_db_type(): cfg = get_config() cfg.database = {'use':'sqlserver'} with pytest.raises(DatabaseConnectionError): api = PotionApplication(cfg)