Model/backend/condition/tests/mapping/test_peabody_mapper.py

206 lines
6.9 KiB
Python

from datetime import datetime
from typing import List
from backend.condition.domain.aspect_type import AspectType
from backend.condition.domain.element_type import ElementType
from backend.condition.domain.mapping.peabody.peabody_mapper import PeabodyMapper
from backend.condition.parsing.records.peabody.peabody_asset_condition import (
PeabodyAssetCondition,
)
from backend.condition.parsing.records.peabody.peabody_property import PeabodyProperty
from backend.condition.domain.element import Element
def test_peabody_mapper_maps_property():
# arrange
peabody_property = PeabodyProperty(
uprn=1,
assets=[
PeabodyAssetCondition(
lo_reference="1000RAND0000",
full_address="FLAT 1 RANDOM SQUARE FAKE STREET LONDON E1 1EE",
location_type_code=1,
parent_lo_reference="RAND1000",
element_code=130,
element="WINDOWS",
sub_element_code=1,
sub_element="Windows",
material_code=1,
material_or_answer="UPVC Double Glazed",
renewal_quantity=8,
renewal_year=2036,
renewal_cost=4800,
cloned="N",
lo_type_code=1,
condition_survey_date=datetime(2024, 2, 15, 12, 47, 0),
),
PeabodyAssetCondition(
lo_reference="1000RAND0000",
full_address="FLAT 1 RANDOM SQUARE FAKE STREET LONDON E1 1EE",
location_type_code=1,
parent_lo_reference="RAND1000",
element_code=100,
element="GENERAL",
sub_element_code=15,
sub_element="External Decoration",
material_code=2,
material_or_answer="Normal",
renewal_quantity=1,
renewal_year=2029,
renewal_cost=1500,
cloned="N",
lo_type_code=1,
condition_survey_date=datetime(2024, 2, 15, 12, 47, 0),
),
],
)
mapper = PeabodyMapper()
expected_assets: List[Element] = [
Element(
uprn=1,
element=ElementType.EXTERNAL_WINDOWS,
aspect_type=AspectType.MATERIAL,
value="UPVC Double Glazed",
quantity=8,
install_date=None,
renewal_year=2036,
element_instance=None,
source_system=None,
comments=None,
),
Element(
uprn=1,
element=ElementType.EXTERNAL_DECORATION,
aspect_type=AspectType.CONDITION,
value="Normal",
quantity=1,
install_date=None,
renewal_year=2029,
element_instance=None,
source_system=None,
comments=None,
),
]
# act
actual_assets = mapper.map_asset_conditions_for_property(peabody_property)
# assert
assert len(actual_assets) == len(expected_assets)
for i, (actual, expected) in enumerate(zip(actual_assets, expected_assets)):
assert actual == expected, f"Mismatch at index {i}"
def test_wall_primary_and_secondary_wall_finish_map_correctly():
# arrange
peabody_property = PeabodyProperty(
uprn=1,
assets=[
PeabodyAssetCondition(
lo_reference="1000RAND0000",
full_address="FLAT 1 RANDOM SQUARE FAKE STREET LONDON E1 1EE",
location_type_code=1,
parent_lo_reference="RAND1000",
element_code=53,
element="External",
sub_element_code=23,
sub_element="Primary Wall Finish",
material_code=4,
material_or_answer="Pointed",
renewal_quantity=65,
renewal_year=2045,
renewal_cost=3835,
cloned="N",
lo_type_code=1,
condition_survey_date=datetime(2024, 2, 15, 12, 47, 0),
),
PeabodyAssetCondition(
lo_reference="1000RAND0000",
full_address="FLAT 1 RANDOM SQUARE FAKE STREET LONDON E1 1EE",
location_type_code=1,
parent_lo_reference="RAND1000",
element_code=120,
element="WALLS",
sub_element_code=2,
sub_element="Wall Finish",
material_code=1,
material_or_answer="Pointing",
renewal_quantity=1,
renewal_year=2069,
renewal_cost=2450,
cloned="N",
lo_type_code=1,
condition_survey_date=datetime(2014, 2, 15, 12, 47, 0),
),
PeabodyAssetCondition(
lo_reference="1000RAND0000",
full_address="FLAT 1 RANDOM SQUARE FAKE STREET LONDON E1 1EE",
location_type_code=1,
parent_lo_reference="RAND1000",
element_code=53,
element="External",
sub_element_code=30,
sub_element="Secondary Wall Finish",
material_code=8,
material_or_answer="Tile Hung",
renewal_quantity=8,
renewal_year=2049,
renewal_cost=472,
cloned="N",
lo_type_code=1,
condition_survey_date=datetime(2014, 2, 15, 12, 47, 0),
),
],
)
mapper = PeabodyMapper()
expected_assets: List[Element] = [
Element(
uprn=1,
element=ElementType.EXTERNAL_WALLS,
aspect_type=AspectType.FINISH,
value="Pointed",
element_instance=1,
aspect_instance=1,
quantity=65,
install_date=None,
renewal_year=2045,
source_system=None,
comments=None,
),
Element(
uprn=1,
element=ElementType.EXTERNAL_WALLS,
aspect_type=AspectType.FINISH,
value="Pointing",
element_instance=1,
aspect_instance=1,
quantity=1,
install_date=None,
renewal_year=2069,
source_system=None,
comments=None,
),
Element(
uprn=1,
element=ElementType.EXTERNAL_WALLS,
aspect_type=AspectType.FINISH,
value="Tile Hung",
element_instance=1,
aspect_instance=2,
quantity=8,
install_date=None,
renewal_year=2049,
source_system=None,
comments=None,
),
]
# act
actual_assets = mapper.map_asset_conditions_for_property(peabody_property)
# assert
assert len(actual_assets) == len(expected_assets)
for i, (actual, expected) in enumerate(zip(actual_assets, expected_assets)):
assert actual == expected, f"Mismatch at index {i}"