42 lines
1.5 KiB
Python
42 lines
1.5 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_access.backend.manifest import get_manifest as get_access_manifest
|
|
from govoplan_core.db.migrations import migrate_database
|
|
from govoplan_tasks.backend.manifest import get_manifest as get_tasks_manifest
|
|
|
|
|
|
class TasksMigrationTests(unittest.TestCase):
|
|
def test_fresh_migration_creates_task_kernel_and_head(self) -> None:
|
|
with tempfile.TemporaryDirectory(prefix="govoplan-tasks-migration-") as directory:
|
|
url = f"sqlite:///{Path(directory) / 'tasks.db'}"
|
|
migrate_database(
|
|
database_url=url,
|
|
enabled_modules=("access", "tasks"),
|
|
manifest_factories=(get_access_manifest, get_tasks_manifest),
|
|
)
|
|
engine = create_engine(url)
|
|
try:
|
|
self.assertTrue(
|
|
{"task_items", "task_assignments"}.issubset(
|
|
inspect(engine).get_table_names()
|
|
)
|
|
)
|
|
with engine.connect() as connection:
|
|
self.assertIn(
|
|
"7c4d9a2e1f30",
|
|
set(MigrationContext.configure(connection).get_current_heads()),
|
|
)
|
|
finally:
|
|
engine.dispose()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|