Skip to content

Commit 12492ab

Browse files
committed
test: alternative error format
1 parent 025260c commit 12492ab

File tree

2 files changed

+100
-1
lines changed

2 files changed

+100
-1
lines changed

tests/cassettes/test_error_alternative_format.yaml

Lines changed: 73 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/test_error.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,28 @@ def test_error(test_client):
1919
)
2020

2121

22+
@pytest.mark.vcr()
23+
def test_error_alternative_format(test_client, basic_claim, full_shipment):
24+
"""Tests that we assign properties of an error correctly when returned via the alternative format.
25+
26+
NOTE: Claims (among other things) uses the alternative errors format.
27+
"""
28+
try:
29+
claim_data = basic_claim
30+
claim_data["tracking_code"] = "123" # Intentionally pass a bad tracking code
31+
32+
test_client.claim.create(**claim_data)
33+
except ApiError as error:
34+
assert error.http_status == 404
35+
assert error.code == "NOT_FOUND"
36+
assert error.message == "The requested resource could not be found."
37+
assert error.errors[0] == "No eligible insurance found with provided tracking code."
38+
assert (
39+
error.http_body
40+
== '{"error": {"code": "NOT_FOUND", "errors": ["No eligible insurance found with provided tracking code."], "message": "The requested resource could not be found."}}' # noqa
41+
)
42+
43+
2244
def test_error_no_json():
2345
"""Tests if we don't have valid JSON that we don't set the JSON body of an error."""
2446
error = ApiError(message="", http_body="bad json")
@@ -55,7 +77,11 @@ def test_error_bad_format_message():
5577
message_data = {
5678
"errors": ["Bad format 1", "Bad format 2"],
5779
"bad_data": [
58-
{"first_message": "Bad format 3", "second_message": "Bad format 4", "thrid_message": "Bad format 5"}
80+
{
81+
"first_message": "Bad format 3",
82+
"second_message": "Bad format 4",
83+
"thrid_message": "Bad format 5",
84+
}
5985
],
6086
}
6187

0 commit comments

Comments
 (0)