|
16 | 16 | serialize_exception, |
17 | 17 | ) |
18 | 18 |
|
19 | | - |
20 | 19 | # --------------------------------------------------------------------------- |
21 | 20 | # Helpers |
22 | 21 | # --------------------------------------------------------------------------- |
@@ -202,12 +201,48 @@ def test_error_method_uses_exception_key(): |
202 | 201 | # --------------------------------------------------------------------------- |
203 | 202 |
|
204 | 203 |
|
205 | | -def test_log_entry_time_is_timezone_aware(): |
206 | | - """LogEntry.time must include timezone offset (not naive UTC).""" |
| 204 | +def test_log_entry_time_uses_z_suffix(): |
| 205 | + """LogEntry.time must use Z suffix for UTC (required by server schema).""" |
207 | 206 | entry = LogEntry(service="svc", level=LogLevel.INFO, message="hello") |
208 | 207 | assert entry.time is not None |
209 | | - # timezone.utc isoformat produces '+00:00' suffix |
210 | | - assert "+00:00" in entry.time or "Z" in entry.time |
| 208 | + assert entry.time.endswith("Z") |
| 209 | + assert "+00:00" not in entry.time |
| 210 | + |
| 211 | + |
| 212 | +def test_log_entry_normalizes_offset_to_z(): |
| 213 | + """Caller-supplied +00:00 offset must be normalized to Z.""" |
| 214 | + entry = LogEntry( |
| 215 | + service="svc", |
| 216 | + level=LogLevel.INFO, |
| 217 | + message="hello", |
| 218 | + time="2026-04-05T10:00:00.123456+00:00", |
| 219 | + ) |
| 220 | + assert entry.time == "2026-04-05T10:00:00.123456Z" |
| 221 | + |
| 222 | + |
| 223 | +def test_log_entry_preserves_non_utc_offset(): |
| 224 | + """Non-UTC offsets must be left as-is (caller's responsibility).""" |
| 225 | + entry = LogEntry( |
| 226 | + service="svc", |
| 227 | + level=LogLevel.INFO, |
| 228 | + message="hello", |
| 229 | + time="2026-04-05T10:00:00+03:00", |
| 230 | + ) |
| 231 | + assert entry.time == "2026-04-05T10:00:00+03:00" |
| 232 | + |
| 233 | + |
| 234 | +def test_to_dict_omits_none_trace_id(): |
| 235 | + """to_dict() must omit trace_id when None (server rejects null).""" |
| 236 | + entry = LogEntry(service="svc", level=LogLevel.INFO, message="hello") |
| 237 | + d = entry.to_dict() |
| 238 | + assert "trace_id" not in d |
| 239 | + |
| 240 | + |
| 241 | +def test_to_dict_includes_trace_id_when_set(): |
| 242 | + """to_dict() must include trace_id when it has a value.""" |
| 243 | + entry = LogEntry(service="svc", level=LogLevel.INFO, message="hello", trace_id="abc-123") |
| 244 | + d = entry.to_dict() |
| 245 | + assert d["trace_id"] == "abc-123" |
211 | 246 |
|
212 | 247 |
|
213 | 248 | # --------------------------------------------------------------------------- |
|
0 commit comments