diff --git a/tests/models/address/test_address.py b/tests/models/address/test_address.py index 3d88df4..2c0856b 100644 --- a/tests/models/address/test_address.py +++ b/tests/models/address/test_address.py @@ -3,29 +3,7 @@ from shipengine_sdk.errors import ValidationError from shipengine_sdk.models import ErrorCode, ErrorSource, ErrorType -from shipengine_sdk.models.address import Address - - -def empty_address_lines() -> Address: - """Returns an invalid address with empty street list.""" - return Address( - street=list(), - city_locality="Boston", - state_province="MA", - postal_code="02215", - country_code="US", - ) - - -def address_with_too_many_lines() -> Address: - """Return an address with too many address lines in the street list.""" - return Address( - street=["4 Jersey St", "ste 200", "1st Floor", "Room B"], - city_locality="Boston", - state_province="MA", - postal_code="02215", - country_code="US", - ) +from tests.util.test_helpers import address_with_too_many_lines, empty_address_lines def address_line_assertions(err: ValidationError, variant: str) -> None: @@ -45,7 +23,7 @@ def address_line_assertions(err: ValidationError, variant: str) -> None: class TestAddress: def test_no_address_lines(self): - """DX-1033 - Too many address lines in the street list.""" + """DX-1033/DX-1051 - No address lines in the street list.""" try: empty_address_lines() except ValidationError as err: @@ -54,7 +32,7 @@ def test_no_address_lines(self): empty_address_lines() def test_address_with_too_many_lines(self): - """DX-1034 - Too many address lines.""" + """DX-1034/DX-1052 - Too many address lines.""" try: address_with_too_many_lines() except ValidationError as err: diff --git a/tests/services/test_normalize_address.py b/tests/services/test_normalize_address.py index 1ed3f16..b9738e8 100644 --- a/tests/services/test_normalize_address.py +++ b/tests/services/test_normalize_address.py @@ -1,13 +1,15 @@ """Test the normalize address method of the ShipEngine SDK.""" import re -from shipengine_sdk.errors import ShipEngineError +from shipengine_sdk.errors import ClientSystemError, ShipEngineError, ValidationError from shipengine_sdk.models import Address, ErrorCode, ErrorSource, ErrorType from ..util.test_helpers import ( + address_missing_required_fields, address_with_errors, address_with_single_error, address_with_warnings, + get_server_side_error, multi_line_address, non_latin_address, normalize_an_address, @@ -161,3 +163,28 @@ def test_normalize_with_multiple_errors(self) -> None: err.message == "Invalid address.\nInvalid City, State, or Zip\nInsufficient or Incorrect Address Data" ) + + def test_normalize_missing_city_state_and_postal_code(self) -> None: + """DX-1053 & DX-1054 - Missing city, state, and postal code.""" + try: + address_missing_required_fields() + except ValidationError as err: + assert err.request_id is None + assert err.source is ErrorSource.SHIPENGINE.value + assert err.error_type is ErrorType.VALIDATION.value + assert err.error_code is ErrorCode.FIELD_VALUE_REQUIRED.value + assert ( + err.message + == "Invalid address. Either the postal code or the city/locality and state/province must be specified." # noqa + ) + + def test_normalize_server_side_error(self) -> None: + """DX-1056 - Server-side error.""" + try: + get_server_side_error() + except ClientSystemError as err: + assert err.request_id is not None + assert err.request_id.startswith("req_") is True + assert err.source is ErrorSource.SHIPENGINE.value + assert err.error_type is ErrorType.SYSTEM.value + assert err.error_code is ErrorCode.UNSPECIFIED.value diff --git a/tests/util/test_helpers.py b/tests/util/test_helpers.py index f74d07e..79866cf 100644 --- a/tests/util/test_helpers.py +++ b/tests/util/test_helpers.py @@ -92,6 +92,28 @@ def valid_canadian_address() -> Address: ) +def empty_address_lines() -> Address: + """Returns an invalid address with empty street list.""" + return Address( + street=list(), + city_locality="Boston", + state_province="MA", + postal_code="02215", + country_code="US", + ) + + +def address_with_too_many_lines() -> Address: + """Return an address with too many address lines in the street list.""" + return Address( + street=["4 Jersey St", "ste 200", "1st Floor", "Room B"], + city_locality="Boston", + state_province="MA", + postal_code="02215", + country_code="US", + ) + + def multi_line_address() -> Address: """Returns a valid multiline address.""" return Address(