- use SQLAlchemy (and PostgreSQL) to model the ORM layer
- add the following models:
+ Address => modelling all kinds of addresses
+ City => model the three target cities
+ Courier => model the UDP's couriers
+ Customer => model the UDP's customers
+ Order => model the orders received by the UDP
+ Restaurant => model the restaurants active on the UDP
- so far, the emphasis lies on expression the Foreign Key
and Check Constraints that are used to validate the assumptions
inherent to the cleanded data
- provide database-independent unit tests with 100% coverage
- provide additional integration tests ("e2e") that commit data to
a PostgreSQL instance to validate that the constraints work
- adapt linting rules a bit
53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
"""Test the package's configuration module."""
|
|
|
|
import pytest
|
|
|
|
from urban_meal_delivery import _config as config_mod # noqa:WPS450
|
|
|
|
|
|
envs = ['production', 'testing']
|
|
|
|
|
|
@pytest.mark.parametrize('env', envs)
|
|
def test_config_repr(env):
|
|
"""Config objects have the text representation '<configuration>'."""
|
|
config = config_mod.get_config(env)
|
|
|
|
assert str(config) == '<configuration>'
|
|
|
|
|
|
def test_invalid_config():
|
|
"""There are only 'production' and 'testing' configurations."""
|
|
with pytest.raises(ValueError, match="'production' or 'testing'"):
|
|
config_mod.get_config('invalid')
|
|
|
|
|
|
@pytest.mark.parametrize('env', envs)
|
|
def test_database_uri_set(env, monkeypatch):
|
|
"""Package does NOT emit warning if DATABASE_URI is set."""
|
|
uri = 'postgresql://user:password@localhost/db'
|
|
monkeypatch.setattr(config_mod.ProductionConfig, 'DATABASE_URI', uri)
|
|
monkeypatch.setattr(config_mod.TestingConfig, 'DATABASE_URI', uri)
|
|
|
|
with pytest.warns(None) as record:
|
|
config_mod.get_config(env)
|
|
|
|
assert len(record) == 0 # noqa:WPS441,WPS507
|
|
|
|
|
|
@pytest.mark.parametrize('env', envs)
|
|
def test_no_database_uri_set(env, monkeypatch):
|
|
"""Package does not work without DATABASE_URI set in the environment."""
|
|
monkeypatch.setattr(config_mod.ProductionConfig, 'DATABASE_URI', None)
|
|
monkeypatch.setattr(config_mod.TestingConfig, 'DATABASE_URI', None)
|
|
|
|
with pytest.warns(UserWarning, match='no DATABASE_URI'):
|
|
config_mod.get_config(env)
|
|
|
|
|
|
def test_random_testing_schema():
|
|
"""CLEAN_SCHEMA is randomized if not seti explicitly."""
|
|
result = config_mod.random_schema_name()
|
|
|
|
assert isinstance(result, str)
|
|
assert len(result) <= 10
|