From d6112f3dc8f45aabd63f789f475c09929bafb56d Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Tue, 27 Jan 2026 15:20:13 +0000 Subject: [PATCH] =?UTF-8?q?Map=20lbwf=20data=20to=20new=20structure=20?= =?UTF-8?q?=F0=9F=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/mapping/peabody/peabody_mapper.py | 2 +- .../tests/mapping/test_lbwf_mapper.py | 247 ++++++++++-------- 2 files changed, 141 insertions(+), 108 deletions(-) diff --git a/backend/condition/domain/mapping/peabody/peabody_mapper.py b/backend/condition/domain/mapping/peabody/peabody_mapper.py index 41b2ff39..7749b024 100644 --- a/backend/condition/domain/mapping/peabody/peabody_mapper.py +++ b/backend/condition/domain/mapping/peabody/peabody_mapper.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, List, Optional, Tuple +from typing import Any, Dict, Optional, Tuple from datetime import date from backend.condition.domain.aspect_condition import AspectCondition diff --git a/backend/condition/tests/mapping/test_lbwf_mapper.py b/backend/condition/tests/mapping/test_lbwf_mapper.py index 8c92c029..064e06f7 100644 --- a/backend/condition/tests/mapping/test_lbwf_mapper.py +++ b/backend/condition/tests/mapping/test_lbwf_mapper.py @@ -3,9 +3,11 @@ from xml.dom.minidom import Element import pytest from datetime import date +from backend.condition.domain.aspect_condition import AspectCondition from backend.condition.domain.aspect_type import AspectType from backend.condition.domain.element_type import ElementType from backend.condition.domain.mapping.lbwf.lbwf_mapper import LbwfMapper +from backend.condition.domain.property_condition_survey import PropertyConditionSurvey from backend.condition.parsing.records.lbwf.lbwf_house import LbwfHouse from backend.condition.parsing.records.lbwf.lbwf_asset_condition import ( LbwfAssetCondition, @@ -219,115 +221,146 @@ def test_lbwf_mapper_maps_house(): survey_year = 2026 - expected_assets: List[Element] = [ - Element( - uprn=1, - element_type=ElementType.ACCESSIBLE_HOUSING_REGISTER, - aspect_type=AspectType.CATEGORY, - element_instance=None, - value="General Needs", - quantity=1, - renewal_year=None, - install_date=None, - comments=None, - ), - Element( - uprn=1, - element_type=ElementType.FLOOR_LEVEL_FRONT_DOOR, - aspect_type=AspectType.LOCATION, - element_instance=None, - value="Ground Floor", - quantity=1, - renewal_year=None, - install_date=None, - comments=None, - ), - Element( - uprn=1, - element_type=ElementType.ASBESTOS, - aspect_type=AspectType.PRESENCE, - element_instance=None, - value="Yes", - quantity=None, - renewal_year=None, - install_date=None, - comments="Source of Data = ACT", - ), - Element( - uprn=1, - element_type=ElementType.HHSRS_ASBESTOS_AND_MMF, - aspect_type=AspectType.RISK, - element_instance=None, - value="Category 4 - Typical Risk", - quantity=None, - renewal_year=None, - install_date=None, - comments="Source of Data = ACT", - ), - Element( - uprn=1, - element_type=ElementType.BATHROOM, - aspect_type=AspectType.LOCATION, - element_instance=None, - value="Bathroom on Entrance Level in Property", - quantity=1, - renewal_year=None, - install_date=None, - comments="Source of Data = Codeman", - ), - Element( - uprn=1, - element_type=ElementType.CENTRAL_HEATING, - aspect_type=AspectType.EXTENT, - element_instance=None, - value="No Central Heating in Property", - quantity=1, - renewal_year=None, - install_date=None, - comments="Source of Data = Codeman", - ), - Element( - uprn=1, - element_type=ElementType.HHSRS_FIRE, - aspect_type=AspectType.RISK, - element_instance=None, - value="Category 4 - Typical Risk", - quantity=1, - renewal_year=None, - install_date=None, - comments="Source of Data = Morgan Sindall", - ), - Element( - uprn=1, - element_type=ElementType.EXTERNAL_WALL, - aspect_type=AspectType.FINISH, - element_instance=1, - value="Render or Pebbledash in External Area", - quantity=1, - renewal_year=2052, - install_date=date(2009, 4, 1), - comments="Source of Data = Codeman", - ), - Element( - uprn=1, - element_type=ElementType.EXTERNAL_WALL, - aspect_type=AspectType.FINISH, - element_instance=2, - value="Smooth Render Wall Finish 2 in External Area", - quantity=1, - renewal_year=2052, - install_date=date(2009, 4, 1), - comments="Source of Data = Codeman", - ), - ] + expected_condition_survey = PropertyConditionSurvey( + uprn=1, + elements=[ + Element( + element_type=ElementType.ACCESSIBLE_HOUSING_REGISTER, + element_instance=1, + aspect_conditions=[ + AspectCondition( + aspect_type=AspectType.CATEGORY, + aspect_instance=1, + value="General Needs", + quantity=1, + install_date=None, + renewal_year=None, + comments=None, + ) + ], + ), + Element( + element_type=ElementType.FLOOR_LEVEL_FRONT_DOOR, + element_instance=1, + aspect_conditions=[ + AspectCondition( + aspect_type=AspectType.LOCATION, + aspect_instance=1, + value="Ground Floor", + quantity=1, + install_date=None, + renewal_year=None, + comments=None, + ) + ], + ), + Element( + element_type=ElementType.ASBESTOS, + element_instance=1, + aspect_conditions=[ + AspectCondition( + aspect_type=AspectType.PRESENCE, + aspect_instance=1, + value="Yes", + quantity=None, + install_date=None, + renewal_year=None, + comments=None, + ) + ], + ), + Element( + element_type=ElementType.HHSRS_ASBESTOS_AND_MMF, + element_instance=1, + aspect_conditions=[ + AspectCondition( + aspect_type=AspectType.RISK, + aspect_instance=1, + value="Category 4 - Typical Risk", + quantity=None, + renewal_year=None, + comments="Source of Data = ACT", + ) + ], + ), + Element( + element_type=ElementType.BATHROOM, + element_instance=1, + aspect_conditions=[ + AspectCondition( + aspect_type=AspectType.LOCATION, + aspect_instance=1, + value="Bathroom on Entrance Level in Property", + quantity=1, + install_date=None, + renewal_year=None, + comments="Source of Data = Codeman", + ) + ], + ), + Element( + element_type=ElementType.CENTRAL_HEATING, + element_instance=1, + aspect_conditions=[ + AspectCondition( + aspect_type=AspectType.EXTENT, + aspect_instance=1, + value="No Central Heating in Property", + quantity=1, + install_date=None, + renewal_year=None, + comments="Source of Data = Codeman", + ) + ], + ), + Element( + element_type=ElementType.HHSRS_FIRE, + element_instance=1, + aspect_conditions=[ + AspectCondition( + aspect_type=AspectType.RISK, + aspect_instance=1, + value="Category 4 - Typical Risk", + quantity=1, + install_date=None, + renewal_year=None, + comments="Source of Data = Morgan Sindall", + ) + ], + ), + Element( + element_type=ElementType.EXTERNAL_WALL, + element_instance=1, + aspect_conditions=[ + AspectCondition( + aspect_type=AspectType.FINISH, + aspect_instance=1, + value="Render or Pebbledash in External Area", + quantity=1, + install_date=date(2009, 4, 1), + renewal_year=2052, + comments="Source of Data = Codeman", + ), + AspectCondition( + aspect_type=AspectType.FINISH, + aspect_instance=2, + value="Smooth Render Wall Finish 2 in External Area", + quantity=1, + install_date=date(2009, 4, 1), + renewal_year=2052, + comments="Source of Data = Codeman", + ), + ], + ), + ], + date=date(2000, 1, 1), # what should this be? + source="LBWF", + ) # act - actual_assets: List[Element] = mapper.map_asset_conditions_for_property( - lbwf_house, survey_year + actual_condition_survey: PropertyConditionSurvey = ( + mapper.map_asset_conditions_for_property(lbwf_house) ) # 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}" + assert actual_condition_survey == expected_condition_survey