fix: add timeout and error wrapping to _find_sticky, clean up test fixture
This commit is contained in:
parent
e37be0935d
commit
90d30167f8
2 changed files with 7 additions and 3 deletions
|
|
@ -73,8 +73,12 @@ def _find_sticky(
|
|||
"""
|
||||
# TODO: use session_file for authenticated requests on private subs
|
||||
url = f"https://www.reddit.com/r/{sub}/hot.json?limit=10"
|
||||
response = httpx.get(url, headers={"User-Agent": "magpie/1.0"})
|
||||
response.raise_for_status()
|
||||
try:
|
||||
response = httpx.get(url, headers={"User-Agent": "magpie/1.0"}, timeout=10)
|
||||
response.raise_for_status()
|
||||
except httpx.HTTPError as exc:
|
||||
logger.warning("Reddit hot.json request failed for r/%s: %s", sub, exc)
|
||||
raise RuntimeError(f"Failed to fetch hot listing for r/{sub}") from exc
|
||||
payload = response.json()
|
||||
if "data" not in payload:
|
||||
logger.warning("Unexpected Reddit API response: %r", payload)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ def strategy():
|
|||
return RedditCommentStrategy()
|
||||
|
||||
|
||||
def test_execute_with_url_override(strategy, monkeypatch):
|
||||
def test_execute_with_url_override(strategy):
|
||||
"""Uses thread_url_override to get thread_id, calls client.comment()"""
|
||||
mock_client = MagicMock()
|
||||
mock_client.comment.return_value = "https://www.reddit.com/r/flipping/comments/abc123/_/xyz789/"
|
||||
|
|
|
|||
Loading…
Reference in a new issue