Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions tests/cassettes/test_error_alternative_format.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion tests/test_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_address_create_verify(incorrect_address, test_client):
"""
Test creating an address with the `verify` param.
"""
# Creating normally (without specifying "verify") will make the address, perform no verifications
# Creating normally (without specifying "verify") will make the address and perform no verifications
address = test_client.address.create(**incorrect_address)

assert isinstance(address, Address)
Expand All @@ -33,7 +33,23 @@ def test_address_create_verify(incorrect_address, test_client):
address = test_client.address.create(**incorrect_address)

assert isinstance(address, Address)

# Delivery verification assertions
assert address.verifications.delivery.success is False
# TODO: details is not deserializing correctly, related to the larger "double EasyPostObject" wrapping issue
# assert address.verifications.delivery.details == {}
assert address.verifications.delivery.errors[0].code == "E.ADDRESS.NOT_FOUND"
assert address.verifications.delivery.errors[0].field == "address"
assert address.verifications.delivery.errors[0].suggestion is None
assert address.verifications.delivery.errors[0].message == "Address not found"

# Zip4 verification assertions
assert address.verifications.zip4.success is False
assert address.verifications.zip4.details is None
assert address.verifications.zip4.errors[0].code == "E.ADDRESS.NOT_FOUND"
assert address.verifications.zip4.errors[0].field == "address"
assert address.verifications.zip4.errors[0].suggestion is None
assert address.verifications.zip4.errors[0].message == "Address not found"


@pytest.mark.vcr()
Expand Down
28 changes: 27 additions & 1 deletion tests/test_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,28 @@ def test_error(test_client):
)


@pytest.mark.vcr()
def test_error_alternative_format(test_client, basic_claim):
"""Tests that we assign properties of an error correctly when returned via the alternative format.

NOTE: Claims (among other things) uses the alternative errors format.
"""
try:
claim_data = basic_claim
claim_data["tracking_code"] = "123" # Intentionally pass a bad tracking code

test_client.claim.create(**claim_data)
except ApiError as error:
assert error.http_status == 404
assert error.code == "NOT_FOUND"
assert error.message == "The requested resource could not be found."
assert error.errors[0] == "No eligible insurance found with provided tracking code."
assert (
error.http_body
== '{"error": {"code": "NOT_FOUND", "errors": ["No eligible insurance found with provided tracking code."], "message": "The requested resource could not be found."}}' # noqa
)


def test_error_no_json():
"""Tests if we don't have valid JSON that we don't set the JSON body of an error."""
error = ApiError(message="", http_body="bad json")
Expand Down Expand Up @@ -55,7 +77,11 @@ def test_error_bad_format_message():
message_data = {
"errors": ["Bad format 1", "Bad format 2"],
"bad_data": [
{"first_message": "Bad format 3", "second_message": "Bad format 4", "thrid_message": "Bad format 5"}
{
"first_message": "Bad format 3",
"second_message": "Bad format 4",
"thrid_message": "Bad format 5",
}
],
}

Expand Down