refactor(forms-runtime): centralize owner-specific email normalization
Module Package Release / publish-packages (push) Successful in 14s
Module Package Release / publish-packages (push) Successful in 14s
Release v0.1.22. Coordinated integrity review: GovOPlaN/govoplan-core#298.
This commit is contained in:
Executable
+37
@@ -0,0 +1,37 @@
|
||||
import unittest
|
||||
|
||||
from govoplan_forms_runtime.backend.dsar_provider import _normalized_email
|
||||
from govoplan_forms_runtime.backend.email_normalization import normalize_status_email
|
||||
from govoplan_forms_runtime.backend.status_access import _normalize_email
|
||||
|
||||
|
||||
class EmailNormalizationTests(unittest.TestCase):
|
||||
def test_status_access_and_dsar_share_the_same_selector_policy(self) -> None:
|
||||
self.assertIs(normalize_status_email, _normalize_email)
|
||||
self.assertIs(normalize_status_email, _normalized_email)
|
||||
|
||||
def test_existing_selector_results_remain_exact_at_policy_boundaries(self) -> None:
|
||||
boundary = "a" * 308 + "@example.org"
|
||||
values = (
|
||||
(None, None), (False, None), (0, None), ("", None), (" ", None),
|
||||
(" Subject@Example.ORG ", "subject@example.org"),
|
||||
("\u00a0Straße@BÜRO.Example\u00a0", "strasse@büro.example"),
|
||||
("a+b@sub.example.org", "a+b@sub.example.org"),
|
||||
("a..b@example..org", "a..b@example..org"), # Existing policy, not a new RFC validator.
|
||||
("a b@example.org", None), ("a@exa\tmple.org", None), ("a@exa\u00a0mple.org", None),
|
||||
("a@@example.org", None), ("@example.org", None), ("a@example", None),
|
||||
("a@.example.org", None), ("a@example.org.", None),
|
||||
(boundary, boundary), ("a" + boundary, None),
|
||||
)
|
||||
for value, expected in values:
|
||||
with self.subTest(value=value):
|
||||
self.assertEqual(expected, normalize_status_email(value))
|
||||
|
||||
def test_selector_canonicalization_does_not_mutate_submitted_values(self) -> None:
|
||||
values = {"email": " Subject@Example.ORG ", "other": ["001", " ", None]}
|
||||
self.assertEqual("subject@example.org", normalize_status_email(values["email"]))
|
||||
self.assertEqual({"email": " Subject@Example.ORG ", "other": ["001", " ", None]}, values)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user