mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
inspection date is date not str
This commit is contained in:
parent
c271caf378
commit
968f025bc3
6 changed files with 17 additions and 12 deletions
|
|
@ -101,11 +101,9 @@ class PasHubRdSapSiteNotesExtractor:
|
|||
|
||||
def extract_general(self) -> General:
|
||||
inspection_date_raw = self._get("Inspection Date:")
|
||||
inspection_date = (
|
||||
datetime.strptime(inspection_date_raw, "%d/%m/%Y").strftime("%Y-%m-%d")
|
||||
if inspection_date_raw
|
||||
else ""
|
||||
)
|
||||
if not inspection_date_raw:
|
||||
raise ValueError("Inspection Date not found in document")
|
||||
inspection_date = datetime.strptime(inspection_date_raw, "%d/%m/%Y").date()
|
||||
|
||||
storeys_raw = self._get("Number of storeys:") or "0"
|
||||
extensions_raw = self._get("Number of Extensions:") or "0"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import json
|
||||
import os
|
||||
from datetime import date
|
||||
|
||||
import pytest
|
||||
|
||||
|
|
@ -51,7 +52,7 @@ class TestGeneral:
|
|||
assert general.epc_exists_at_point_of_assessment is False
|
||||
|
||||
def test_inspection_date(self, general: General) -> None:
|
||||
assert general.inspection_date == "2025-09-25"
|
||||
assert general.inspection_date == date(2025, 9, 25)
|
||||
|
||||
def test_transaction_type(self, general: General) -> None:
|
||||
assert general.transaction_type == "Grant-Scheme (ECO, RHI, etc.)"
|
||||
|
|
@ -84,7 +85,7 @@ class TestGeneral:
|
|||
assert general == General(
|
||||
epc_checked_before_assessment=True,
|
||||
epc_exists_at_point_of_assessment=False,
|
||||
inspection_date="2025-09-25",
|
||||
inspection_date=date(2025, 9, 25),
|
||||
transaction_type="Grant-Scheme (ECO, RHI, etc.)",
|
||||
tenure="Rented Social",
|
||||
property_type="House",
|
||||
|
|
@ -530,7 +531,7 @@ class TestExtract:
|
|||
def test_full_extract(self) -> None:
|
||||
result = PasHubRdSapSiteNotesExtractor(load_text_fixture()).extract()
|
||||
assert result.inspection_metadata is None
|
||||
assert result.general.inspection_date == "2025-09-25"
|
||||
assert result.general.inspection_date == date(2025, 9, 25)
|
||||
assert result.building_construction.main_building.wall_thickness_mm == 310
|
||||
assert result.building_measurements.main_building.floors[0].area_m2 == 35.68
|
||||
assert result.roof_space.main_building.insulation_thickness_mm == 100
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ class EpcPropertyDataMapper:
|
|||
|
||||
return EpcPropertyData(
|
||||
dwelling_type=f"{general.detachment_type} {general.property_type.lower()}",
|
||||
inspection_date=date.fromisoformat(general.inspection_date),
|
||||
inspection_date=general.inspection_date,
|
||||
tenure=general.tenure,
|
||||
transaction_type=general.transaction_type,
|
||||
roofs=[],
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import dataclasses
|
||||
import typing
|
||||
from datetime import date
|
||||
from typing import Any, Dict, Type, TypeVar
|
||||
|
||||
T = TypeVar("T")
|
||||
|
|
@ -70,4 +71,7 @@ def _coerce(value: Any, hint: Any) -> Any:
|
|||
if dataclasses.is_dataclass(hint) and isinstance(value, dict):
|
||||
return _from_dict_impl(hint, value)
|
||||
|
||||
if hint is date and isinstance(value, str):
|
||||
return date.fromisoformat(value)
|
||||
|
||||
return value
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
from dataclasses import dataclass
|
||||
from datetime import date
|
||||
from typing import List, Optional
|
||||
|
||||
|
||||
|
|
@ -8,7 +9,7 @@ class InspectionMetadata:
|
|||
email_address: str
|
||||
report_reference: str
|
||||
created_on: str
|
||||
date_of_inspection: str
|
||||
date_of_inspection: date
|
||||
property_address: str
|
||||
property_photo: Optional[bool] = None
|
||||
|
||||
|
|
@ -17,7 +18,7 @@ class InspectionMetadata:
|
|||
class General:
|
||||
epc_checked_before_assessment: bool
|
||||
epc_exists_at_point_of_assessment: bool
|
||||
inspection_date: str
|
||||
inspection_date: date
|
||||
transaction_type: str
|
||||
tenure: str
|
||||
property_type: str
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import json
|
||||
import os
|
||||
from datetime import date
|
||||
from typing import Any, Dict
|
||||
|
||||
import pytest
|
||||
|
|
@ -224,7 +225,7 @@ class TestExample2:
|
|||
self, survey: PasHubRdSapSiteNotes
|
||||
) -> None:
|
||||
assert survey.inspection_metadata.created_on == "2025-11-10"
|
||||
assert survey.inspection_metadata.date_of_inspection == "2025-09-25"
|
||||
assert survey.inspection_metadata.date_of_inspection == date(2025, 9, 25)
|
||||
|
||||
# --- general ---
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue