Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
Use the single call method that Webb suggested for the mock response.
I left out the BufferedReader case because I don't understand it.
I left in the Exception case although I don't understand it either,
but I'm guessing it can help to unify some of the "abnormal" test cases
with the "normal" one - but it is not used in this incarnation.
  • Loading branch information
ndokos committed Apr 8, 2023
1 parent 69c36e5 commit 9ec1294
Showing 1 changed file with 13 additions and 25 deletions.
38 changes: 13 additions & 25 deletions lib/pbench/test/unit/agent/task/test_results_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,20 @@ class TestResultsPush:
def add_http_mock_response(
status_code: HTTPStatus = None, message: Optional[Union[str, Dict]] = None
):
parms = {}
if status_code:
if message is None:
responses.add(
responses.PUT,
f"{TestResultsPush.URL}/upload/{os.path.basename(tarball)}",
status=status_code,
)
elif isinstance(message, dict):
responses.add(
responses.PUT,
f"{TestResultsPush.URL}/upload/{os.path.basename(tarball)}",
status=status_code,
json=message,
)
else:
responses.add(
responses.PUT,
f"{TestResultsPush.URL}/upload/{os.path.basename(tarball)}",
status=status_code,
body=message,
)
else:
responses.add(
responses.PUT,
f"{TestResultsPush.URL}/upload/{os.path.basename(tarball)}",
)
parms["status"] = status_code

if isinstance(message, dict):
parms["json"] = message
elif isinstance(message, (str, Exception)):
parms["body"] = message

responses.add(
responses.PUT,
f"{TestResultsPush.URL}/upload/{os.path.basename(tarball)}",
**parms,
)

@staticmethod
def add_connectionerr_mock_response():
Expand Down

0 comments on commit 9ec1294

Please sign in to comment.