Files
shelfmark/tests/prowlarr/test_api_proxy.py
T
c43da4537d fix(network): apply HTTP proxy to Open Library and Prowlarr requests (#1526)
Fixes #1524

Open Library metadata searches and Prowlarr API calls used
`get_ssl_verify` but never `get_proxies`, so the HTTP proxy set in
Settings → Network was not applied to their HTTPS requests. Both now
pass the configured proxies. Relying on `requests`' `trust_env` with
only `HTTP_PROXY` set leaves the same gap for `https://` destinations.

Verification (Linux, `uv run --frozen pytest`):
- New tests `tests/metadata/test_openlibrary_proxy.py` and
`tests/prowlarr/test_api_proxy.py`: 4 passed. With the source change
reverted they fail (2 failed, 2 errors).
- `tests/metadata` + `tests/prowlarr`: 949 passed, 42 skipped.
- The full suite in my environment showed 61 failures and 26 errors
outside these areas. I did not compare them against `main`, so I'm not
claiming the full suite is green here; CI will show it.
- `ruff check` and `ruff format --check` on the changed files pass.

Prepared with AI assistance; reviewed and tested by me before
submitting.

Co-authored-by: dbdefault <246079841+dbdefault@users.noreply.github.com>
Co-authored-by: CaliBrain <calibrain@l4n.xyz>
2026-10-22 02:47:43 -04:00

68 lines
2.1 KiB
Python

"""Prowlarr API client must honor Network HTTP proxy settings (#1524)."""
import pytest
import requests
import shelfmark.release_sources.prowlarr.api as prowlarr_api
from shelfmark.release_sources.prowlarr.api import ProwlarrClient
_TORZNAB_EMPTY = """<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"><channel></channel></rss>"""
class _Response:
def __init__(self, text="", status_code=200, reason="OK", payload=None):
self.text = text
self.status_code = status_code
self.reason = reason
self.ok = status_code < 400
self._payload = payload if payload is not None else {}
def raise_for_status(self):
if not self.ok:
raise requests.exceptions.HTTPError(f"{self.status_code} {self.reason}", response=self)
def json(self):
return self._payload
@pytest.fixture
def http_proxy(monkeypatch):
expected = {
"http": "http://10.0.80.3:8118",
"https": "http://10.0.80.3:8118",
}
monkeypatch.setattr(prowlarr_api, "get_proxies", lambda _url: expected)
monkeypatch.setattr(prowlarr_api, "get_ssl_verify", lambda _url: True)
return expected
def test_prowlarr_json_request_passes_configured_http_proxy(monkeypatch, http_proxy):
client = ProwlarrClient("http://prowlarr:9696", "apikey")
captured: dict[str, object] = {}
def fake_request(**kwargs):
captured.update(kwargs)
return _Response(payload={"version": "1.0.0"})
monkeypatch.setattr(client._session, "request", fake_request)
ok, _message = client.test_connection()
assert ok is True
assert captured.get("proxies") == http_proxy
def test_prowlarr_torznab_search_passes_configured_http_proxy(monkeypatch, http_proxy):
client = ProwlarrClient("http://prowlarr:9696", "apikey", indexer_timeout=90)
captured: dict[str, object] = {}
def fake_get(**kwargs):
captured.update(kwargs)
return _Response(_TORZNAB_EMPTY)
monkeypatch.setattr(client._session, "get", fake_get)
assert client.torznab_search(indexer_id=1, query="Dune") == []
assert captured.get("proxies") == http_proxy