from importlib.util import module_from_spec, spec_from_file_location from datetime import datetime from pathlib import Path MIGRATION_PATH = Path(__file__).parents[1] / "alembic" / "versions" / "0017_home_content.py" SPEC = spec_from_file_location("home_content_migration", MIGRATION_PATH) assert SPEC and SPEC.loader MIGRATION = module_from_spec(SPEC) SPEC.loader.exec_module(MIGRATION) def test_team_building_seed_contains_detail_fallback_fields(): for row in MIGRATION.SEED_TEAM_BUILDINGS: assert row["detailSubtitle"] == row["description"] assert row["detailParagraphs"] == [row["description"]] def test_wild_archive_seed_contains_detail_images_fallback(): for row in MIGRATION.SEED_WILD_ARCHIVES: assert row["images"] == [row["image"]] def test_seed_rows_only_include_columns_available_in_existing_table(): timestamp = datetime(2026, 1, 1) rows_without_detail_columns = MIGRATION.prepare_seed_rows( MIGRATION.SEED_TEAM_BUILDINGS[:1], {"id", "description", "createdAt", "updatedAt"}, timestamp, ) assert "detailSubtitle" not in rows_without_detail_columns[0] assert "detailParagraphs" not in rows_without_detail_columns[0] rows_with_detail_columns = MIGRATION.prepare_seed_rows( MIGRATION.SEED_TEAM_BUILDINGS[:1], {"id", "description", "detailSubtitle", "detailParagraphs", "createdAt", "updatedAt"}, timestamp, ) assert rows_with_detail_columns[0]["detailSubtitle"] == rows_with_detail_columns[0]["description"] assert rows_with_detail_columns[0]["detailParagraphs"] == [rows_with_detail_columns[0]["description"]]