Files
govoplan-encryption/tests/test_migrations.py
T

51 lines
1.9 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_encryption.backend.manifest import get_manifest
class EncryptionMigrationTests(unittest.TestCase):
def test_migration_creates_lifecycle_tables(self) -> None:
with tempfile.TemporaryDirectory(prefix="govoplan-encryption-") as directory:
url = f"sqlite:///{Path(directory) / 'encryption.db'}"
migrate_database(
database_url=url,
enabled_modules=("encryption",),
manifest_factories=(get_manifest,),
)
engine = create_engine(url)
try:
tables = set(inspect(engine).get_table_names())
self.assertTrue(
{
"encryption_vaults",
"encryption_key_versions",
"encryption_key_operations",
"encryption_content_protections",
"encryption_protection_migrations",
"encryption_recovery_ceremonies",
"encryption_recovery_approvals",
"encryption_local_key_material",
"encryption_local_wrapped_content_keys",
"encryption_local_provider_operations",
}.issubset(tables)
)
with engine.connect() as connection:
self.assertIn(
"e5b7c9d1f3a4",
set(MigrationContext.configure(connection).get_current_heads()),
)
finally:
engine.dispose()
if __name__ == "__main__":
unittest.main()