46 lines
1.6 KiB
Python
46 lines
1.6 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
import tempfile
|
|
import unittest
|
|
|
|
from alembic.runtime.migration import MigrationContext
|
|
from sqlalchemy import create_engine, inspect
|
|
|
|
from govoplan_approvals.backend.manifest import get_manifest
|
|
from govoplan_core.db.migrations import migrate_database
|
|
|
|
|
|
class ApprovalsMigrationTests(unittest.TestCase):
|
|
def test_fresh_migration_creates_approval_runtime_tables(self) -> None:
|
|
with tempfile.TemporaryDirectory(prefix="govoplan-approvals-") as directory:
|
|
url = f"sqlite:///{Path(directory) / 'approvals.db'}"
|
|
migrate_database(
|
|
database_url=url,
|
|
enabled_modules=("approvals",),
|
|
manifest_factories=(get_manifest,),
|
|
)
|
|
engine = create_engine(url)
|
|
try:
|
|
tables = set(inspect(engine).get_table_names())
|
|
self.assertTrue(
|
|
{
|
|
"approval_template_revisions",
|
|
"approval_request_revisions",
|
|
"approval_decision_records",
|
|
"approval_lifecycle_events",
|
|
"approval_replays",
|
|
}.issubset(tables)
|
|
)
|
|
with engine.connect() as connection:
|
|
self.assertIn(
|
|
"8b9c0d1e2f3a",
|
|
set(MigrationContext.configure(connection).get_current_heads()),
|
|
)
|
|
finally:
|
|
engine.dispose()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|