Test that a proxy error page for one repo doesn't crash the run
This commit is contained in:
1 parent
bfcac9b9ee
commit
1188b72263
2 files changed
+21
-2
No files matched your search
+9
-2
@@ -15,10 +15,17 @@ import language_stats
|
||||
|
||||
def make_response(status, payload):
|
||||
"""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.status_code = status
|
||||
resp._content = json.dumps(payload).encode("utf-8")
|
||||
if isinstance(payload, bytes):
|
||||
resp._content = payload
|
||||
else:
|
||||
resp._content = json.dumps(payload).encode("utf-8")
|
||||
return resp
|
||||
|
||||
|
||||
|
||||
@@ -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(
|
||||
gitea, capsys
|
||||
):
|
||||
|
||||
Reference in new issue
Block a user