34 lines
1.0 KiB
Python
34 lines
1.0 KiB
Python
import pytest
|
|
from sqlalchemy import text
|
|
from sqlalchemy.exc import IntegrityError
|
|
|
|
from app.core.db import SessionLocal
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("statement", "constraint_name"),
|
|
(
|
|
(
|
|
"UPDATE vehicles SET odometer_km = -1 WHERE public_ref = 'MO-001'",
|
|
"ck_vehicles_odometer",
|
|
),
|
|
(
|
|
"UPDATE bookings SET ends_at = starts_at WHERE public_ref = 'BK-DEMO-RETURN'",
|
|
"ck_bookings_time_window",
|
|
),
|
|
(
|
|
"UPDATE data_quality_issues SET status = 'invented' "
|
|
"WHERE public_ref = 'DQ-DEMO-DUPLICATE'",
|
|
"ck_data_quality_status",
|
|
),
|
|
("UPDATE outbox_events SET attempts = -1", "ck_outbox_attempts"),
|
|
),
|
|
)
|
|
def test_database_rejects_invalid_domain_state(statement: str, constraint_name: str) -> None:
|
|
with SessionLocal() as db:
|
|
with pytest.raises(IntegrityError) as caught:
|
|
db.execute(text(statement))
|
|
db.commit()
|
|
db.rollback()
|
|
assert constraint_name in str(caught.value)
|