Add an ORM layer
- 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
This commit is contained in:
parent
d219fa816d
commit
fdcc93a1ea
24 changed files with 2119 additions and 4 deletions
51
tests/db/test_customer.py
Normal file
51
tests/db/test_customer.py
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
"""Test the ORM's Customer model."""
|
||||
|
||||
import pytest
|
||||
from sqlalchemy.orm import exc as orm_exc
|
||||
|
||||
from urban_meal_delivery import db
|
||||
|
||||
|
||||
class TestSpecialMethods:
|
||||
"""Test special methods in Customer."""
|
||||
|
||||
# pylint:disable=no-self-use
|
||||
|
||||
def test_create_customer(self, customer_data):
|
||||
"""Test instantiation of a new Customer object."""
|
||||
result = db.Customer(**customer_data)
|
||||
|
||||
assert result is not None
|
||||
|
||||
def test_text_representation(self, customer_data):
|
||||
"""Customer has a non-literal text representation."""
|
||||
customer = db.Customer(**customer_data)
|
||||
id_ = customer_data['id']
|
||||
|
||||
result = repr(customer)
|
||||
|
||||
assert result == f'<Customer(#{id_})>'
|
||||
|
||||
|
||||
@pytest.mark.e2e
|
||||
@pytest.mark.no_cover
|
||||
class TestConstraints:
|
||||
"""Test the database constraints defined in Customer."""
|
||||
|
||||
# pylint:disable=no-self-use
|
||||
|
||||
def test_insert_into_database(self, customer, db_session):
|
||||
"""Insert an instance into the database."""
|
||||
db_session.add(customer)
|
||||
db_session.commit()
|
||||
|
||||
def test_dublicate_primary_key(self, customer, customer_data, db_session):
|
||||
"""Can only add a record once."""
|
||||
db_session.add(customer)
|
||||
db_session.commit()
|
||||
|
||||
another_customer = db.Customer(**customer_data)
|
||||
db_session.add(another_customer)
|
||||
|
||||
with pytest.raises(orm_exc.FlushError):
|
||||
db_session.commit()
|
||||
Loading…
Add table
Add a link
Reference in a new issue