From a3a620a7e9d0236393fef7705bc3a3efa0a94f6c Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Wed, 1 Jul 2026 14:13:17 +0000 Subject: [PATCH] Normalize RdSAP percent_draughtproofed on the 21.0.0 path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PRD #1385 phase 2. 21.0.0 was the last mapper still dropping the lodged percent_draughtproofed (top-level int) — every other path (17.0/…/21.0.1) reads it. Dropping it understated the SAP §2 draughtproofing/infiltration credit for 21.0.0 certs. Verification: new test 1 passed (harvested 21.0.0 sample lodges 100); corpus 6002 passed; SAP-accuracy regressions pass; pyright unchanged (39 -> 39). Co-Authored-By: Claude Opus 4.8 (1M context) --- datatypes/epc/domain/mapper.py | 4 +++ ...st_mapper_percent_draughtproofed_21_0_0.py | 34 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 tests/datatypes/epc/domain/test_mapper_percent_draughtproofed_21_0_0.py 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