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
28 changes: 3 additions & 25 deletions tests/models/address/test_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
29 changes: 28 additions & 1 deletion tests/services/test_normalize_address.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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
22 changes: 22 additions & 0 deletions tests/util/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down