Skip to content
Snippets Groups Projects
Commit a6cb022c authored by Florian Bruhin's avatar Florian Bruhin
Browse files

tests: Add golden tests for error conditions

parent 46ee962a
No related branches found
No related tags found
No related merge requests found
input:
http_status: 500
exit_code: 1
output: |
Last change: 0 seconds ago
Server error '500 Internal Server Error' for url
'http://localhost:5000/testbook'
For more information check: https://httpstatuses.com/500
input:
error: SomethingWentWrongError
msg: Alles kaputt
http_status: 400
exit_code: 1
output: |
Last change: 0 seconds ago
Client error '400 Bad Request' for url 'http://localhost:5000/testbook'
For more information check: https://httpstatuses.com/400
Error: SomethingWentWrongError
Message: Alles kaputt
💥 Submission failed! (2022-10-12 13:37:00)
......@@ -140,12 +140,20 @@ def test_golden(
time_machine: TimeMachineFixture,
nb_arg: str,
) -> None:
httpx_mock.add_response(json=golden["input"]) # FIXME add URL?
httpx_mock.add_response( # FIXME add URL?
method="POST",
json=golden["input"],
status_code=golden.get("http_status", 200),
)
delay = golden.get("delay", 0)
time_machine.move_to(FROZEN_TIME + datetime.timedelta(seconds=delay))
result = runner.invoke(cli.app, [nb_arg])
print(result.stdout)
assert result.exit_code == 0
# FIXME pytest-golden should probably support a fallback for .get, or at least
# __contains__
exit_code = 0 if golden.get("exit_code") is None else golden.out["exit_code"]
assert result.exit_code == exit_code
assert result.stdout == golden.out["output"]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment