From 883028c89e37e74f4db9581648a6e1a36b5ea42f Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Wed, 20 May 2026 09:58:23 +0000 Subject: [PATCH] P6.1 follow-on: unbox BuildingPartIdentifier at backend boundaries Threads the strict BuildingPartIdentifier type (introduced in a8b443f6) through the two remaining backend touchpoints: - EpcBuildingPartModel.from_*: SQLModel column expects a string, so unbox the enum with .identifier.value before binding to the DB. - documents_parser end-to-end tests: swap bare-string equality ("main" / "extension_1") for identity checks against the enum members (BuildingPartIdentifier.MAIN / EXTENSION_1). Documents_parser test pack passes (105/105). No dedicated SQLModel test covers EpcBuildingPartModel.from_*; the .value line is exercised transitively via db_writer.py / local_runner.py in production. Co-Authored-By: Claude Opus 4.7 --- backend/app/db/models/epc_property.py | 2 +- backend/documents_parser/tests/test_elmhurst_end_to_end.py | 4 ++-- backend/documents_parser/tests/test_end_to_end.py | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/backend/app/db/models/epc_property.py b/backend/app/db/models/epc_property.py index 74083da2..93882d5d 100644 --- a/backend/app/db/models/epc_property.py +++ b/backend/app/db/models/epc_property.py @@ -501,7 +501,7 @@ class EpcBuildingPartModel(SQLModel, table=True): aw2 = part.sap_alternative_wall_2 return cls( epc_property_id=epc_property_id, - identifier=part.identifier, + identifier=part.identifier.value, construction_age_band=part.construction_age_band, wall_construction=str(part.wall_construction), wall_insulation_type=str(part.wall_insulation_type), diff --git a/backend/documents_parser/tests/test_elmhurst_end_to_end.py b/backend/documents_parser/tests/test_elmhurst_end_to_end.py index 977ea138..af192eeb 100644 --- a/backend/documents_parser/tests/test_elmhurst_end_to_end.py +++ b/backend/documents_parser/tests/test_elmhurst_end_to_end.py @@ -5,7 +5,7 @@ from datetime import date import pytest from backend.documents_parser.elmhurst_extractor import ElmhurstSiteNotesExtractor -from datatypes.epc.domain.epc_property_data import EpcPropertyData +from datatypes.epc.domain.epc_property_data import BuildingPartIdentifier, EpcPropertyData from datatypes.epc.domain.mapper import EpcPropertyDataMapper FIXTURE_PATH = os.path.join( @@ -130,7 +130,7 @@ class TestBuildingPart: assert len(result.sap_building_parts) == 1 def test_identifier(self, result: EpcPropertyData) -> None: - assert result.sap_building_parts[0].identifier == "main" + assert result.sap_building_parts[0].identifier is BuildingPartIdentifier.MAIN def test_construction_age_band(self, result: EpcPropertyData) -> None: assert result.sap_building_parts[0].construction_age_band == "1950-1966" diff --git a/backend/documents_parser/tests/test_end_to_end.py b/backend/documents_parser/tests/test_end_to_end.py index c413b55f..d1a02717 100644 --- a/backend/documents_parser/tests/test_end_to_end.py +++ b/backend/documents_parser/tests/test_end_to_end.py @@ -6,6 +6,7 @@ import pytest from backend.documents_parser.extractor import PasHubRdSapSiteNotesExtractor from backend.documents_parser.pdf import pdf_to_text_list from datatypes.epc.domain.epc_property_data import ( + BuildingPartIdentifier, EpcPropertyData, InstantaneousWwhrs, MainHeatingDetail, @@ -187,7 +188,7 @@ class TestPdfToEpcPropertyData: ), sap_building_parts=[ SapBuildingPart( - identifier="main", + identifier=BuildingPartIdentifier.MAIN, construction_age_band="1950-1966", wall_construction="Cavity", wall_insulation_type="Filled Cavity", @@ -218,7 +219,7 @@ class TestPdfToEpcPropertyData: floor_u_value_known=False, ), SapBuildingPart( - identifier="extension_1", + identifier=BuildingPartIdentifier.EXTENSION_1, construction_age_band="2003-2006", wall_construction="Cavity", wall_insulation_type="As built",