import json import os import pytest from backend.documents_parser.extractor import PasHubRdSapSiteNotesExtractor from datatypes.epc.surveys.pashub_rdsap_site_notes import ( BuildingConstruction, ExtensionConstruction, FloorConstruction, General, MainBuildingConstruction, PasHubRdSapSiteNotes, ) FIXTURES = os.path.join(os.path.dirname(__file__), "fixtures") def load_text_fixture() -> list[str]: with open(os.path.join(FIXTURES, "site_notes_example_text.json")) as f: return json.load(f) class TestGeneral: @pytest.fixture def general(self) -> General: return PasHubRdSapSiteNotesExtractor(load_text_fixture()).extract_general() def test_epc_checked_before_assessment(self, general: General) -> None: assert general.epc_checked_before_assessment is True def test_epc_exists_at_point_of_assessment(self, general: General) -> None: 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" def test_transaction_type(self, general: General) -> None: assert general.transaction_type == "Grant-Scheme (ECO, RHI, etc.)" def test_tenure(self, general: General) -> None: assert general.tenure == "Rented Social" def test_property_type(self, general: General) -> None: assert general.property_type == "House" def test_detachment_type(self, general: General) -> None: assert general.detachment_type == "Mid-terrace" def test_number_of_storeys(self, general: General) -> None: assert general.number_of_storeys == 2 def test_number_of_extensions(self, general: General) -> None: assert general.number_of_extensions == 1 def test_electricity_smart_meter(self, general: General) -> None: assert general.electricity_smart_meter is True def test_mains_gas_available(self, general: General) -> None: assert general.mains_gas_available is True def test_measurements_location(self, general: General) -> None: assert general.measurements_location == "Internal" def test_full_general(self, general: General) -> None: assert general == General( epc_checked_before_assessment=True, epc_exists_at_point_of_assessment=False, inspection_date="2025-09-25", transaction_type="Grant-Scheme (ECO, RHI, etc.)", tenure="Rented Social", property_type="House", detachment_type="Mid-terrace", number_of_storeys=2, terrain_type="Suburban", number_of_extensions=1, electricity_smart_meter=True, electric_meter_type="Single", dwelling_export_capable=True, mains_gas_available=True, gas_smart_meter=True, gas_meter_accessible=True, measurements_location="Internal", ) class TestBuildingConstruction: @pytest.fixture def construction(self) -> BuildingConstruction: return PasHubRdSapSiteNotesExtractor( load_text_fixture() ).extract_building_construction() def test_main_building_wall_u_value_known_is_false( self, construction: BuildingConstruction ) -> None: assert construction.main_building.wall_u_value_known is False def test_main_building_wall_thickness_mm( self, construction: BuildingConstruction ) -> None: assert construction.main_building.wall_thickness_mm == 310 def test_main_building_filled_cavity_indicators_present( self, construction: BuildingConstruction ) -> None: assert ( construction.main_building.filled_cavity_indicators == "evidence of cavity fill drill holes" ) def test_extension_filled_cavity_indicators_absent( self, construction: BuildingConstruction ) -> None: assert construction.extensions is not None assert construction.extensions[0].filled_cavity_indicators is None def test_one_extension(self, construction: BuildingConstruction) -> None: assert construction.extensions is not None assert len(construction.extensions) == 1 def test_extension_id(self, construction: BuildingConstruction) -> None: assert construction.extensions is not None assert construction.extensions[0].id == 1 def test_full_building_construction( self, construction: BuildingConstruction ) -> None: assert construction == BuildingConstruction( main_building=MainBuildingConstruction( age_range="1950-1966", age_indicators="local knowledge, enquiries of owner", walls_construction_type="Cavity", cavity_construction_indicators="wall thickness over 270 mm", walls_insulation_type="Filled Cavity", filled_cavity_indicators="evidence of cavity fill drill holes", thermal_conductivity_of_wall_insulation="Unknown", wall_u_value_known=False, wall_thickness_mm=310, party_wall_construction_type="Cavity Masonry, Filled", ), floor=FloorConstruction( floor_type="Ground Floor", floor_construction="Solid", floor_insulation_type="As Built", floor_u_value_known=False, ), extensions=[ ExtensionConstruction( id=1, age_range="2003-2006", age_indicators="local knowledge, enquiries of owner", walls_construction_type="Cavity", cavity_construction_indicators="wall thickness over 270 mm", walls_insulation_type="As built", thermal_conductivity_of_wall_insulation="Unknown", wall_u_value_known=False, wall_thickness_mm=310, party_wall_construction_type="Cavity Masonry, Filled", filled_cavity_indicators=None, ) ], )