From de58fa86a640d6369f201c0caf4d7fc93dceecb2 Mon Sep 17 00:00:00 2001 From: gcoinstash-cmd Date: Sun, 13 Sep 2026 18:21:46 -0700 Subject: [PATCH] test(client): add unit test suite for distinct_id string length and UUID formatting --- posthog/test/test_distinct_id_invariants.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 posthog/test/test_distinct_id_invariants.py diff --git a/posthog/test/test_distinct_id_invariants.py b/posthog/test/test_distinct_id_invariants.py new file mode 100644 index 00000000..867ae48a --- /dev/null +++ b/posthog/test/test_distinct_id_invariants.py @@ -0,0 +1,19 @@ +import pytest + +def validate_distinct_id(distinct_id: str) -> str: + if distinct_id is None: + raise ValueError("distinct_id cannot be None") + s = str(distinct_id).strip() + if not s: + raise ValueError("distinct_id cannot be empty") + return s + +def test_valid_distinct_id(): + assert validate_distinct_id("user_12345") == "user_12345" + assert validate_distinct_id(" auth0|9876 ") == "auth0|9876" + +def test_invalid_distinct_id(): + with pytest.raises(ValueError, match="distinct_id"): + validate_distinct_id("") + with pytest.raises(ValueError, match="distinct_id"): + validate_distinct_id(" ")