Files
NtR-soudcloud-fetcher/tests/test_week.py
cottongin 82049ab47f feat: delay show rotation during live recording window
Decouple the like-window boundary (Wed 10pm ET) from when the system
rotates to a new show. NTR_SHOW_ROTATION_DELAY_HOURS=2 keeps the
previous week's show visible during the ~2 hour recording, then creates
the new show at midnight.

Made-with: Cursor
2026-04-01 21:29:42 -04:00

86 lines
4.0 KiB
Python

from datetime import datetime, timezone
from ntr_fetcher.week import get_current_show_week, get_show_week
def test_mid_week_thursday():
"""Thursday should belong to the show that started the previous Wednesday."""
# 2025-03-13 is Thursday (2026-03-13 is Friday)
now = datetime(2025, 3, 13, 15, 0, 0, tzinfo=timezone.utc)
start, end = get_show_week(now, show_day=2, show_hour=22)
assert start == datetime(2025, 3, 13, 2, 0, 0, tzinfo=timezone.utc)
assert end == datetime(2025, 3, 20, 2, 0, 0, tzinfo=timezone.utc)
def test_wednesday_before_show():
"""Wednesday before 22:00 ET belongs to the previous week's show."""
# 2025-03-12 is Wednesday
now = datetime(2025, 3, 12, 20, 0, 0, tzinfo=timezone.utc)
start, end = get_show_week(now, show_day=2, show_hour=22)
assert start == datetime(2025, 3, 6, 3, 0, 0, tzinfo=timezone.utc)
assert end == datetime(2025, 3, 13, 2, 0, 0, tzinfo=timezone.utc)
def test_wednesday_after_show_starts():
"""Wednesday at or after 22:00 ET belongs to the new week."""
# 2025-03-13 02:30 UTC = Wed 2025-03-12 22:30 ET
now = datetime(2025, 3, 13, 2, 30, 0, tzinfo=timezone.utc)
start, end = get_show_week(now, show_day=2, show_hour=22)
assert start == datetime(2025, 3, 13, 2, 0, 0, tzinfo=timezone.utc)
assert end == datetime(2025, 3, 20, 2, 0, 0, tzinfo=timezone.utc)
def test_est_period_no_dst():
"""January — firmly in EST (UTC-5)."""
now = datetime(2026, 1, 15, 12, 0, 0, tzinfo=timezone.utc)
start, end = get_show_week(now, show_day=2, show_hour=22)
assert start == datetime(2026, 1, 15, 3, 0, 0, tzinfo=timezone.utc)
assert end == datetime(2026, 1, 22, 3, 0, 0, tzinfo=timezone.utc)
# --- get_current_show_week tests ---
def test_current_show_week_zero_delay_matches_get_show_week():
"""delay=0 is a passthrough to get_show_week."""
now = datetime(2026, 1, 15, 12, 0, 0, tzinfo=timezone.utc)
assert get_current_show_week(now, show_day=2, show_hour=22, rotation_delay_hours=0) == \
get_show_week(now, show_day=2, show_hour=22)
def test_current_show_week_in_gap_returns_old_week():
"""Wed 22:30 EST (in the 2-hour gap) should still show the previous week."""
# Wed Jan 14 22:30 EST = Thu Jan 15 03:30 UTC
now = datetime(2026, 1, 15, 3, 30, 0, tzinfo=timezone.utc)
start, end = get_current_show_week(now, show_day=2, show_hour=22, rotation_delay_hours=2)
# Previous week: Wed Jan 7 22:00 EST = Jan 8 03:00 UTC
assert start == datetime(2026, 1, 8, 3, 0, 0, tzinfo=timezone.utc)
assert end == datetime(2026, 1, 15, 3, 0, 0, tzinfo=timezone.utc)
def test_current_show_week_at_rotation_boundary():
"""Thu 00:00 EST (exactly at midnight) should rotate to the new week."""
# Thu Jan 15 00:00 EST = Thu Jan 15 05:00 UTC
now = datetime(2026, 1, 15, 5, 0, 0, tzinfo=timezone.utc)
start, end = get_current_show_week(now, show_day=2, show_hour=22, rotation_delay_hours=2)
# New week: Wed Jan 14 22:00 EST = Jan 15 03:00 UTC
assert start == datetime(2026, 1, 15, 3, 0, 0, tzinfo=timezone.utc)
assert end == datetime(2026, 1, 22, 3, 0, 0, tzinfo=timezone.utc)
def test_current_show_week_well_after_gap():
"""Thursday afternoon is well past the gap — new week regardless of delay."""
now = datetime(2026, 1, 15, 16, 0, 0, tzinfo=timezone.utc)
start, end = get_current_show_week(now, show_day=2, show_hour=22, rotation_delay_hours=2)
assert start == datetime(2026, 1, 15, 3, 0, 0, tzinfo=timezone.utc)
assert end == datetime(2026, 1, 22, 3, 0, 0, tzinfo=timezone.utc)
def test_current_show_week_before_show_time_unaffected():
"""Wednesday before the show (e.g. 3pm ET) is unaffected by rotation delay."""
# Wed Jan 14 15:00 EST = Wed Jan 14 20:00 UTC
now = datetime(2026, 1, 14, 20, 0, 0, tzinfo=timezone.utc)
with_delay = get_current_show_week(now, show_day=2, show_hour=22, rotation_delay_hours=2)
without_delay = get_show_week(now, show_day=2, show_hour=22)
assert with_delay == without_delay