diff --git a/datatypes/epc/domain/mapper.py b/datatypes/epc/domain/mapper.py index c4b9e5c9b..94b49205e 100644 --- a/datatypes/epc/domain/mapper.py +++ b/datatypes/epc/domain/mapper.py @@ -2142,6 +2142,10 @@ class EpcPropertyDataMapper: open_chimneys_count=schema.open_chimneys_count or 0, insulated_door_count=schema.insulated_door_count, draughtproofed_door_count=schema.draughtproofed_door_count, + # 21.0.0 lodges percent_draughtproofed but the mapper dropped it, + # unlike every other path (17.0/…/21.0.1). Understated the §2 + # draughtproofing/infiltration credit. + percent_draughtproofed=schema.percent_draughtproofed, led_fixed_lighting_bulbs_count=schema.led_fixed_lighting_bulbs_count or 0, cfl_fixed_lighting_bulbs_count=schema.cfl_fixed_lighting_bulbs_count or 0, incandescent_fixed_lighting_bulbs_count=schema.incandescent_fixed_lighting_bulbs_count, diff --git a/tests/datatypes/epc/domain/test_mapper_percent_draughtproofed_21_0_0.py b/tests/datatypes/epc/domain/test_mapper_percent_draughtproofed_21_0_0.py new file mode 100644 index 000000000..ba8319d0e --- /dev/null +++ b/tests/datatypes/epc/domain/test_mapper_percent_draughtproofed_21_0_0.py @@ -0,0 +1,34 @@ +"""Regression: the RdSAP-Schema-21.0.0 mapper must carry the lodged +percent_draughtproofed, like every other API path (17.0/…/21.0.1). + +PRD #1385 (mapper normalization). 21.0.0 was the last path still dropping +`percent_draughtproofed` (top-level int, lodged by the schema), understating the +§2 draughtproofing/infiltration credit. +""" + +from __future__ import annotations + +import json +from pathlib import Path +from typing import Any + +from datatypes.epc.domain.mapper import EpcPropertyDataMapper + +# The harvested 21.0.0 sample lodges percent_draughtproofed=100. +_FIXTURE = Path("backend/epc_api/json_samples/RdSAP-Schema-21.0.0/epc.json") + + +def _load() -> dict[str, Any]: + data: dict[str, Any] = json.loads(_FIXTURE.read_text()) + assert data["schema_type"] == "RdSAP-Schema-21.0.0" + return data + + +def test_21_0_0_carries_percent_draughtproofed() -> None: + data = _load() + assert data["percent_draughtproofed"] == 100 + + epc = EpcPropertyDataMapper.from_api_response(data) + + # Was dropped to None on the 21.0.0 path; now carried through. + assert epc.percent_draughtproofed == 100