43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
import tempfile
|
|
|
|
from alembic.runtime.migration import MigrationContext
|
|
from sqlalchemy import create_engine, inspect
|
|
|
|
from govoplan_core.db.migrations import migrate_database
|
|
from govoplan_reporting.backend.manifest import get_manifest
|
|
|
|
|
|
def test_fresh_migration_creates_provider_evidence_tables_and_current_head() -> None:
|
|
with tempfile.TemporaryDirectory(
|
|
prefix="govoplan-reporting-migration-"
|
|
) as directory:
|
|
url = f"sqlite:///{Path(directory) / 'reporting.db'}"
|
|
migrate_database(
|
|
database_url=url,
|
|
enabled_modules=("reporting",),
|
|
manifest_factories=(get_manifest,),
|
|
)
|
|
engine = create_engine(url)
|
|
try:
|
|
with engine.connect() as connection:
|
|
tables = set(inspect(connection).get_table_names())
|
|
assert {
|
|
"reporting_provider_executions",
|
|
"reporting_provider_exports",
|
|
}.issubset(tables)
|
|
assert "b7c4e1a9d2f6" in set(
|
|
MigrationContext.configure(connection).get_current_heads()
|
|
)
|
|
columns = {
|
|
item["name"]
|
|
for item in inspect(connection).get_columns(
|
|
"reporting_provider_executions"
|
|
)
|
|
}
|
|
assert "retention_redacted_at" in columns
|
|
finally:
|
|
engine.dispose()
|