Test that a proxy error page for one repo doesn't crash the run

This commit is contained in:
Mark Eaton committed 2026-11-11 19:47:53 -05:00
1 parent bfcac9b9ee
commit 1188b72263
2 files changed
+20 -1

No files matched your search

+8 -1
View File
@@ -15,9 +15,16 @@ import language_stats
def make_response(status, payload): def make_response(status, payload):
"""Build a real requests.Response so .ok, .json() and .raise_for_status() """Build a real requests.Response so .ok, .json() and .raise_for_status()
behave exactly as they do against a live server.""" behave exactly as they do against a live server.
A bytes payload is sent as-is (e.g. an HTML error page from a proxy);
anything else is sent as JSON.
"""
resp = requests.Response() resp = requests.Response()
resp.status_code = status resp.status_code = status
if isinstance(payload, bytes):
resp._content = payload
else:
resp._content = json.dumps(payload).encode("utf-8") resp._content = json.dumps(payload).encode("utf-8")
return resp return resp
+12
View File
@@ -86,6 +86,18 @@ def test_repo_whose_languages_are_forbidden_is_skipped_with_a_warning(gitea, cap
) )
def test_repo_whose_languages_return_a_proxy_error_page_is_skipped(gitea, capsys):
# A reverse proxy in front of Gitea answers a slow request with an HTML
# page, not JSON; trying to parse it would crash the whole run.
gitea.add("GET", WEBSITE_LANGS, b"<html><h1>504 Gateway Time-out</h1></html>", 504)
gitea.add("GET", SCRIPTS_LANGS, {"Python": 2000})
repos = [{"name": "website"}, {"name": "scripts"}]
assert aggregate_language_bytes(get_session(), repos) == {"Python": 2000}
assert (
"Warning: Could not fetch languages for website: 504" in capsys.readouterr().err
)
def test_error_message_inside_a_success_response_is_skipped_with_a_warning( def test_error_message_inside_a_success_response_is_skipped_with_a_warning(
gitea, capsys gitea, capsys
): ):