@@ -161,7 +161,7 @@ def unique(request, freezed_time):
161161 return f"{ prefix } -{ int (freezed_time .timestamp ())} "
162162
163163
164- def relative_time (freezed_time , iso ):
164+ def relative_time (freezed_time , iso , is_iso_with_timezone_indicator ):
165165 time_re = re .compile (r"now( *([+-]) *(\d+)([smhdMy]))?" )
166166
167167 def func (arg ):
@@ -185,10 +185,16 @@ def func(arg):
185185 elif unit == "y" :
186186 ret += relativedelta (years = num )
187187 if iso :
188- # Return ISO 8601 formatted string with Z timezone indicator
189- # Example: 2025-04-17T03:17:07.923Z
190- from datetime import timezone
191- return ret .astimezone (timezone .utc ).isoformat (timespec = "milliseconds" ).replace ("+00:00" , "Z" )
188+ if is_iso_with_timezone_indicator :
189+ # Return ISO 8601 formatted string with Z timezone indicator
190+ # Example: 2025-04-17T03:17:07.923Z
191+ from datetime import timezone
192+ return ret .astimezone (timezone .utc ).isoformat (timespec = "milliseconds" ).replace ("+00:00" , "Z" )
193+ else :
194+ return ret .replace (tzinfo = None ) # return datetime object and not string
195+ # NOTE this is not a full ISO 8601 format, but it's enough for our needs
196+ # return ret.strftime('%Y-%m-%dT%H:%M:%S') + ret.strftime('.%f')[:4] + 'Z'
197+
192198 return int (ret .timestamp ())
193199 return ""
194200
@@ -207,6 +213,10 @@ def context(vcr, unique, freezed_time):
207213 and the undo operations to perform after a test scenario.
208214 """
209215 unique_hash = hashlib .sha256 (unique .encode ("utf-8" )).hexdigest ()[:16 ]
216+
217+ # Dirty fix as on_call cassette and API use the `Z` format instead of `+00:00`
218+ is_iso_with_timezone_indicator = "on_call" in unique
219+
210220 ctx = {
211221 "undo_operations" : [],
212222 "unique" : unique ,
@@ -216,8 +226,8 @@ def context(vcr, unique, freezed_time):
216226 "unique_lower_alnum" : PATTERN_ALPHANUM .sub ("" , unique ).lower (),
217227 "unique_upper_alnum" : PATTERN_ALPHANUM .sub ("" , unique ).upper (),
218228 "unique_hash" : unique_hash ,
219- "timestamp" : relative_time (freezed_time , False ),
220- "timeISO" : relative_time (freezed_time , True ),
229+ "timestamp" : relative_time (freezed_time , False , False ),
230+ "timeISO" : relative_time (freezed_time , True , is_iso_with_timezone_indicator ),
221231 "uuid" : generate_uuid (freezed_time ),
222232 }
223233
0 commit comments