Add typed IDM relationship contracts
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from govoplan_core.core.idm import (
|
||||
IdentityRelationshipDecisionRef,
|
||||
IdentityRelationshipRef,
|
||||
IdmRelationshipDirectory,
|
||||
TypedGroupMembershipResolutionRef,
|
||||
TypedGroupRef,
|
||||
)
|
||||
|
||||
|
||||
class RelationshipDirectoryStub:
|
||||
def get_typed_group(self, group_id, *, tenant_id=None):
|
||||
return None
|
||||
|
||||
def list_typed_groups(self, **kwargs):
|
||||
return ()
|
||||
|
||||
def identity_relationships_for_identity(self, identity_id, **kwargs):
|
||||
return ()
|
||||
|
||||
def identity_relationships_for_identities(self, identity_ids, **kwargs):
|
||||
return {identity_id: () for identity_id in identity_ids}
|
||||
|
||||
def identity_relationships_for_group(self, group_id, **kwargs):
|
||||
return ()
|
||||
|
||||
def identity_relationships_for_groups(self, group_ids, **kwargs):
|
||||
return {group_id: () for group_id in group_ids}
|
||||
|
||||
def resolve_typed_group_memberships(self, group_ids, **kwargs):
|
||||
return {}
|
||||
|
||||
|
||||
class IdmRelationshipContractTests(unittest.TestCase):
|
||||
def test_runtime_protocol_and_resolution_identity_projection(self) -> None:
|
||||
self.assertIsInstance(RelationshipDirectoryStub(), IdmRelationshipDirectory)
|
||||
relationship = IdentityRelationshipRef(
|
||||
id="relationship-1",
|
||||
tenant_id="tenant-1",
|
||||
relationship_kind="member",
|
||||
subject_identity_id="identity-1",
|
||||
target_group_id="group-1",
|
||||
)
|
||||
resolution = TypedGroupMembershipResolutionRef(
|
||||
group=TypedGroupRef(
|
||||
id="group-1",
|
||||
tenant_id="tenant-1",
|
||||
key="group",
|
||||
name="Group",
|
||||
group_type="business_status",
|
||||
),
|
||||
effective_at=datetime(2026, 8, 2, tzinfo=timezone.utc),
|
||||
decisions=(
|
||||
IdentityRelationshipDecisionRef(
|
||||
relationship=relationship,
|
||||
included=True,
|
||||
code="relationship.effective",
|
||||
explanation="The relationship is effective.",
|
||||
identity_status="active",
|
||||
),
|
||||
IdentityRelationshipDecisionRef(
|
||||
relationship=relationship,
|
||||
included=False,
|
||||
code="relationship.revoked",
|
||||
explanation="The relationship was revoked.",
|
||||
identity_status="active",
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
self.assertEqual(("identity-1",), resolution.identity_ids)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user