47 lines
1.6 KiB
Python
47 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_identity_trust.backend.manifest import get_manifest
|
|
|
|
|
|
class IdentityTrustMigrationTests(unittest.TestCase):
|
|
def test_migration_creates_all_trust_tables(self) -> None:
|
|
with tempfile.TemporaryDirectory(
|
|
prefix="govoplan-identity-trust-"
|
|
) as directory:
|
|
url = f"sqlite:///{Path(directory) / 'trust.db'}"
|
|
migrate_database(
|
|
database_url=url,
|
|
enabled_modules=("identity_trust",),
|
|
manifest_factories=(get_manifest,),
|
|
)
|
|
engine = create_engine(url)
|
|
try:
|
|
tables = set(inspect(engine).get_table_names())
|
|
self.assertTrue(
|
|
{
|
|
"identity_trust_device_keys",
|
|
"identity_trust_key_epochs",
|
|
"identity_trust_assurance_evidence",
|
|
"identity_trust_key_access_decisions",
|
|
}.issubset(tables)
|
|
)
|
|
with engine.connect() as connection:
|
|
self.assertIn(
|
|
"c3f5a7b9d1e2",
|
|
set(MigrationContext.configure(connection).get_current_heads()),
|
|
)
|
|
finally:
|
|
engine.dispose()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|