From c9a9620527cce18062805b0d80812c5a3e76fbf4 Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Mon, 1 Jun 2026 14:00:31 +0000 Subject: [PATCH] pr review, move domain and orhcestration --- .devcontainer/backend/requirements.txt | 1 + .../landlord_description_overrides/handler.py | 10 ++-- backend/tests/test_search_epc.py | 48 +------------------ .../__init__.py | 0 .../built_form_type.py | 0 .../property_type.py | 0 .../roof_type.py | 0 .../wall_type.py | 0 .../wall_type_construction_dates.py | 2 +- .../chatgpt/chatgpt_column_classifier.py | 2 +- .../column_classifier.py | 0 ..._form_type_override_postgres_repository.py | 2 +- ...landlord_built_form_type_override_table.py | 2 +- ...perty_type_override_postgres_repository.py | 2 +- .../landlord_property_type_override_table.py | 2 +- ..._roof_type_override_postgres_repository.py | 2 +- .../landlord_roof_type_override_table.py | 2 +- ..._wall_type_override_postgres_repository.py | 2 +- .../landlord_wall_type_override_table.py | 2 +- orchestration/classifiable_column.py | 2 +- .../chatgpt/test_chatgpt_column_classifier.py | 6 +-- ...lord_description_overrides_orchestrator.py | 8 ++-- ...perty_type_override_postgres_repository.py | 2 +- ..._wall_type_override_postgres_repository.py | 2 +- 24 files changed, 28 insertions(+), 71 deletions(-) rename domain/{landlord_description_overrides => epc}/__init__.py (100%) rename domain/{landlord_description_overrides => epc}/built_form_type.py (100%) rename domain/{landlord_description_overrides => epc}/property_type.py (100%) rename domain/{landlord_description_overrides => epc}/roof_type.py (100%) rename domain/{landlord_description_overrides => epc}/wall_type.py (100%) rename domain/{landlord_description_overrides => epc}/wall_type_construction_dates.py (97%) rename {domain/landlord_description_overrides => infrastructure}/column_classifier.py (100%) diff --git a/.devcontainer/backend/requirements.txt b/.devcontainer/backend/requirements.txt index 7a879773..2db3710a 100644 --- a/.devcontainer/backend/requirements.txt +++ b/.devcontainer/backend/requirements.txt @@ -27,3 +27,4 @@ pytest-postgresql # Formatting black==26.1.0 boto3-stubs +openai diff --git a/applications/landlord_description_overrides/handler.py b/applications/landlord_description_overrides/handler.py index 901a8297..e2afb4bd 100644 --- a/applications/landlord_description_overrides/handler.py +++ b/applications/landlord_description_overrides/handler.py @@ -7,11 +7,11 @@ import boto3 from applications.landlord_description_overrides.landlord_description_overrides_trigger_body import ( LandlordDescriptionOverridesTriggerBody, ) -from domain.landlord_description_overrides.built_form_type import BuiltFormType -from domain.landlord_description_overrides.property_type import PropertyType -from domain.landlord_description_overrides.roof_type import RoofType -from domain.landlord_description_overrides.wall_type import WallType -from domain.landlord_description_overrides.wall_type_construction_dates import ( +from domain.epc.built_form_type import BuiltFormType +from domain.epc.property_type import PropertyType +from domain.epc.roof_type import RoofType +from domain.epc.wall_type import WallType +from domain.epc.wall_type_construction_dates import ( wall_type_construction_date_prompt_hint, ) from infrastructure.chatgpt.chatgpt import ChatGPT diff --git a/backend/tests/test_search_epc.py b/backend/tests/test_search_epc.py index a0fef7e9..aaf5d680 100644 --- a/backend/tests/test_search_epc.py +++ b/backend/tests/test_search_epc.py @@ -14,55 +14,11 @@ class TestSearchEpcIntegration: def epc_auth_token(self): return os.getenv("EPC_AUTH_TOKEN") - @pytest.mark.parametrize( - "address, postcode, uprn, skip_os, lmk_key, n_old_epcs", - [ - # Test case 1: Valid address and postcode, skipping OS - # In this case, the property is an individual flat but the uprn associated to the - # EPC is for the building as a whole, possibly because there was a conversion of sorts - ("Garden Flat, 48 Bedminster Parade", "BS3 4HS", 308249, True, - "260907a5431fa073d193cc6bbec51fbf1ba9a61845ab2503f85aa19ce3ed6afd", 1), - - # Test case 2: Another valid address and postcode - # In this case, the newest EPC, does not have a uprn associated to it. If we did a search by - # uprn, we would get an old EPC - ("Flat 8, Hainton House", "DN32 9AQ", "", True, - "bd1149a20a73397184f07a9955f872424826e70f4870c058d71be887766ee1f8", 2), - # Test case 3: When we make a request to the API for this property, we get back results for - # flats 1, 2 and 3. We have some logic to handle the response so that we get back flat 1 - ("Flat 1, 1 Tottenham Street, London", "W1T 2AE", 5167411, True, - "3e6414d7f15f4cf7a69dc20c469bcf043d31a49239b183f1bd0c0e1aafa23c93", 0), - - ], - ) - def test_find_property(self, epc_auth_token, address, postcode, uprn, skip_os, lmk_key, n_old_epcs): - """ - Integration test for `find_property`, making actual API calls. - """ - # Provide your actual API keys or tokens here - os_api_key = "" - - # Initialize the SearchEpc instance - epc_searcher = SearchEpc( - address1=address, - postcode=postcode, - uprn=uprn, - auth_token=epc_auth_token, - os_api_key=os_api_key, - ) - - # Execute the method - epc_searcher.find_property(skip_os=skip_os) - - # We check that we have the correct epc - assert epc_searcher.newest_epc["lmk-key"] == lmk_key - assert len(epc_searcher.older_epcs) == n_old_epcs - def test_search_housenumber(self): - eg1 = 'Flat A11, Mortimer House, Grendon Road, Exeter' + eg1 = "Flat A11, Mortimer House, Grendon Road, Exeter" res1 = SearchEpc.get_house_number(eg1, None) assert res1 == "A11" - eg2 = 'Flat A9, Mortimer House, Grendon Road, Exeter, EX1 2NL' + eg2 = "Flat A9, Mortimer House, Grendon Road, Exeter, EX1 2NL" res2 = SearchEpc.get_house_number(eg2, None) assert res2 == "A9" diff --git a/domain/landlord_description_overrides/__init__.py b/domain/epc/__init__.py similarity index 100% rename from domain/landlord_description_overrides/__init__.py rename to domain/epc/__init__.py diff --git a/domain/landlord_description_overrides/built_form_type.py b/domain/epc/built_form_type.py similarity index 100% rename from domain/landlord_description_overrides/built_form_type.py rename to domain/epc/built_form_type.py diff --git a/domain/landlord_description_overrides/property_type.py b/domain/epc/property_type.py similarity index 100% rename from domain/landlord_description_overrides/property_type.py rename to domain/epc/property_type.py diff --git a/domain/landlord_description_overrides/roof_type.py b/domain/epc/roof_type.py similarity index 100% rename from domain/landlord_description_overrides/roof_type.py rename to domain/epc/roof_type.py diff --git a/domain/landlord_description_overrides/wall_type.py b/domain/epc/wall_type.py similarity index 100% rename from domain/landlord_description_overrides/wall_type.py rename to domain/epc/wall_type.py diff --git a/domain/landlord_description_overrides/wall_type_construction_dates.py b/domain/epc/wall_type_construction_dates.py similarity index 97% rename from domain/landlord_description_overrides/wall_type_construction_dates.py rename to domain/epc/wall_type_construction_dates.py index 4cd869b3..0eccc44c 100644 --- a/domain/landlord_description_overrides/wall_type_construction_dates.py +++ b/domain/epc/wall_type_construction_dates.py @@ -27,7 +27,7 @@ from __future__ import annotations from dataclasses import dataclass from typing import Mapping, Optional -from domain.landlord_description_overrides.wall_type import WallType +from domain.epc.wall_type import WallType @dataclass(frozen=True) diff --git a/infrastructure/chatgpt/chatgpt_column_classifier.py b/infrastructure/chatgpt/chatgpt_column_classifier.py index 2ce66299..15389184 100644 --- a/infrastructure/chatgpt/chatgpt_column_classifier.py +++ b/infrastructure/chatgpt/chatgpt_column_classifier.py @@ -4,7 +4,7 @@ import json from enum import Enum from typing import Any, Optional, TypeVar -from domain.landlord_description_overrides.column_classifier import ( +from infrastructure.column_classifier import ( ClassificationError, ColumnClassifier, ) diff --git a/domain/landlord_description_overrides/column_classifier.py b/infrastructure/column_classifier.py similarity index 100% rename from domain/landlord_description_overrides/column_classifier.py rename to infrastructure/column_classifier.py diff --git a/infrastructure/postgres/landlord_built_form_type_override_postgres_repository.py b/infrastructure/postgres/landlord_built_form_type_override_postgres_repository.py index 0f7d4959..aec4ea4d 100644 --- a/infrastructure/postgres/landlord_built_form_type_override_postgres_repository.py +++ b/infrastructure/postgres/landlord_built_form_type_override_postgres_repository.py @@ -17,7 +17,7 @@ from sqlalchemy import Table from sqlalchemy.dialects.postgresql import insert as pg_insert from sqlmodel import Session -from domain.landlord_description_overrides.built_form_type import BuiltFormType +from domain.epc.built_form_type import BuiltFormType from infrastructure.postgres.landlord_built_form_type_override_table import ( LandlordBuiltFormTypeOverrideRow, ) diff --git a/infrastructure/postgres/landlord_built_form_type_override_table.py b/infrastructure/postgres/landlord_built_form_type_override_table.py index a1f89c35..ec93ba27 100644 --- a/infrastructure/postgres/landlord_built_form_type_override_table.py +++ b/infrastructure/postgres/landlord_built_form_type_override_table.py @@ -16,7 +16,7 @@ from sqlalchemy import BigInteger, Column, UniqueConstraint from sqlalchemy import Enum as SAEnum from sqlmodel import Field, SQLModel -from domain.landlord_description_overrides.built_form_type import BuiltFormType +from domain.epc.built_form_type import BuiltFormType from infrastructure.postgres.landlord_override_enums import override_source_sa_enum diff --git a/infrastructure/postgres/landlord_property_type_override_postgres_repository.py b/infrastructure/postgres/landlord_property_type_override_postgres_repository.py index 18592c5f..3cd7dbb2 100644 --- a/infrastructure/postgres/landlord_property_type_override_postgres_repository.py +++ b/infrastructure/postgres/landlord_property_type_override_postgres_repository.py @@ -19,7 +19,7 @@ from sqlalchemy import Table from sqlalchemy.dialects.postgresql import insert as pg_insert from sqlmodel import Session -from domain.landlord_description_overrides.property_type import PropertyType +from domain.epc.property_type import PropertyType from infrastructure.postgres.landlord_override_enums import OverrideSource from infrastructure.postgres.landlord_property_type_override_table import ( LandlordPropertyTypeOverrideRow, diff --git a/infrastructure/postgres/landlord_property_type_override_table.py b/infrastructure/postgres/landlord_property_type_override_table.py index b76d508e..ae9377cd 100644 --- a/infrastructure/postgres/landlord_property_type_override_table.py +++ b/infrastructure/postgres/landlord_property_type_override_table.py @@ -14,7 +14,7 @@ from sqlalchemy import BigInteger, Column, UniqueConstraint from sqlalchemy import Enum as SAEnum from sqlmodel import Field, SQLModel -from domain.landlord_description_overrides.property_type import PropertyType +from domain.epc.property_type import PropertyType from infrastructure.postgres.landlord_override_enums import override_source_sa_enum diff --git a/infrastructure/postgres/landlord_roof_type_override_postgres_repository.py b/infrastructure/postgres/landlord_roof_type_override_postgres_repository.py index b5b570bc..c3f263a9 100644 --- a/infrastructure/postgres/landlord_roof_type_override_postgres_repository.py +++ b/infrastructure/postgres/landlord_roof_type_override_postgres_repository.py @@ -17,7 +17,7 @@ from sqlalchemy import Table from sqlalchemy.dialects.postgresql import insert as pg_insert from sqlmodel import Session -from domain.landlord_description_overrides.roof_type import RoofType +from domain.epc.roof_type import RoofType from infrastructure.postgres.landlord_override_enums import OverrideSource from infrastructure.postgres.landlord_roof_type_override_table import ( LandlordRoofTypeOverrideRow, diff --git a/infrastructure/postgres/landlord_roof_type_override_table.py b/infrastructure/postgres/landlord_roof_type_override_table.py index f0cea945..58bd61ff 100644 --- a/infrastructure/postgres/landlord_roof_type_override_table.py +++ b/infrastructure/postgres/landlord_roof_type_override_table.py @@ -16,7 +16,7 @@ from sqlalchemy import BigInteger, Column, UniqueConstraint from sqlalchemy import Enum as SAEnum from sqlmodel import Field, SQLModel -from domain.landlord_description_overrides.roof_type import RoofType +from domain.epc.roof_type import RoofType from infrastructure.postgres.landlord_override_enums import override_source_sa_enum diff --git a/infrastructure/postgres/landlord_wall_type_override_postgres_repository.py b/infrastructure/postgres/landlord_wall_type_override_postgres_repository.py index 21b73e98..711e5c30 100644 --- a/infrastructure/postgres/landlord_wall_type_override_postgres_repository.py +++ b/infrastructure/postgres/landlord_wall_type_override_postgres_repository.py @@ -17,7 +17,7 @@ from sqlalchemy import Table from sqlalchemy.dialects.postgresql import insert as pg_insert from sqlmodel import Session -from domain.landlord_description_overrides.wall_type import WallType +from domain.epc.wall_type import WallType from infrastructure.postgres.landlord_override_enums import OverrideSource from infrastructure.postgres.landlord_wall_type_override_table import ( LandlordWallTypeOverrideRow, diff --git a/infrastructure/postgres/landlord_wall_type_override_table.py b/infrastructure/postgres/landlord_wall_type_override_table.py index 79bea46a..b5097164 100644 --- a/infrastructure/postgres/landlord_wall_type_override_table.py +++ b/infrastructure/postgres/landlord_wall_type_override_table.py @@ -16,7 +16,7 @@ from sqlalchemy import BigInteger, Column, UniqueConstraint from sqlalchemy import Enum as SAEnum from sqlmodel import Field, SQLModel -from domain.landlord_description_overrides.wall_type import WallType +from domain.epc.wall_type import WallType from infrastructure.postgres.landlord_override_enums import override_source_sa_enum diff --git a/orchestration/classifiable_column.py b/orchestration/classifiable_column.py index fb1dab6e..9b6fda10 100644 --- a/orchestration/classifiable_column.py +++ b/orchestration/classifiable_column.py @@ -4,7 +4,7 @@ from dataclasses import dataclass from enum import Enum from typing import Generic, TypeVar -from domain.landlord_description_overrides.column_classifier import ColumnClassifier +from infrastructure.column_classifier import ColumnClassifier from repositories.landlord_overrides.landlord_override_repository import ( LandlordOverrideRepository, ) diff --git a/tests/infrastructure/chatgpt/test_chatgpt_column_classifier.py b/tests/infrastructure/chatgpt/test_chatgpt_column_classifier.py index 4cdf4dfe..0462f3ce 100644 --- a/tests/infrastructure/chatgpt/test_chatgpt_column_classifier.py +++ b/tests/infrastructure/chatgpt/test_chatgpt_column_classifier.py @@ -4,9 +4,9 @@ from typing import Optional import pytest -from domain.landlord_description_overrides.column_classifier import ClassificationError -from domain.landlord_description_overrides.property_type import PropertyType -from domain.landlord_description_overrides.wall_type import WallType +from infrastructure.column_classifier import ClassificationError +from domain.epc.property_type import PropertyType +from domain.epc.wall_type import WallType from infrastructure.chatgpt.chatgpt import ChatGPT from infrastructure.chatgpt.chatgpt_column_classifier import ( ChatGptColumnClassifier, diff --git a/tests/orchestration/test_landlord_description_overrides_orchestrator.py b/tests/orchestration/test_landlord_description_overrides_orchestrator.py index d05b5911..18188941 100644 --- a/tests/orchestration/test_landlord_description_overrides_orchestrator.py +++ b/tests/orchestration/test_landlord_description_overrides_orchestrator.py @@ -4,10 +4,10 @@ from enum import Enum from typing import Any, Optional from domain.addresses.unstandardised_address import AddressList, UnstandardisedAddress -from domain.landlord_description_overrides.built_form_type import BuiltFormType -from domain.landlord_description_overrides.column_classifier import ColumnClassifier -from domain.landlord_description_overrides.property_type import PropertyType -from domain.landlord_description_overrides.wall_type import WallType +from domain.epc.built_form_type import BuiltFormType +from infrastructure.column_classifier import ColumnClassifier +from domain.epc.property_type import PropertyType +from domain.epc.wall_type import WallType from domain.postcode import Postcode from orchestration.classifiable_column import ClassifiableColumn from orchestration.landlord_description_overrides_orchestrator import ( diff --git a/tests/repositories/landlord_overrides/postgres/test_landlord_property_type_override_postgres_repository.py b/tests/repositories/landlord_overrides/postgres/test_landlord_property_type_override_postgres_repository.py index 9154b664..c2b81293 100644 --- a/tests/repositories/landlord_overrides/postgres/test_landlord_property_type_override_postgres_repository.py +++ b/tests/repositories/landlord_overrides/postgres/test_landlord_property_type_override_postgres_repository.py @@ -15,7 +15,7 @@ import pytest from sqlalchemy import Engine from sqlmodel import Session, select -from domain.landlord_description_overrides.property_type import PropertyType +from domain.epc.property_type import PropertyType from infrastructure.postgres.landlord_override_enums import OverrideSource from infrastructure.postgres.landlord_property_type_override_postgres_repository import ( LandlordPropertyTypeOverridePostgresRepository, diff --git a/tests/repositories/landlord_overrides/postgres/test_landlord_wall_type_override_postgres_repository.py b/tests/repositories/landlord_overrides/postgres/test_landlord_wall_type_override_postgres_repository.py index 4cee6f5a..9504a520 100644 --- a/tests/repositories/landlord_overrides/postgres/test_landlord_wall_type_override_postgres_repository.py +++ b/tests/repositories/landlord_overrides/postgres/test_landlord_wall_type_override_postgres_repository.py @@ -14,7 +14,7 @@ import pytest from sqlalchemy import Engine from sqlmodel import Session, select -from domain.landlord_description_overrides.wall_type import WallType +from domain.epc.wall_type import WallType from infrastructure.postgres.landlord_override_enums import OverrideSource from infrastructure.postgres.landlord_wall_type_override_postgres_repository import ( LandlordWallTypeOverridePostgresRepository,