Map lbwf data to new structure 🟥

This commit is contained in:
Daniel Roth 2026-01-27 15:20:13 +00:00
parent 61caf8c495
commit d6112f3dc8
2 changed files with 141 additions and 108 deletions

View file

@ -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

View file

@ -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