from typing import List from xml.dom.minidom import Element import pytest from datetime import date from backend.condition.domain.aspect_type import AspectType from backend.condition.domain.element import Element from backend.condition.domain.mapping.lbwf.lbwf_mapper import LbwfMapper from backend.condition.parsing.records.lbwf.lbwf_house import LbwfHouse from backend.condition.parsing.records.lbwf.lbwf_asset_condition import ( LbwfAssetCondition, ) from backend.condition.domain.asset_condition import AssetCondition def test_lbwf_mapper_maps_house(): # arrange lbwf_house = LbwfHouse( uprn=1, reference=100, address="123 Fake Street, London, A10 1AB", epc="F", shdf="NO", house="HOUSE", fail_decency=2025, assets=[ LbwfAssetCondition( prop_ref=100, domna=100, address="123 Fake Street, London, A10 1AB", ownership="LBWF_OWNED", prop_status="OCCP", prop_type="HOU", prop_sub_type="TERRACED", element_group="ASSETS", element_code="AHR_CAT", element_code_description="Accessible Housing Register Category", attribute_code="F", attribute_code_description="General Needs", element_date_value=None, element_numerical_value=None, element_text_value=None, quantity=1, install_date=None, remaining_life=None, element_comments=None, ), LbwfAssetCondition( prop_ref=100, domna=100, address="123 Fake Street, London, A10 1AB", ownership="LBWF_OWNED", prop_status="OCCP", prop_type="HOU", prop_sub_type="TERRACED", element_group="ASSETS", element_code="FLVL", element_code_description="Floor Level of Front Door", attribute_code="0G", attribute_code_description="Ground Floor", element_date_value=None, element_numerical_value=None, element_text_value=None, quantity=1, install_date=None, remaining_life=None, element_comments=None, ), LbwfAssetCondition( prop_ref=100, domna=100, address="123 Fake Street, London, A10 1AB", ownership="LBWF_OWNED", prop_status="OCCP", prop_type="HOU", prop_sub_type="TERRACED", element_group="ASSETS", element_code="ASBESTOS", element_code_description="Asbestos Present", attribute_code="YES", attribute_code_description="Yes", element_date_value=None, element_numerical_value=None, element_text_value=None, quantity=None, install_date=None, remaining_life=None, element_comments="Source of Data = ACT", ), LbwfAssetCondition( prop_ref=100, domna=100, address="123 Fake Street, London, A10 1AB", ownership="LBWF_OWNED", prop_status="OCCP", prop_type="HOU", prop_sub_type="TERRACED", element_group="ASSETS", element_code="HHSRSASB", element_code_description="Asbestos (and MMF)", attribute_code="TYPRISK", attribute_code_description="Category 4 - Typical Risk", element_date_value=None, element_numerical_value=None, element_text_value=None, quantity=None, install_date=None, remaining_life=None, element_comments="Source of Data = ACT", ), LbwfAssetCondition( prop_ref=100, domna=100, address="123 Fake Street, London, A10 1AB", ownership="LBWF_OWNED", prop_status="OCCP", prop_type="HOU", prop_sub_type="TERRACED", element_group="ASSETS", element_code="INTBTHRLOC", element_code_description="Location of Bathroom in Property", attribute_code="ENTRANCE", attribute_code_description="Bathroom on Entrance Level in Property", element_date_value=None, element_numerical_value=None, element_text_value=None, quantity=1, install_date=None, remaining_life=None, element_comments="Source of Data = Codeman", ), LbwfAssetCondition( prop_ref=100, domna=100, address="123 Fake Street, London, A10 1AB", ownership="LBWF_OWNED", prop_status="OCCP", prop_type="HOU", prop_sub_type="TERRACED", element_group="ASSETS", element_code="INTCHEXTNT", element_code_description="Extent of Central Heating in Property", attribute_code="NONE", attribute_code_description="No Central Heating in Property", element_date_value=None, element_numerical_value=None, element_text_value=None, quantity=1, install_date=None, remaining_life=None, element_comments="Source of Data = Codeman", ), LbwfAssetCondition( prop_ref=100, domna=100, address="123 Fake Street, London, A10 1AB", ownership="LBWF_OWNED", prop_status="OCCP", prop_type="HOU", prop_sub_type="TERRACED", element_group="ASSETS", element_code="HHSRSFIRE", element_code_description="Fire", attribute_code="TYPRISK", attribute_code_description="Category 4 - Typical Risk", element_date_value=None, element_numerical_value=None, element_text_value=None, quantity=1, install_date=None, remaining_life=None, element_comments="Source of Data = Morgan Sindall", ), LbwfAssetCondition( prop_ref=100, domna=100, address="123 Fake Street, London, A10 1AB", ownership="LBWF_OWNED", prop_status="OCCP", prop_type="HOU", prop_sub_type="TERRACED", element_group="ASSETS", element_code="EXTWALLFN1", element_code_description="Wall Finish 1 in External Area", attribute_code="SMTHRENDER", attribute_code_description="Render or Pebbledash in External Area", element_date_value=None, element_numerical_value=None, element_text_value=None, quantity=1, install_date=date(2009, 4, 1), remaining_life=26, element_comments="Source of Data = Codeman", ), LbwfAssetCondition( prop_ref=100, domna=100, address="123 Fake Street, London, A10 1AB", ownership="LBWF_OWNED", prop_status="OCCP", prop_type="HOU", prop_sub_type="TERRACED", element_group="ASSETS", element_code="EXTWALLFN2", element_code_description="Wall Finish 2 in External Area", attribute_code="SMTHRENDER", attribute_code_description="Smooth Render Wall Finish 2 in External Area", element_date_value=None, element_numerical_value=None, element_text_value=None, quantity=1, install_date=date(2009, 4, 1), remaining_life=26, element_comments="Source of Data = Codeman", ), ], ) mapper = LbwfMapper() survey_year = 2026 expected_assets: List[AssetCondition] = [ AssetCondition( uprn=1, element=Element.ACCESSIBLE_HOUSING_REGISTER, aspect_type=AspectType.CATEGORY, element_instance=None, value="General Needs", quantity=1, renewal_year=None, install_date=None, comments=None, ), AssetCondition( uprn=1, element=Element.FLOOR_LEVEL_FRONT_DOOR, aspect_type=AspectType.LOCATION, element_instance=None, value="Ground Floor", quantity=1, renewal_year=None, install_date=None, comments=None, ), AssetCondition( uprn=1, element=Element.ASBESTOS, aspect_type=AspectType.PRESENCE, element_instance=None, value="Yes", quantity=None, renewal_year=None, install_date=None, comments="Source of Data = ACT", ), AssetCondition( uprn=1, element=Element.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", ), AssetCondition( uprn=1, element=Element.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", ), AssetCondition( uprn=1, element=Element.HEATING_SYSTEM, 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", ), AssetCondition( uprn=1, element=Element.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", ), AssetCondition( uprn=1, element=Element.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", ), AssetCondition( uprn=1, element=Element.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", ), ] # act actual_assets: List[AssetCondition] = mapper.map_asset_conditions_for_property( lbwf_house, survey_year ) # 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}"