feat: orchestrate governed tenant erasure
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib
|
||||
import tempfile
|
||||
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_tenancy.backend.manifest import get_manifest
|
||||
|
||||
|
||||
def test_tenant_erasure_migration_is_declared() -> None:
|
||||
migration = importlib.import_module(
|
||||
"govoplan_tenancy.backend.migrations.versions."
|
||||
"b3d8e1f4a6c2_v021_tenant_erasure_operations"
|
||||
)
|
||||
|
||||
assert migration.revision == "b3d8e1f4a6c2"
|
||||
assert migration.down_revision is None
|
||||
assert migration.branch_labels == ("module:tenancy",)
|
||||
|
||||
|
||||
def test_tenancy_migration_creates_erasure_operation_table_and_head() -> None:
|
||||
with tempfile.TemporaryDirectory(prefix="govoplan-tenancy-migration-") as directory:
|
||||
url = f"sqlite:///{Path(directory) / 'tenancy.db'}"
|
||||
migrate_database(
|
||||
database_url=url,
|
||||
enabled_modules=("tenancy",),
|
||||
manifest_factories=(get_manifest,),
|
||||
)
|
||||
engine = create_engine(url)
|
||||
try:
|
||||
with engine.connect() as connection:
|
||||
assert "b3d8e1f4a6c2" in set(
|
||||
MigrationContext.configure(connection).get_current_heads()
|
||||
)
|
||||
assert {
|
||||
name
|
||||
for name in inspect(connection).get_table_names()
|
||||
if name.startswith("tenancy_")
|
||||
} == {"tenancy_erasure_operations"}
|
||||
finally:
|
||||
engine.dispose()
|
||||
Reference in New Issue
Block a user