@@ -3872,7 +3872,9 @@ async def test_cache_hit_past_start_resolves(self):
38723872 async def test_db_path_future_start_raises_after_recache (self ):
38733873 svc , url_repo , url_cache = self ._svc ()
38743874 url_cache .get .return_value = None
3875- future = datetime .now (timezone .utc ) + timedelta (hours = 1 )
3875+ future = (datetime .now (timezone .utc ) + timedelta (hours = 1 )).replace (
3876+ microsecond = 0
3877+ )
38763878 url_repo .find_by_alias .return_value = make_url_v2_doc (starts_at = future )
38773879
38783880 with pytest .raises (NotYetLiveError ) as exc :
@@ -4002,6 +4004,36 @@ async def test_update_start_after_existing_expiry_rejected(self):
40024004 URL_OID , UpdateUrlRequest (starts_at = self .FUTURE_TS + 60 ), USER_OID
40034005 )
40044006
4007+ @pytest .mark .asyncio
4008+ async def test_update_start_against_naive_stored_expiry_is_a_400_not_a_500 (self ):
4009+ """Mongo hands back naive UTC; the request side is aware. The order
4010+ check must normalise both or the comparison raises TypeError."""
4011+ svc , url_repo , _url_cache = self ._svc ()
4012+ from schemas .dto .requests .url import UpdateUrlRequest
4013+
4014+ naive_expiry = datetime .fromtimestamp (self .FUTURE_TS , tz = timezone .utc ).replace (
4015+ tzinfo = None
4016+ )
4017+ url_repo .find_by_id .return_value = make_url_v2_doc (expire_after = naive_expiry )
4018+ with pytest .raises (ValidationError , match = "before expire_after" ):
4019+ await svc .update (
4020+ URL_OID , UpdateUrlRequest (starts_at = self .FUTURE_TS + 60 ), USER_OID
4021+ )
4022+
4023+ @pytest .mark .asyncio
4024+ async def test_update_expiry_against_naive_stored_start_is_a_400_not_a_500 (self ):
4025+ svc , url_repo , _url_cache = self ._svc ()
4026+ from schemas .dto .requests .url import UpdateUrlRequest
4027+
4028+ naive_start = datetime .fromtimestamp (self .FUTURE_TS , tz = timezone .utc ).replace (
4029+ tzinfo = None
4030+ )
4031+ url_repo .find_by_id .return_value = make_url_v2_doc (starts_at = naive_start )
4032+ with pytest .raises (ValidationError , match = "before expire_after" ):
4033+ await svc .update (
4034+ URL_OID , UpdateUrlRequest (expire_after = self .FUTURE_TS - 60 ), USER_OID
4035+ )
4036+
40054037 @pytest .mark .asyncio
40064038 async def test_update_unchanged_start_is_a_noop (self ):
40074039 svc , url_repo , _url_cache = self ._svc ()
0 commit comments