From 0d3434522e523a86a1241c8029be4ff62becfe3f Mon Sep 17 00:00:00 2001 From: KaseyCantu Date: Tue, 8 Jun 2021 14:03:34 -0500 Subject: [PATCH 1/4] DX-1051 - Empty address lines - This test is already written from DX-1033. This error is only thrown when instantiating an Address object with a missing street. https://auctane.atlassian.net/browse/DX-1051 --- tests/models/address/test_address.py | 26 ++------------------------ tests/util/test_helpers.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/models/address/test_address.py b/tests/models/address/test_address.py index 3d88df4..cd4e09f 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: 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( From 29b3a6b3675f4b8b2d11a89de4c3b1cbe41c660f Mon Sep 17 00:00:00 2001 From: KaseyCantu Date: Tue, 8 Jun 2021 14:11:08 -0500 Subject: [PATCH 2/4] DX-1052 - Empty address lines - This test is already written from DX-1033. This error is only thrown when instantiating an Address object with a missing street. https://auctane.atlassian.net/browse/DX-1052 --- tests/models/address/test_address.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/models/address/test_address.py b/tests/models/address/test_address.py index cd4e09f..2c0856b 100644 --- a/tests/models/address/test_address.py +++ b/tests/models/address/test_address.py @@ -32,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: From b676f65ae36cb7bbae749a2e829c05b1d9e3420d Mon Sep 17 00:00:00 2001 From: KaseyCantu Date: Tue, 8 Jun 2021 14:16:27 -0500 Subject: [PATCH 3/4] DX-1053 & DX-1054 - Covers acceptance criteria for both by making assertions for both tickets in one test. https://auctane.atlassian.net/browse/DX-1053 & https://auctane.atlassian.net/browse/DX-1053 --- tests/services/test_normalize_address.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/services/test_normalize_address.py b/tests/services/test_normalize_address.py index 1ed3f16..77c4d6d 100644 --- a/tests/services/test_normalize_address.py +++ b/tests/services/test_normalize_address.py @@ -1,10 +1,11 @@ """Test the normalize address method of the ShipEngine SDK.""" import re -from shipengine_sdk.errors import ShipEngineError +from shipengine_sdk.errors import 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, @@ -161,3 +162,17 @@ 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 + ) From c6ea5df1178431002012f46f5098004759a93e49 Mon Sep 17 00:00:00 2001 From: KaseyCantu Date: Tue, 8 Jun 2021 14:19:15 -0500 Subject: [PATCH 4/4] DX-1056 - server side error. https://auctane.atlassian.net/browse/DX-1056 --- tests/services/test_normalize_address.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/services/test_normalize_address.py b/tests/services/test_normalize_address.py index 77c4d6d..b9738e8 100644 --- a/tests/services/test_normalize_address.py +++ b/tests/services/test_normalize_address.py @@ -1,7 +1,7 @@ """Test the normalize address method of the ShipEngine SDK.""" import re -from shipengine_sdk.errors import ShipEngineError, ValidationError +from shipengine_sdk.errors import ClientSystemError, ShipEngineError, ValidationError from shipengine_sdk.models import Address, ErrorCode, ErrorSource, ErrorType from ..util.test_helpers import ( @@ -9,6 +9,7 @@ address_with_errors, address_with_single_error, address_with_warnings, + get_server_side_error, multi_line_address, non_latin_address, normalize_an_address, @@ -176,3 +177,14 @@ def test_normalize_missing_city_state_and_postal_code(self) -> None: 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