Files
sigcal/tests/test_feed.py
T
kawaiipunk bdd41929d4 Fix watchdog gaps, image failures and stale reminders
- catch httpx errors on send/heartbeat so a dead signal-api alerts instead
  of failing silently
- never let compose/images block the text post; count failed attempts
- drop reminders for events removed from the feed, using the feed's
  coverage horizon so the 30-event cap does not mark future events gone
- persist feed validators only after a successful parse
- do not seed from an empty feed
- flatten transparent images onto white; catch decompression bombs
- --dump uses a throwaway database
- avoid duplicated postcode in the venue line
- remove dead code; add regression tests
2026-11-18 16:42:47 +00:00

57 lines
1.9 KiB
Python

from __future__ import annotations
from datetime import datetime, timezone
from pathlib import Path
import httpx
from calbot.feed import Feed, FeedResponse, normalize_feed_url
from calbot.store import Store
NOW = datetime(2026, 11, 18, 12, 0, tzinfo=timezone.utc)
EMPTY_FEED = b"BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//test//EN\r\nEND:VCALENDAR\r\n"
def test_webcal_is_fetched_over_https():
assert normalize_feed_url("webcal://example.test/x.ics") == "https://example.test/x.ics"
assert normalize_feed_url("https://example.test/x.ics") == "https://example.test/x.ics"
def test_validators_are_only_stored_after_commit(tmp_path):
def handler(request: httpx.Request) -> httpx.Response:
if request.headers.get("if-none-match") == '"abc"':
return httpx.Response(304)
return httpx.Response(200, content=EMPTY_FEED, headers={"ETag": '"abc"'})
store = Store(Path(tmp_path) / "db.sqlite3")
client = httpx.Client(transport=httpx.MockTransport(handler))
feed = Feed("webcal://example.test/feed.ics", store, 15, client)
response = feed.fetch(NOW)
assert isinstance(response, FeedResponse)
assert response.content == EMPTY_FEED
# A parse failure would skip commit(), so nothing may be persisted yet.
assert store.get_meta("feed_etag") is None
feed.commit(response)
assert store.get_meta("feed_etag") == '"abc"'
second = feed.fetch(NOW)
assert second.not_modified
assert second.content is None
def test_fetch_raises_on_http_error(tmp_path):
def handler(request: httpx.Request) -> httpx.Response:
return httpx.Response(500, text="boom")
store = Store(Path(tmp_path) / "db.sqlite3")
client = httpx.Client(transport=httpx.MockTransport(handler))
feed = Feed("https://example.test/feed.ics", store, 15, client)
try:
feed.fetch(NOW)
except httpx.HTTPStatusError:
pass
else: # pragma: no cover
raise AssertionError("expected HTTPStatusError")