/code-review high round 1 (5 findings): - iso(dt) now typed `date | None` — MediaAsset.upload_date is a plain `date`, not a datetime; the helper's signature was too narrow for the type-contract epic. +test. - restore alphabetical app.* import order in audit.py and plex.py (the new iso/_common imports had been dropped in mid-block). The other 3 findings are deliberate design choices, left as-is for UAT: push/push-plan now gate write-scope before the 404 (dependency ordering); the unified 403 message; and owned_or_404's owner_attr kept for S1b's DownloadShare.to_user_id-style owners. Gate: ruff clean, pytest 164 green.
31 lines
997 B
Python
31 lines
997 B
Python
"""iso(): the single date/datetime→JSON serializer the routes share (R6 S1a)."""
|
|
from datetime import date, datetime, timezone
|
|
|
|
from app.utils import iso
|
|
|
|
|
|
def test_none_maps_to_none():
|
|
assert iso(None) is None
|
|
|
|
|
|
def test_plain_date_serializes_as_iso_date():
|
|
# MediaAsset.upload_date is a `date`, not a datetime — the contract must accept it.
|
|
assert iso(date(2026, 7, 26)) == "2026-07-26"
|
|
|
|
|
|
def test_aware_datetime_keeps_offset():
|
|
dt = datetime(2026, 7, 26, 12, 30, 0, tzinfo=timezone.utc)
|
|
assert iso(dt) == "2026-07-26T12:30:00+00:00"
|
|
|
|
|
|
def test_naive_datetime_serializes_without_offset():
|
|
dt = datetime(2026, 7, 26, 12, 30, 0)
|
|
assert iso(dt) == "2026-07-26T12:30:00"
|
|
|
|
|
|
def test_matches_datetime_isoformat_contract():
|
|
# iso is exactly `dt.isoformat()` for a present value — guards the routes that used to
|
|
# hand-roll `x.isoformat() if x else None`.
|
|
dt = datetime(2020, 1, 2, 3, 4, 5, 678901, tzinfo=timezone.utc)
|
|
assert iso(dt) == dt.isoformat()
|