mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
96 lines
3.1 KiB
Python
96 lines
3.1 KiB
Python
import dataclasses
|
|
|
|
import pytest
|
|
|
|
from domain.addresses.unstandardised_address import UnstandardisedAddress
|
|
from domain.postcode import Postcode
|
|
|
|
|
|
def test_unstandardised_address_holds_postcode_value_object() -> None:
|
|
# act
|
|
addr = UnstandardisedAddress(address="1 The Street", postcode=Postcode("sw1a 1aa"))
|
|
# assert
|
|
assert addr.postcode == Postcode("SW1A1AA")
|
|
|
|
|
|
def test_unstandardised_address_preserves_unstandardised_address_verbatim() -> None:
|
|
# The free-text unstandardised_address string is intentionally NOT normalised --
|
|
# only the postcode is canonicalised, and that happens inside Postcode.
|
|
# act
|
|
addr = UnstandardisedAddress(address=" 1 The Street ", postcode=Postcode("SW1A1AA"))
|
|
# assert
|
|
assert addr.address == " 1 The Street "
|
|
|
|
|
|
def test_unstandardised_address_internal_reference_defaults_to_none() -> None:
|
|
# act
|
|
addr = UnstandardisedAddress(address="1 The Street", postcode=Postcode("SW1A1AA"))
|
|
# assert
|
|
assert addr.org_reference is None
|
|
|
|
|
|
def test_unstandardised_address_internal_reference_accepted() -> None:
|
|
# act
|
|
addr = UnstandardisedAddress(
|
|
address="1 The Street",
|
|
postcode=Postcode("SW1A1AA"),
|
|
org_reference="cust-42",
|
|
)
|
|
# assert
|
|
assert addr.org_reference == "cust-42"
|
|
|
|
|
|
def test_unstandardised_address_is_frozen() -> None:
|
|
# arrange
|
|
addr = UnstandardisedAddress(address="1 The Street", postcode=Postcode("SW1A1AA"))
|
|
# act / assert
|
|
with pytest.raises(dataclasses.FrozenInstanceError):
|
|
addr.postcode = Postcode("OTHER") # type: ignore[misc]
|
|
|
|
|
|
def test_unstandardised_address_equality_uses_canonical_postcode() -> None:
|
|
# Postcode sanitises eagerly, so addresses built from different surface
|
|
# forms of the same postcode compare equal.
|
|
# arrange
|
|
a = UnstandardisedAddress(address="1 The Street", postcode=Postcode("sw1a 1aa"))
|
|
b = UnstandardisedAddress(address="1 The Street", postcode=Postcode("SW1A1AA"))
|
|
# act / assert
|
|
assert a == b
|
|
|
|
|
|
def test_unstandardised_address_source_row_defaults_to_empty_dict() -> None:
|
|
# act
|
|
addr = UnstandardisedAddress(address="1 The Street", postcode=Postcode("SW1A1AA"))
|
|
# assert
|
|
assert addr.additional_info == {}
|
|
|
|
|
|
def test_unstandardised_address_carries_source_row() -> None:
|
|
# arrange
|
|
row = {"Address 1": "1 The Street", "postcode": "SW1A 1AA", "SAP Score": "72"}
|
|
# act
|
|
addr = UnstandardisedAddress(
|
|
address="1 The Street",
|
|
postcode=Postcode("SW1A 1AA"),
|
|
additional_info=row,
|
|
)
|
|
# assert
|
|
assert addr.additional_info == row
|
|
|
|
|
|
def test_unstandardised_address_equality_ignores_source_row() -> None:
|
|
# source_row is excluded from equality (and hashing): identity stays
|
|
# defined by the parsed fields.
|
|
# arrange
|
|
a = UnstandardisedAddress(
|
|
address="1 The Street",
|
|
postcode=Postcode("SW1A1AA"),
|
|
additional_info={"x": "1"},
|
|
)
|
|
b = UnstandardisedAddress(
|
|
address="1 The Street",
|
|
postcode=Postcode("SW1A1AA"),
|
|
additional_info={"y": "2"},
|
|
)
|
|
# act / assert
|
|
assert a == b
|