Add scoped postbox template previews
This commit is contained in:
@@ -899,6 +899,133 @@ class PostboxServiceTests(unittest.TestCase):
|
||||
revised.revisions[1].name_pattern,
|
||||
)
|
||||
|
||||
def test_template_preview_is_read_only_and_explains_existing_vacant_and_colliding_targets(
|
||||
self,
|
||||
) -> None:
|
||||
self.idm.assignments = [self.assignment]
|
||||
with Session(self.engine) as session:
|
||||
template = self.service.create_template(
|
||||
session,
|
||||
tenant_id="tenant-1",
|
||||
slug="case-intake",
|
||||
name="Case intake",
|
||||
description=None,
|
||||
function_type_id="case-clerk-type",
|
||||
scope_kind="tenant",
|
||||
scope_id=None,
|
||||
name_pattern="{unit_name} / {function_name}",
|
||||
address_pattern="{template_slug}.{unit_slug}.{function_slug}",
|
||||
classification="internal",
|
||||
allow_vacant_delivery=True,
|
||||
actor_id="admin-1",
|
||||
)
|
||||
self.service.publish_template(
|
||||
session,
|
||||
tenant_id="tenant-1",
|
||||
template_id=template.id,
|
||||
revision_number=None,
|
||||
actor_id="admin-1",
|
||||
expected_revision=template.resource_revision,
|
||||
)
|
||||
self.service.materialize_template(
|
||||
session,
|
||||
tenant_id="tenant-1",
|
||||
template_id=template.id,
|
||||
organization_unit_id="unit-1",
|
||||
function_id="function-1",
|
||||
context_key=None,
|
||||
actor_id="admin-1",
|
||||
)
|
||||
before = session.query(Postbox).count()
|
||||
|
||||
preview = self.service.preview_template_targets(
|
||||
session,
|
||||
tenant_id="tenant-1",
|
||||
template_id=template.id,
|
||||
slug=template.slug,
|
||||
name=template.name,
|
||||
description=None,
|
||||
function_type_id="case-clerk-type",
|
||||
scope_kind="tenant",
|
||||
scope_id=None,
|
||||
scope_structure_id=None,
|
||||
scope_relation_type_ids=(),
|
||||
name_pattern="{unit_name} / {function_name}",
|
||||
address_pattern="{template_slug}.{unit_slug}.{function_slug}",
|
||||
classification="internal",
|
||||
allow_vacant_delivery=True,
|
||||
routing_policy={},
|
||||
encryption_profile="plaintext_v1",
|
||||
encryption_vault_id=None,
|
||||
context_key=None,
|
||||
limit=200,
|
||||
)
|
||||
|
||||
self.assertEqual(3, preview["total"])
|
||||
self.assertEqual(1, preview["existing_count"])
|
||||
self.assertEqual(2, preview["vacant_count"])
|
||||
self.assertEqual(before, session.query(Postbox).count())
|
||||
|
||||
collision_preview = self.service.preview_template_targets(
|
||||
session,
|
||||
tenant_id="tenant-1",
|
||||
template_id=None,
|
||||
slug="collision",
|
||||
name="Collision",
|
||||
description=None,
|
||||
function_type_id="case-clerk-type",
|
||||
scope_kind="tenant",
|
||||
scope_id=None,
|
||||
scope_structure_id=None,
|
||||
scope_relation_type_ids=(),
|
||||
name_pattern="{unit_name} / {function_name}",
|
||||
address_pattern="same-address",
|
||||
classification="internal",
|
||||
allow_vacant_delivery=True,
|
||||
routing_policy={},
|
||||
encryption_profile="plaintext_v1",
|
||||
encryption_vault_id=None,
|
||||
context_key=None,
|
||||
limit=200,
|
||||
)
|
||||
self.assertEqual(3, collision_preview["blocked_count"])
|
||||
self.assertIn(
|
||||
"duplicate_generated_address",
|
||||
collision_preview["diagnostics"],
|
||||
)
|
||||
|
||||
self.organizations.duplicate_parent_match = True
|
||||
hierarchy_preview = self.service.preview_template_targets(
|
||||
session,
|
||||
tenant_id="tenant-1",
|
||||
template_id=None,
|
||||
slug="hierarchy",
|
||||
name="Hierarchy",
|
||||
description=None,
|
||||
function_type_id="case-clerk-type",
|
||||
scope_kind="subtree",
|
||||
scope_id="unit-child",
|
||||
scope_structure_id="structure-1",
|
||||
scope_relation_type_ids=("relation-type-1",),
|
||||
name_pattern="{unit_name} / {function_name}",
|
||||
address_pattern="{template_slug}.{unit_slug}.{function_slug}",
|
||||
classification="internal",
|
||||
allow_vacant_delivery=True,
|
||||
routing_policy={},
|
||||
encryption_profile="plaintext_v1",
|
||||
encryption_vault_id=None,
|
||||
context_key=None,
|
||||
limit=200,
|
||||
)
|
||||
self.assertIn(
|
||||
"ambiguous_scope_paths",
|
||||
hierarchy_preview["diagnostics"],
|
||||
)
|
||||
self.assertEqual(
|
||||
"descendants",
|
||||
self.organizations.last_hierarchy_request["direction"],
|
||||
)
|
||||
|
||||
def test_delivery_catalog_exposes_exact_and_derived_target_choices(
|
||||
self,
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user