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 <noreply@anthropic.com>
This commit is contained in:
Khalim Conn-Kowlessar 2026-05-20 09:58:23 +00:00
parent a8b443f669
commit 883028c89e
3 changed files with 6 additions and 5 deletions

View file

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

View file

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

View file

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