Define tenant lifecycle event contract
This commit is contained in:
70
tests/test_tenant_lifecycle.py
Normal file
70
tests/test_tenant_lifecycle.py
Normal file
@@ -0,0 +1,70 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from govoplan_tenancy.backend.lifecycle import (
|
||||
TENANT_EVENT_CREATED,
|
||||
TENANT_EVENT_DELETION_REQUESTED,
|
||||
TENANT_EVENT_ERASURE_COMPLETED,
|
||||
TENANT_EVENT_RESUMED,
|
||||
TENANT_EVENT_SUSPENDED,
|
||||
TENANT_LIFECYCLE_EVENTS,
|
||||
tenant_lifecycle_event,
|
||||
tenant_lifecycle_event_type,
|
||||
)
|
||||
|
||||
|
||||
class TenantLifecycleContractTests(unittest.TestCase):
|
||||
def test_lifecycle_event_names_are_stable(self) -> None:
|
||||
self.assertEqual("tenant.created", tenant_lifecycle_event_type("created"))
|
||||
self.assertEqual("tenant.suspended", tenant_lifecycle_event_type("suspended"))
|
||||
self.assertEqual("tenant.resumed", tenant_lifecycle_event_type("resumed"))
|
||||
self.assertEqual("tenant.deletion_requested", tenant_lifecycle_event_type("deletion_requested"))
|
||||
self.assertEqual("tenant.erasure_completed", tenant_lifecycle_event_type("erasure_completed"))
|
||||
self.assertEqual(
|
||||
(
|
||||
TENANT_EVENT_CREATED,
|
||||
TENANT_EVENT_SUSPENDED,
|
||||
TENANT_EVENT_RESUMED,
|
||||
TENANT_EVENT_DELETION_REQUESTED,
|
||||
TENANT_EVENT_ERASURE_COMPLETED,
|
||||
),
|
||||
TENANT_LIFECYCLE_EVENTS,
|
||||
)
|
||||
|
||||
def test_lifecycle_event_builds_audit_details_without_losing_extra_fields(self) -> None:
|
||||
occurred_at = datetime(2026, 7, 11, 12, 30, tzinfo=UTC)
|
||||
|
||||
event = tenant_lifecycle_event(
|
||||
"deletion_requested",
|
||||
tenant_id="tenant-1",
|
||||
tenant_slug="city",
|
||||
tenant_name="City Office",
|
||||
actor_account_id="account-1",
|
||||
requested_by_account_id="account-2",
|
||||
reason="end of contract",
|
||||
counts={"files": 2},
|
||||
occurred_at=occurred_at,
|
||||
details={"mode": "retire"},
|
||||
)
|
||||
|
||||
self.assertEqual(TENANT_EVENT_DELETION_REQUESTED, event.event_type)
|
||||
self.assertEqual("tenant-1", event.tenant_id)
|
||||
self.assertEqual(
|
||||
{
|
||||
"mode": "retire",
|
||||
"slug": "city",
|
||||
"name": "City Office",
|
||||
"actor_account_id": "account-1",
|
||||
"requested_by_account_id": "account-2",
|
||||
"reason": "end of contract",
|
||||
"counts": {"files": 2},
|
||||
"occurred_at": "2026-07-11T12:30:00+00:00",
|
||||
},
|
||||
event.audit_details(),
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user