Use globals for the database connection

- remove the factory functions for creating engines and sessions
- define global engine, connection, and session objects to be used
  everywhere in the urban_meal_delivery package
This commit is contained in:
Alexander Hess 2021-01-04 18:50:26 +01:00
commit 2e3ccd14d5
Signed by: alexander
GPG key ID: 344EA5AB10D868E0
8 changed files with 74 additions and 24 deletions

View file

@ -36,11 +36,27 @@ def test_database_uri_set(env, monkeypatch):
@pytest.mark.parametrize('env', envs)
def test_no_database_uri_set(env, monkeypatch):
def test_no_database_uri_set_with_testing_env_var(env, monkeypatch):
"""Package does not work without DATABASE_URI set in the environment."""
monkeypatch.setattr(configuration.ProductionConfig, 'DATABASE_URI', None)
monkeypatch.setattr(configuration.TestingConfig, 'DATABASE_URI', None)
monkeypatch.setenv('TESTING', 'true')
with pytest.warns(None) as record:
configuration.make_config(env)
assert len(record) == 0 # noqa:WPS441,WPS507
@pytest.mark.parametrize('env', envs)
def test_no_database_uri_set_without_testing_env_var(env, monkeypatch):
"""Package does not work without DATABASE_URI set in the environment."""
monkeypatch.setattr(configuration.ProductionConfig, 'DATABASE_URI', None)
monkeypatch.setattr(configuration.TestingConfig, 'DATABASE_URI', None)
monkeypatch.delenv('TESTING', raising=False)
with pytest.warns(UserWarning, match='no DATABASE_URI'):
configuration.make_config(env)