56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
from __future__ import annotations
|
|
|
|
import unittest
|
|
from datetime import UTC, datetime
|
|
|
|
from govoplan_core.core.contact_points import (
|
|
CAPABILITY_ADDRESSES_CONTACT_POINT_RESOLUTION,
|
|
CONTACT_POINT_CONTRACT_VERSION,
|
|
ContactPointResolutionRequest,
|
|
contact_point_resolution_provider,
|
|
)
|
|
from govoplan_core.core.distribution_lists import DistributionSourceReference
|
|
|
|
|
|
class _Registry:
|
|
def __init__(self, capability: object | None = None) -> None:
|
|
self._capability = capability
|
|
|
|
def has_capability(self, name: str) -> bool:
|
|
return (
|
|
name == CAPABILITY_ADDRESSES_CONTACT_POINT_RESOLUTION
|
|
and self._capability is not None
|
|
)
|
|
|
|
def capability(self, _name: str) -> object:
|
|
return self._capability
|
|
|
|
|
|
class ContactPointContractTests(unittest.TestCase):
|
|
def test_request_is_provider_neutral_and_versioned(self) -> None:
|
|
request = ContactPointResolutionRequest(
|
|
tenant_id="tenant-1",
|
|
subject=DistributionSourceReference(
|
|
provider="idm",
|
|
resource_type="identity",
|
|
resource_id="identity-1",
|
|
),
|
|
effective_at=datetime(2026, 8, 2, tzinfo=UTC),
|
|
requested_channels=("email", "postal"),
|
|
address_purpose="official",
|
|
fallback_rule="primary",
|
|
postal_format="international",
|
|
)
|
|
|
|
self.assertEqual("1.0", CONTACT_POINT_CONTRACT_VERSION)
|
|
self.assertEqual("idm", request.subject.provider)
|
|
self.assertEqual(("email", "postal"), request.requested_channels)
|
|
|
|
def test_accessor_rejects_objects_that_do_not_implement_the_protocol(self) -> None:
|
|
self.assertIsNone(contact_point_resolution_provider(None))
|
|
self.assertIsNone(contact_point_resolution_provider(_Registry(object())))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|