From 10489a1acf3204029eb811eb1608d32b6b99cba1 Mon Sep 17 00:00:00 2001 From: Nick Dokos Date: Wed, 12 Apr 2023 13:01:24 -0400 Subject: [PATCH] Address review comments --- .../test/unit/agent/task/test_results_push.py | 64 ++++--------------- 1 file changed, 12 insertions(+), 52 deletions(-) diff --git a/lib/pbench/test/unit/agent/task/test_results_push.py b/lib/pbench/test/unit/agent/task/test_results_push.py index 3c4b22d261..23cdb72498 100644 --- a/lib/pbench/test/unit/agent/task/test_results_push.py +++ b/lib/pbench/test/unit/agent/task/test_results_push.py @@ -26,7 +26,7 @@ class TestResultsPush: @staticmethod def add_http_mock_response( status_code: HTTPStatus = HTTPStatus.CREATED, - message: Optional[Union[str, Dict]] = None, + message: Optional[Union[str, Dict, Exception]] = None, ): parms = {} if status_code: @@ -194,60 +194,20 @@ def test_access_error(monkeypatch): @pytest.mark.parametrize( "status_code,message,exit_code", ( - ( - HTTPStatus.CREATED, - None, - 0, - ), - ( - HTTPStatus.OK, - {"message": "Dup"}, - 0, - ), - ( - HTTPStatus.OK, - "Dup", - 0, - ), - ( - HTTPStatus.NO_CONTENT, - {"message": "No content"}, - 0, - ), - ( - HTTPStatus.NO_CONTENT, - "No content", - 0, - ), + (HTTPStatus.CREATED, None, 0), + (HTTPStatus.OK, {"message": "Dup"}, 0), + (HTTPStatus.OK, "Dup", 0), + (HTTPStatus.NO_CONTENT, {"message": "No content"}, 0), + (HTTPStatus.NO_CONTENT, "No content", 0), ( HTTPStatus.REQUEST_ENTITY_TOO_LARGE, {"message": "Request Entity Too Large"}, 1, ), - ( - HTTPStatus.REQUEST_ENTITY_TOO_LARGE, - "Request Entity Too Large", - 1, - ), - ( - HTTPStatus.NOT_FOUND, - {"message": "Not Found"}, - 1, - ), - ( - HTTPStatus.NOT_FOUND, - "Not Found", - 1, - ), - ( - 0, - requests.exceptions.ConnectionError( - ": " - "Failed to establish a new connection: [Errno 8] " - "nodename nor servname provided, or not known" - ), - 1, - ), + (HTTPStatus.REQUEST_ENTITY_TOO_LARGE, "Request Entity Too Large", 1), + (HTTPStatus.NOT_FOUND, {"message": "Not Found"}, 1), + (HTTPStatus.NOT_FOUND, "Not Found", 1), + (None, requests.exceptions.ConnectionError("Oops"), 1), ), ) def test_push_status(status_code, message, exit_code): @@ -282,6 +242,6 @@ def test_push_status(status_code, message, exit_code): else: assert False, "message must be dict, string, Exception or None" - if status_code >= 400: + if status_code and status_code >= 400: err_msg = f"HTTP Error status: {status_code.value}, message: {err_msg}" - assert err_msg in result.stderr.strip() + assert err_msg in result.stderr