Skip to content

Commit 0b20a07

Browse files
oschwaldclaude
andcommitted
Share the RFC 3339 time validation tests
The event, phone, and email verification time tests repeated the same loops. Use one check_rfc3339_time helper, next to check_bool, for all three fields. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 4145164 commit 0b20a07

1 file changed

Lines changed: 9 additions & 28 deletions

File tree

‎tests/test_validation.py‎

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ def check_bool(self, obj: str, key: str) -> None:
8282
for bad in ("", 0, "True"):
8383
self.check_invalid_transaction({obj: {key: bad}})
8484

85+
def check_rfc3339_time(self, obj: str, key: str) -> None:
86+
for good in GOOD_TIMES:
87+
self.check_transaction({obj: {key: good}})
88+
for bad in BAD_TIMES + NON_STRING_TIMES:
89+
self.check_invalid_transaction({obj: {key: bad}})
90+
8591
def setup_report(self, report: dict[str, Any]) -> None:
8692
if "ip_address" not in report:
8793
report["ip_address"] = "1.2.3.4"
@@ -186,18 +192,7 @@ def test_phone_was_verification_successful(self) -> None:
186192
self.check_bool(self.type, "phone_was_verification_successful")
187193

188194
def test_phone_verification_time(self) -> None:
189-
for good in GOOD_TIMES:
190-
self.check_transaction({self.type: {"phone_verification_time": good}})
191-
for bad in BAD_TIMES:
192-
self.check_invalid_transaction(
193-
{self.type: {"phone_verification_time": bad}},
194-
)
195-
196-
def test_phone_verification_time_not_string(self) -> None:
197-
for bad in NON_STRING_TIMES:
198-
self.check_invalid_transaction(
199-
{self.type: {"phone_verification_time": bad}},
200-
)
195+
self.check_rfc3339_time(self.type, "phone_verification_time")
201196

202197

203198
class TestBillingAddress(AddressBase):
@@ -372,14 +367,7 @@ def test_domain(self) -> None:
372367
self.check_invalid_transaction({"email": {"domain": bad}})
373368

374369
def test_verification_time(self) -> None:
375-
for good in GOOD_TIMES:
376-
self.check_transaction({"email": {"verification_time": good}})
377-
for bad in BAD_TIMES:
378-
self.check_invalid_transaction({"email": {"verification_time": bad}})
379-
380-
def test_verification_time_not_string(self) -> None:
381-
for bad in NON_STRING_TIMES:
382-
self.check_invalid_transaction({"email": {"verification_time": bad}})
370+
self.check_rfc3339_time("email", "verification_time")
383371

384372
def test_was_verification_successful(self) -> None:
385373
self.check_bool("email", "was_verification_successful")
@@ -399,14 +387,7 @@ def test_shop_id(self) -> None:
399387
self.check_transaction_str_type("event", "shop_id")
400388

401389
def test_time(self) -> None:
402-
for good in GOOD_TIMES:
403-
self.check_transaction({"event": {"time": good}})
404-
for bad in BAD_TIMES:
405-
self.check_invalid_transaction({"event": {"time": bad}})
406-
407-
def test_time_not_string(self) -> None:
408-
for bad in NON_STRING_TIMES:
409-
self.check_invalid_transaction({"event": {"time": bad}})
390+
self.check_rfc3339_time("event", "time")
410391

411392
def test_time_impossible_date_message(self) -> None:
412393
transaction: dict[str, Any] = {"event": {"time": "2026-02-30T10:00:00Z"}}

0 commit comments

Comments
 (0)