50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
from __future__ import annotations
|
|
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from alembic.runtime.migration import MigrationContext
|
|
from sqlalchemy import create_engine, inspect
|
|
|
|
from govoplan_core.db.migrations import migrate_database
|
|
from govoplan_dashboard.backend.manifest import get_manifest
|
|
|
|
|
|
class DashboardMigrationTests(unittest.TestCase):
|
|
def test_migration_creates_dashboard_layouts_and_head(self) -> None:
|
|
with tempfile.TemporaryDirectory(
|
|
prefix="govoplan-dashboard-migration-"
|
|
) as directory:
|
|
url = f"sqlite:///{Path(directory) / 'dashboard.db'}"
|
|
migrate_database(
|
|
database_url=url,
|
|
enabled_modules=("dashboard",),
|
|
manifest_factories=(get_manifest,),
|
|
)
|
|
engine = create_engine(url)
|
|
try:
|
|
with engine.connect() as connection:
|
|
self.assertIn(
|
|
"7b9d2f4a6c8e",
|
|
set(
|
|
MigrationContext.configure(
|
|
connection
|
|
).get_current_heads()
|
|
),
|
|
)
|
|
self.assertEqual(
|
|
{"dashboard_layouts"},
|
|
{
|
|
name
|
|
for name in inspect(connection).get_table_names()
|
|
if name.startswith("dashboard_")
|
|
},
|
|
)
|
|
finally:
|
|
engine.dispose()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|