Skip to content

Commit

Permalink
Always add a reason to erroneous HTTP responses
Browse files Browse the repository at this point in the history
Otherwise, `aiohttp` cannot parse the response with the trailing space in the status — `"HTTP/1.1 555 "` — since `"555 ".split()` returns only one element, and the whole string `"555 "` is used as the status with expectations of being a 3-digit numeric.

Signed-off-by: Sergey Vasilyev <nolar@nolar.info>
  • Loading branch information
nolar committed Oct 8, 2023
1 parent 538df59 commit ea46f6f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions tests/k8s/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async def test_no_events_for_events(
async def test_api_errors_logged_but_suppressed(
resp_mocker, aresponses, hostname, settings, logger, assert_logs):

post_mock = resp_mocker(return_value=aresponses.Response(status=555))
post_mock = resp_mocker(return_value=aresponses.Response(status=555, reason='oops'))
aresponses.add(hostname, '/api/v1/namespaces/ns/events', 'post', post_mock)

obj = {'apiVersion': 'group/version',
Expand Down Expand Up @@ -161,7 +161,7 @@ async def test_message_is_cut_to_max_length(
async def test_headers_are_not_leaked(
resp_mocker, aresponses, hostname, settings, logger, assert_logs, status):

post_mock = resp_mocker(return_value=aresponses.Response(status=status))
post_mock = resp_mocker(return_value=aresponses.Response(status=status, reason='oops'))
aresponses.add(hostname, '/api/v1/namespaces/ns/events', 'post', post_mock)

obj = {'apiVersion': 'group/version',
Expand Down
2 changes: 1 addition & 1 deletion tests/k8s/test_watching_infinitely.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def test_exception_escalates(

async def test_infinite_watch_never_exits_normally(
settings, resource, stream, namespace, aresponses):
error = aresponses.Response(status=555)
error = aresponses.Response(status=555, reason='oops')
stream.feed(
STREAM_WITH_ERROR_410GONE, # watching restarted
STREAM_WITH_UNKNOWN_EVENT, # event ignored
Expand Down

0 comments on commit ea46f6f

Please sign in to comment.