intermittent commit
This commit is contained in:
@@ -2,6 +2,14 @@ from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
from govoplan_policy.backend.retention import (
|
||||
PrivacyRetentionPolicy,
|
||||
PrivacyRetentionPolicyPatch,
|
||||
PrivacyPolicyError,
|
||||
_parent_privacy_policy_scope_id,
|
||||
_privacy_policy_patch_payload,
|
||||
_required_privacy_policy_scope_id,
|
||||
)
|
||||
from govoplan_policy.backend.hierarchy import (
|
||||
PolicyRestrictionRule,
|
||||
simulate_hierarchical_policy_change,
|
||||
@@ -10,6 +18,36 @@ from govoplan_policy.backend.hierarchy import (
|
||||
|
||||
|
||||
class PolicyHierarchyTests(unittest.TestCase):
|
||||
def test_privacy_policy_parent_scope_ids_follow_scope_precedence(self) -> None:
|
||||
self.assertEqual(
|
||||
"tenant-1",
|
||||
_parent_privacy_policy_scope_id(tenant_id="tenant-1", scope_type="tenant", scope_id=None),
|
||||
)
|
||||
self.assertIsNone(_parent_privacy_policy_scope_id(tenant_id="tenant-1", scope_type="user", scope_id=None))
|
||||
self.assertIsNone(_parent_privacy_policy_scope_id(tenant_id="tenant-1", scope_type="group", scope_id=None))
|
||||
self.assertEqual(
|
||||
"campaign-1",
|
||||
_parent_privacy_policy_scope_id(tenant_id="tenant-1", scope_type="campaign", scope_id="campaign-1"),
|
||||
)
|
||||
|
||||
def test_privacy_policy_patch_payload_validates_and_removes_unset_fields(self) -> None:
|
||||
payload = _privacy_policy_patch_payload({"audit_detail_level": "minimal", "generated_eml_retention_days": None})
|
||||
|
||||
self.assertEqual({"audit_detail_level": "minimal"}, payload)
|
||||
|
||||
def test_privacy_policy_models_extend_shared_schema_contract(self) -> None:
|
||||
policy = PrivacyRetentionPolicy.model_validate({"generated_eml_retention_days": ""})
|
||||
patch = PrivacyRetentionPolicyPatch.model_validate({"allow_lower_level_limits": {"audit_detail_level": False}})
|
||||
|
||||
self.assertIsNone(policy.generated_eml_retention_days)
|
||||
self.assertEqual({"audit_detail_level": False}, patch.allow_lower_level_limits)
|
||||
|
||||
def test_required_privacy_policy_scope_id_reports_missing_scope(self) -> None:
|
||||
with self.assertRaises(PrivacyPolicyError) as captured:
|
||||
_required_privacy_policy_scope_id("group", None)
|
||||
|
||||
self.assertEqual("Group privacy policy requires scope_id", str(captured.exception))
|
||||
|
||||
def test_parent_locks_block_lower_level_field_changes_and_limit_reenable(self) -> None:
|
||||
issues = validate_hierarchical_policy_patch(
|
||||
parent_policy={"retention_days": 30},
|
||||
|
||||
Reference in New Issue
Block a user