66 lines
2.3 KiB
Python
66 lines
2.3 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_quick_access.backend.manifest import get_manifest
|
|
|
|
|
|
class QuickAccessMigrationTests(unittest.TestCase):
|
|
def test_migration_creates_profile_table_and_head(self) -> None:
|
|
with tempfile.TemporaryDirectory(
|
|
prefix="govoplan-quick-access-migration-"
|
|
) as directory:
|
|
url = f"sqlite:///{Path(directory) / 'quick-access.db'}"
|
|
migrate_database(
|
|
database_url=url,
|
|
enabled_modules=("quick_access",),
|
|
manifest_factories=(get_manifest,),
|
|
)
|
|
engine = create_engine(url)
|
|
try:
|
|
with engine.connect() as connection:
|
|
self.assertIn(
|
|
"9a4e6c2d8f10",
|
|
set(MigrationContext.configure(connection).get_current_heads()),
|
|
)
|
|
self.assertIn(
|
|
"quick_access_profiles",
|
|
inspect(connection).get_table_names(),
|
|
)
|
|
self.assertEqual(
|
|
{
|
|
"category_preferences",
|
|
"revision",
|
|
"scope_id",
|
|
"scope_key",
|
|
"scope_type",
|
|
"tenant_id",
|
|
"tool_preferences",
|
|
},
|
|
{
|
|
column["name"]
|
|
for column in inspect(connection).get_columns(
|
|
"quick_access_profiles"
|
|
)
|
|
if column["name"] not in {
|
|
"created_at",
|
|
"created_by",
|
|
"id",
|
|
"updated_at",
|
|
"updated_by",
|
|
}
|
|
},
|
|
)
|
|
finally:
|
|
engine.dispose()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|