11"""Tests for the generic VersionSnapshot model."""
22
3- from datetime import UTC , datetime
3+ from datetime import UTC , datetime , timedelta
44
55import pytest
66from pydantic import BaseModel , ConfigDict , ValidationError
@@ -83,6 +83,11 @@ def test_blank_content_hash_rejected(self) -> None:
8383 with pytest .raises (ValidationError ):
8484 _make_snapshot (content_hash = "" )
8585
86+ @pytest .mark .unit
87+ def test_malformed_content_hash_rejected (self ) -> None :
88+ with pytest .raises (ValidationError , match = "64-character lowercase hex" ):
89+ _make_snapshot (content_hash = "not-a-sha256-hash" )
90+
8691 @pytest .mark .unit
8792 def test_blank_saved_by_rejected (self ) -> None :
8893 with pytest .raises (ValidationError ):
@@ -93,6 +98,14 @@ def test_naive_datetime_rejected(self) -> None:
9398 with pytest .raises (ValidationError ):
9499 _make_snapshot (saved_at = datetime (2026 , 4 , 7 , 12 , 0 )) # noqa: DTZ001
95100
101+ @pytest .mark .unit
102+ def test_non_utc_aware_datetime_rejected (self ) -> None :
103+ from datetime import timezone as tz
104+
105+ non_utc = datetime (2026 , 4 , 7 , 12 , 0 , tzinfo = tz (timedelta (hours = 5 )))
106+ with pytest .raises (ValidationError , match = "must be UTC" ):
107+ _make_snapshot (saved_at = non_utc )
108+
96109 @pytest .mark .unit
97110 def test_version_two_accepted (self ) -> None :
98111 s = _make_snapshot (version = 2 )
0 commit comments