from importlib.util import module_from_spec, spec_from_file_location from pathlib import Path MIGRATION_PATH = Path(__file__).parents[1] / "alembic" / "versions" / "0024_vehicle_demand.py" SPEC = spec_from_file_location("vehicle_demand_migration", MIGRATION_PATH) assert SPEC and SPEC.loader MIGRATION = module_from_spec(SPEC) SPEC.loader.exec_module(MIGRATION) def test_vehicle_demand_columns_are_added_only_when_missing(): assert MIGRATION.missing_lead_columns(set()) == { "leadType", "contactName", "customerId", "vehicleDemand", } assert MIGRATION.missing_lead_columns({"leadType", "contactName"}) == { "customerId", "vehicleDemand", } def test_vehicle_demand_indexes_and_foreign_key_are_only_added_when_missing(): assert MIGRATION.missing_named_indexes(set(), MIGRATION.LEAD_INDEXES) == { "ix_Lead_leadType", "ix_Lead_customerId", } assert not MIGRATION.should_create_customer_fk( [ { "referred_table": "Customer", "referred_columns": ["id"], "constrained_columns": ["customerId"], } ] )