mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-30 13:10:47 +00:00
Prove prediction resolves landlord overrides to a real cohort match end-to-end 🟩
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
864ba8dc1b
commit
80b86d4790
1 changed files with 35 additions and 11 deletions
|
|
@ -28,11 +28,11 @@ from datatypes.epc.domain.epc_property_data import EpcPropertyData
|
||||||
from datatypes.epc.domain.mapper import EpcPropertyDataMapper
|
from datatypes.epc.domain.mapper import EpcPropertyDataMapper
|
||||||
from datatypes.epc.search.epc_search_result import EpcSearchResult
|
from datatypes.epc.search.epc_search_result import EpcSearchResult
|
||||||
from domain.epc_prediction.epc_prediction import EpcPrediction
|
from domain.epc_prediction.epc_prediction import EpcPrediction
|
||||||
from domain.epc_prediction.prediction_target import PredictionTargetAttributes
|
|
||||||
from domain.geospatial.coordinates import Coordinates
|
from domain.geospatial.coordinates import Coordinates
|
||||||
from domain.geospatial.planning_restrictions import PlanningRestrictions
|
from domain.geospatial.planning_restrictions import PlanningRestrictions
|
||||||
from domain.geospatial.spatial_reference import SpatialReference
|
from domain.geospatial.spatial_reference import SpatialReference
|
||||||
from domain.property.property import Property
|
from domain.property.property import Property
|
||||||
|
from infrastructure.postgres.property_override_table import PropertyOverrideRow
|
||||||
from infrastructure.postgres.property_table import PropertyRow
|
from infrastructure.postgres.property_table import PropertyRow
|
||||||
from orchestration.ingestion_orchestrator import IngestionOrchestrator
|
from orchestration.ingestion_orchestrator import IngestionOrchestrator
|
||||||
from repositories.comparable_properties.epc_comparable_properties_repository import (
|
from repositories.comparable_properties.epc_comparable_properties_repository import (
|
||||||
|
|
@ -41,6 +41,12 @@ from repositories.comparable_properties.epc_comparable_properties_repository imp
|
||||||
from repositories.epc.epc_postgres_repository import EpcPostgresRepository
|
from repositories.epc.epc_postgres_repository import EpcPostgresRepository
|
||||||
from repositories.geospatial.geospatial_repository import GeospatialRepository
|
from repositories.geospatial.geospatial_repository import GeospatialRepository
|
||||||
from repositories.postgres_unit_of_work import PostgresUnitOfWork
|
from repositories.postgres_unit_of_work import PostgresUnitOfWork
|
||||||
|
from repositories.property.override_backed_prediction_attributes_reader import (
|
||||||
|
OverrideBackedPredictionAttributesReader,
|
||||||
|
)
|
||||||
|
from repositories.property.property_overrides_postgres_reader import (
|
||||||
|
PropertyOverridesPostgresReader,
|
||||||
|
)
|
||||||
from repositories.property.property_postgres_repository import (
|
from repositories.property.property_postgres_repository import (
|
||||||
PropertyPostgresRepository,
|
PropertyPostgresRepository,
|
||||||
)
|
)
|
||||||
|
|
@ -105,14 +111,6 @@ class _NoSolarFetcher:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
class _FakeAttributesReader:
|
|
||||||
"""Stands in for Jun-te's property_overrides read adapter: the landlord-known
|
|
||||||
property type (here a House, code "0", matching the cohort)."""
|
|
||||||
|
|
||||||
def attributes_for(self, property_id: int) -> PredictionTargetAttributes:
|
|
||||||
return PredictionTargetAttributes(property_type="0", built_form="2")
|
|
||||||
|
|
||||||
|
|
||||||
def _cohort_results() -> list[EpcSearchResult]:
|
def _cohort_results() -> list[EpcSearchResult]:
|
||||||
return [
|
return [
|
||||||
EpcSearchResult(
|
EpcSearchResult(
|
||||||
|
|
@ -135,7 +133,9 @@ def test_epc_less_property_is_predicted_persisted_and_resolved_end_to_end(
|
||||||
db_engine: Engine,
|
db_engine: Engine,
|
||||||
) -> None:
|
) -> None:
|
||||||
# Arrange — an EPC-less Property exists in the database (postcode + UPRN known,
|
# Arrange — an EPC-less Property exists in the database (postcode + UPRN known,
|
||||||
# no EPC lodged), plus its postcode cohort behind the faked EPC API.
|
# no EPC lodged), plus its postcode cohort behind the faked EPC API, plus the
|
||||||
|
# landlord overrides the finaliser resolved for it (House / Semi-Detached) that
|
||||||
|
# the real read adapter will translate into the gov-code space ("0" / "2").
|
||||||
with Session(db_engine) as session:
|
with Session(db_engine) as session:
|
||||||
row = PropertyRow(
|
row = PropertyRow(
|
||||||
portfolio_id=1, postcode=_POSTCODE, address="1 Target Street", uprn=10000
|
portfolio_id=1, postcode=_POSTCODE, address="1 Target Street", uprn=10000
|
||||||
|
|
@ -145,6 +145,28 @@ def test_epc_less_property_is_predicted_persisted_and_resolved_end_to_end(
|
||||||
property_id = row.id
|
property_id = row.id
|
||||||
assert property_id is not None
|
assert property_id is not None
|
||||||
|
|
||||||
|
session.add(
|
||||||
|
PropertyOverrideRow(
|
||||||
|
property_id=property_id,
|
||||||
|
portfolio_id=1,
|
||||||
|
building_part=0,
|
||||||
|
override_component="property_type",
|
||||||
|
override_value="House",
|
||||||
|
original_spreadsheet_description="3-bed semi",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
session.add(
|
||||||
|
PropertyOverrideRow(
|
||||||
|
property_id=property_id,
|
||||||
|
portfolio_id=1,
|
||||||
|
building_part=0,
|
||||||
|
override_component="built_form_type",
|
||||||
|
override_value="Semi-Detached",
|
||||||
|
original_spreadsheet_description="3-bed semi",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
session.commit()
|
||||||
|
|
||||||
cohort_coords = {20000 + i: Coordinates(longitude=-1.55, latitude=53.81) for i in range(3)}
|
cohort_coords = {20000 + i: Coordinates(longitude=-1.55, latitude=53.81) for i in range(3)}
|
||||||
comparables_repo = EpcComparablePropertiesRepository(
|
comparables_repo = EpcComparablePropertiesRepository(
|
||||||
_FakeCohortEpcClient(_cohort_results()), _FakeGeospatialRepo(cohort_coords)
|
_FakeCohortEpcClient(_cohort_results()), _FakeGeospatialRepo(cohort_coords)
|
||||||
|
|
@ -155,7 +177,9 @@ def test_epc_less_property_is_predicted_persisted_and_resolved_end_to_end(
|
||||||
geospatial_repo=_FakeGeospatialRepo({10000: Coordinates(longitude=-1.55, latitude=53.81)}),
|
geospatial_repo=_FakeGeospatialRepo({10000: Coordinates(longitude=-1.55, latitude=53.81)}),
|
||||||
solar_fetcher=_NoSolarFetcher(),
|
solar_fetcher=_NoSolarFetcher(),
|
||||||
comparables_repo=comparables_repo,
|
comparables_repo=comparables_repo,
|
||||||
prediction_attributes_reader=_FakeAttributesReader(),
|
prediction_attributes_reader=OverrideBackedPredictionAttributesReader(
|
||||||
|
PropertyOverridesPostgresReader(lambda: Session(db_engine))
|
||||||
|
),
|
||||||
epc_prediction=EpcPrediction(),
|
epc_prediction=EpcPrediction(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue