51 lines
1.7 KiB
Python
51 lines
1.7 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_views.backend.manifest import get_manifest
|
|
|
|
|
|
class ViewsMigrationTests(unittest.TestCase):
|
|
def test_migration_creates_views_tables_and_head(self) -> None:
|
|
with tempfile.TemporaryDirectory(
|
|
prefix="govoplan-views-migration-"
|
|
) as directory:
|
|
url = f"sqlite:///{Path(directory) / 'views.db'}"
|
|
migrate_database(
|
|
database_url=url,
|
|
enabled_modules=("views",),
|
|
manifest_factories=(get_manifest,),
|
|
)
|
|
engine = create_engine(url)
|
|
try:
|
|
with engine.connect() as connection:
|
|
self.assertIn(
|
|
"b8e4c1f7a2d9",
|
|
set(MigrationContext.configure(connection).get_current_heads()),
|
|
)
|
|
self.assertEqual(
|
|
{
|
|
"view_assignments",
|
|
"view_definitions",
|
|
"view_preferences",
|
|
"view_revisions",
|
|
},
|
|
{
|
|
name
|
|
for name in inspect(connection).get_table_names()
|
|
if name.startswith("view_")
|
|
},
|
|
)
|
|
finally:
|
|
engine.dispose()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|