""" Reply contexts are fetched for real (v2.10.2) v2.7.0 made fetch_source return (content, content_type, final_url) but fetch_reply_context still unpacked two values, so every new reply, like and repost stored fetch_status='error'. Other tests stub fetch_reply_context out; this one runs it through the mocked network. """ import sqlite3 import httpx from starpunk.reply_context import fetch_reply_context PUBLIC = [(2, 1, 6, "", ("93.184.216.34", 0))] PAGE = """Their site

A post worth replying to

Ada Example

Some thoughts.

""" def test_reply_context_is_fetched_and_stored(app, monkeypatch): def site(request): if request.url.path == "/old": return httpx.Response(301, headers={"Location": "https://their.example/posts/1"}) return httpx.Response(200, html=PAGE) monkeypatch.setattr("starpunk.webmention_ssrf.socket.getaddrinfo", lambda *a, **k: PUBLIC) monkeypatch.setattr("starpunk.webmention_ssrf.TRANSPORT", httpx.MockTransport(site)) with app.app_context(): context = fetch_reply_context(app.config["DATABASE_PATH"], "https://their.example/old", app.config["SITE_URL"]) assert context["fetch_status"] == "fetched", context assert context["title"] == "A post worth replying to" assert context["author_name"] == "Ada Example" # Relative links resolve against the URL after the redirect assert context["author_url"] == "https://their.example/about" assert "Some thoughts" in (context["content_snippet"] or "") row = sqlite3.connect(app.config["DATABASE_PATH"]).execute( "SELECT fetch_status FROM reply_contexts WHERE url = ?", ("https://their.example/old",) ).fetchone() assert row == ("fetched",)