fix: convert feed timestamps to US/Eastern and add test
Made-with: Cursor
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import json
|
||||
import logging
|
||||
from datetime import datetime, timezone
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
import feedparser
|
||||
import requests
|
||||
@@ -44,6 +45,9 @@ def fetch_and_cache_articles() -> dict:
|
||||
except Exception:
|
||||
pub_date = datetime.now(timezone.utc)
|
||||
|
||||
# Convert to US/Eastern and make naive for SQLite
|
||||
pub_date = pub_date.astimezone(ZoneInfo("America/New_York")).replace(tzinfo=None)
|
||||
|
||||
categories = [t.term for t in entry.get("tags", [])]
|
||||
|
||||
content_html = ""
|
||||
|
||||
@@ -81,3 +81,19 @@ def test_fetch_handles_feed_error(app, db):
|
||||
|
||||
assert result["error"] is not None
|
||||
assert Article.query.count() == 0
|
||||
|
||||
|
||||
def test_fetch_converts_timezone_to_eastern(app, db):
|
||||
with app.app_context():
|
||||
with patch("src.fetcher.requests.get") as mock_get:
|
||||
mock_get.return_value = _mock_feed_response(SAMPLE_RSS_XML)
|
||||
with patch("src.fetcher.process_image") as mock_img:
|
||||
mock_img.return_value = ("/fake/path.jpg", 800, 450)
|
||||
fetch_and_cache_articles()
|
||||
|
||||
article = Article.query.filter_by(title="Test Article One").first()
|
||||
# The XML has: Mon, 06 Apr 2026 12:00:00 +0000
|
||||
# US/Eastern in April is EDT (UTC-4), so it should be 08:00:00
|
||||
assert article.pub_date.tzinfo is None
|
||||
assert article.pub_date.hour == 8
|
||||
assert article.pub_date.minute == 0
|
||||
|
||||
Reference in New Issue
Block a user