fixed roof tests

This commit is contained in:
Khalim Conn-Kowlessar 2024-01-19 17:42:03 +00:00
parent 43f3169e0c
commit 4608ac89a5
4 changed files with 68 additions and 51 deletions

View file

@ -68,7 +68,7 @@ class Property(Definitions):
self.in_conservation_area, self.is_listed, self.is_heritage = None, None, None
self.restricted_measures = False
self.year_built = epc_record.get("year_built")
self.number_of_rooms = epc_record.prepared_epc["number_heated_rooms"]
self.number_of_rooms = epc_record.prepared_epc.get("number_heated_rooms")
self.age_band = epc_record.get("age_band")
self.construction_age_band = epc_record.get("construction_age_band")
self.number_of_floors = epc_record.get("number_of_floors")
@ -81,7 +81,7 @@ class Property(Definitions):
"co2_emissions": epc_record.get("co2_emissions_current"),
}
self.ventilation = {
"ventilation": epc_record.prepared_epc["mechanical_ventilation"],
"ventilation": epc_record.prepared_epc.get("mechanical_ventilation"),
}
self.solar_pv = {
"solar_pv": epc_record.get("photo_supply"),
@ -91,29 +91,29 @@ class Property(Definitions):
"solar_hot_water_boolean": epc_record.get("solar_water_heating_flag_bool"),
}
self.wind_turbine = {
"wind_turbine": epc_record.prepared_epc["wind_turbine_count"],
"wind_turbine": epc_record.prepared_epc.get("wind_turbine_count"),
}
self.number_of_open_fireplaces = {
"number_of_open_fireplaces": epc_record.prepared_epc["number_open_fireplaces"],
"number_of_open_fireplaces": epc_record.prepared_epc.get("number_open_fireplaces"),
}
self.number_of_extensions = {
"number_of_extensions": epc_record.prepared_epc["extension_count"],
"number_of_extensions": epc_record.prepared_epc.get("extension_count"),
}
self.number_of_storeys = {
"number_of_storeys": epc_record.prepared_epc["flat_storey_count"],
"number_of_storeys": epc_record.prepared_epc.get("flat_storey_count"),
}
self.heat_loss_corridor = {
"heat_loss_corridor": epc_record.prepared_epc["heat_loss_corridor"],
"length": epc_record.prepared_epc["unheated_corridor_length"],
"heat_loss_corridor": epc_record.prepared_epc.get("heat_loss_corridor"),
"length": epc_record.prepared_epc.get("unheated_corridor_length"),
"heat_loss_corridor_boolean": epc_record.get("heat_loss_corridor_bool"),
}
self.mains_gas = epc_record.prepared_epc['mains_gas_flag']
self.floor_height = epc_record.prepared_epc['floor_height']
self.mains_gas = epc_record.prepared_epc.get('mains_gas_flag')
self.floor_height = epc_record.prepared_epc.get('floor_height')
self.insulation_wall_area = None
self.floor_area = epc_record.prepared_epc.get('total_floor_area')
self.pitched_roof_area = None
self.insulation_floor_area = None
self.number_lighting_outlets = epc_record.prepared_epc["fixed_lighting_outlets_count"]
self.number_lighting_outlets = epc_record.prepared_epc.get("fixed_lighting_outlets_count")
self.floor_level = None
self.number_of_windows = None
self.solar_pv_roof_area = None

View file

@ -1,16 +1,18 @@
from backend.Property import Property
from unittest.mock import Mock
from recommendations.FireplaceRecommendations import FireplaceRecommendations
from etl.epc.Record import EPCRecord
class TestFirepaceRecommendations:
def test_no_fireplaces(self):
property_instance = Property(id=0, address="fake", postcode="fake")
property_instance.data = {
"number-open-fireplaces": 0
epc_record = EPCRecord()
epc_record.prepared_epc = {
"number-open-fireplaces": 0,
}
property_instance = Property(id=0, address="fake", postcode="fake", epc_record=epc_record)
recommender = FireplaceRecommendations(
property_instance=property_instance
)
@ -22,10 +24,11 @@ class TestFirepaceRecommendations:
assert recommender.recommendation is None
def test_one_fireplace(self):
property_instance = Property(id=0, address="fake", postcode="fake")
property_instance.data = {
"number-open-fireplaces": 1
epc_record = EPCRecord()
epc_record.prepared_epc = {
"number-open-fireplaces": 1,
}
property_instance = Property(id=0, address="fake", postcode="fake", epc_record=epc_record)
recommender = FireplaceRecommendations(
property_instance=property_instance
@ -40,10 +43,11 @@ class TestFirepaceRecommendations:
assert recommender.recommendation[0]["total"] == 300
def test_multiple_fireplaces(self):
property_instance = Property(id=0, address="fake", postcode="fake")
property_instance.data = {
"number-open-fireplaces": 3
epc_record = EPCRecord()
epc_record.prepared_epc = {
"number-open-fireplaces": 3,
}
property_instance = Property(id=0, address="fake", postcode="fake", epc_record=epc_record)
recommender = FireplaceRecommendations(
property_instance=property_instance

View file

@ -1,5 +1,5 @@
import pytest
from unittest.mock import Mock
from etl.epc.Record import EPCRecord
from backend.Property import Property
from recommendations.LightingRecommendations import LightingRecommendations
@ -9,18 +9,20 @@ from recommendations.tests.test_data.materials import materials
class TestLightingRecommendations:
def test_init_invalid_materials(self):
input_property0 = Property(id=1, postcode="F4k3 6", address="623 fake street")
epc_record = EPCRecord()
epc_record.prepared_epc = {"county": "Greater London Authority"}
input_property0 = Property(id=1, postcode="F4k3 6", address="623 fake street", epc_record=epc_record)
input_property0.lighting = {"low_energy_proportion": 0}
input_property0.data = {"county": "Greater London Authority"}
# Test for invalid materials
with pytest.raises(ValueError):
LightingRecommendations(input_property0, [])
def test_recommend_no_action_needed(self):
# Case where no recommendation is needed
input_property1 = Property(id=1, postcode="F4k3 6", address="623 fake street")
epc_record = EPCRecord()
epc_record.prepared_epc = {"county": "Greater London Authority"}
input_property1 = Property(id=1, postcode="F4k3 6", address="623 fake street", epc_record=epc_record)
input_property1.lighting = {"low_energy_proportion": 100}
input_property1.data = {"county": "Greater London Authority"}
lr = LightingRecommendations(input_property1, materials)
lr.recommend()
@ -28,9 +30,9 @@ class TestLightingRecommendations:
def test_recommend_action_needed(self):
# Case where recommendation is needed
input_property1 = Property(id=1, postcode="F4k3 6", address="623 fake street")
input_property1.lighting = {"low_energy_proportion": 100}
input_property1.data = {"county": "Greater London Authority"}
epc_record = EPCRecord()
epc_record.prepared_epc = {"county": "Greater London Authority"}
input_property1 = Property(id=1, postcode="F4k3 6", address="623 fake street", epc_record=epc_record)
input_property1.lighting = {"low_energy_proportion": 0.80}
input_property1.number_lighting_outlets = 20

View file

@ -1,12 +1,17 @@
from backend.Property import Property
from recommendations.RoofRecommendations import RoofRecommendations
from recommendations.tests.test_data.materials import materials
from etl.epc.Record import EPCRecord
class TestRoofRecommendations:
def test_loft_insulation_recommendation_no_insulation(self):
property_instance = Property(id=0, address="fake", postcode="fake")
epc_record = EPCRecord()
epc_record.prepared_epc = {
"county": "Cambridgeshire",
}
property_instance = Property(id=0, address="fake", postcode="fake", epc_record=epc_record)
property_instance.age_band = "F"
property_instance.insulation_floor_area = 100
property_instance.roof = {
@ -18,9 +23,6 @@ class TestRoofRecommendations:
'is_at_rafters': False, 'is_assumed': True, 'has_dwelling_above': False, 'is_valid': True,
'insulation_thickness': 'none', 'roof_thermal_transmittance': None, 'roof_insulation_thickness': 'none'
}
property_instance.data = {
"county": "Cambridgeshire",
}
roof_recommender = RoofRecommendations(property_instance=property_instance, materials=materials)
@ -31,7 +33,9 @@ class TestRoofRecommendations:
assert len(roof_recommender.recommendations)
def test_loft_insulation_recommendation_50mm_insulation(self):
property_instance2 = Property(id=0, address="fake", postcode="fake")
epc_record = EPCRecord()
epc_record.prepared_epc = {"county": "Kent"}
property_instance2 = Property(id=0, address="fake", postcode="fake", epc_record=epc_record)
property_instance2.age_band = "F"
property_instance2.insulation_floor_area = 100
property_instance2.roof = {
@ -43,7 +47,6 @@ class TestRoofRecommendations:
'is_at_rafters': False, 'is_assumed': True, 'has_dwelling_above': False, 'is_valid': True,
'insulation_thickness': '50', 'roof_thermal_transmittance': None, 'roof_insulation_thickness': 'none'
}
property_instance2.data = {"county": "Kent"}
roof_recommender2 = RoofRecommendations(property_instance=property_instance2, materials=materials)
@ -57,7 +60,9 @@ class TestRoofRecommendations:
assert roof_recommender2.recommendations[0]["new_u_value"] == 0.14
assert roof_recommender2.recommendations[0]["starting_u_value"] == 0.68
property_instance3 = Property(id=0, address="fake", postcode="fake")
epc_record = EPCRecord()
epc_record.prepared_epc = {"county": "Greater London Authority"}
property_instance3 = Property(id=0, address="fake", postcode="fake", epc_record=epc_record)
property_instance3.age_band = "F"
property_instance3.insulation_floor_area = 100
property_instance3.roof = {
@ -69,7 +74,6 @@ class TestRoofRecommendations:
'is_at_rafters': False, 'is_assumed': True, 'has_dwelling_above': False, 'is_valid': True,
'insulation_thickness': '50', 'roof_thermal_transmittance': None, 'roof_insulation_thickness': 'none'
}
property_instance3.data = {"county": "Greater London Authority"}
roof_recommender3 = RoofRecommendations(property_instance=property_instance3, materials=materials)
@ -82,7 +86,9 @@ class TestRoofRecommendations:
assert roof_recommender3.recommendations[0]["parts"][0]["depth"] == 270
def test_loft_insulation_recommendation_150mm_insulation(self):
property_instance4 = Property(id=0, address="fake", postcode="fake")
epc_record = EPCRecord()
epc_record.prepared_epc = {"county": "North East Lincolnshire"}
property_instance4 = Property(id=0, address="fake", postcode="fake", epc_record=epc_record)
property_instance4.age_band = "F"
property_instance4.insulation_floor_area = 100
property_instance4.roof = {
@ -94,7 +100,6 @@ class TestRoofRecommendations:
'is_at_rafters': False, 'is_assumed': True, 'has_dwelling_above': False, 'is_valid': True,
'insulation_thickness': '150', 'roof_thermal_transmittance': None, 'roof_insulation_thickness': 'none'
}
property_instance4.data = {"county": "North East Lincolnshire"}
roof_recommender4 = RoofRecommendations(property_instance=property_instance4, materials=materials)
@ -109,7 +114,9 @@ class TestRoofRecommendations:
assert roof_recommender4.recommendations[0]["starting_u_value"] == 0.3
assert roof_recommender4.recommendations[0]["parts"][0]["depth"] == 150
property_instance5 = Property(id=0, address="fake", postcode="fake")
epc_record = EPCRecord()
epc_record.prepared_epc = {"county": "Somerset"}
property_instance5 = Property(id=0, address="fake", postcode="fake", epc_record=epc_record)
property_instance5.age_band = "F"
property_instance5.insulation_floor_area = 100
property_instance5.roof = {
@ -121,7 +128,6 @@ class TestRoofRecommendations:
'is_at_rafters': False, 'is_assumed': True, 'has_dwelling_above': False, 'is_valid': True,
'insulation_thickness': '150', 'roof_thermal_transmittance': None, 'roof_insulation_thickness': 'none'
}
property_instance5.data = {"county": "Somerset"}
roof_recommender5 = RoofRecommendations(property_instance=property_instance5, materials=materials)
@ -136,7 +142,9 @@ class TestRoofRecommendations:
def test_loft_insulation_recommendation_270mm_insulation(self):
# We shouldn't recommend anything in this case
property_instance6 = Property(id=0, address="fake", postcode="fake")
epc_record = EPCRecord()
epc_record.prepared_epc = {"county": "Portsmouth"}
property_instance6 = Property(id=0, address="fake", postcode="fake", epc_record=epc_record)
property_instance6.age_band = "F"
property_instance6.insulation_floor_area = 100
property_instance6.roof = {
@ -148,7 +156,6 @@ class TestRoofRecommendations:
'is_at_rafters': False, 'is_assumed': True, 'has_dwelling_above': False, 'is_valid': True,
'insulation_thickness': '270', 'roof_thermal_transmittance': None, 'roof_insulation_thickness': 'none'
}
property_instance6.data = {"county": "Portsmouth"}
roof_recommender6 = RoofRecommendations(property_instance=property_instance6, materials=materials)
@ -277,7 +284,9 @@ class TestRoofRecommendations:
# "Insulate your room roof with 270mm of Example room roof insulation"
def test_flat_no_insulation(self):
property_instance11 = Property(id=11, address="fake", postcode="fake")
epc_record = EPCRecord()
epc_record.prepared_epc = {"county": "Swindon"}
property_instance11 = Property(id=11, address="fake", postcode="fake", epc_record=epc_record)
property_instance11.age_band = "D"
property_instance11.insulation_floor_area = 33.5
property_instance11.perimeter = 24
@ -288,7 +297,6 @@ class TestRoofRecommendations:
'is_roof_room': False, 'is_loft': False, 'is_flat': True, 'is_thatched': False, 'is_at_rafters': False,
'is_assumed': True, 'has_dwelling_above': False, 'is_valid': True, 'insulation_thickness': 'none'
}
property_instance11.data = {"county": "Swindon"}
roof_recommender11 = RoofRecommendations(property_instance=property_instance11, materials=materials)
@ -306,7 +314,9 @@ class TestRoofRecommendations:
"Insulate the home's flat roof with 150mm of Ecotherm Eco-Versal General Purpose Insulation Board"
def test_flat_insulated(self):
property_instance12 = Property(id=12, address="fake", postcode="fake")
epc_record = EPCRecord()
epc_record.prepared_epc = {"county": "Thurrock"}
property_instance12 = Property(id=12, address="fake", postcode="fake", epc_record=epc_record)
property_instance12.age_band = "D"
property_instance12.insulation_floor_area = 40
property_instance12.perimeter = 30
@ -319,7 +329,6 @@ class TestRoofRecommendations:
'is_loft': False, 'is_flat': True, 'is_thatched': False, 'is_at_rafters': False, 'is_assumed': True,
'has_dwelling_above': False, 'is_valid': True, 'insulation_thickness': 'average'
}
property_instance12.data = {"county": "Thurrock"}
roof_recommender12 = RoofRecommendations(property_instance=property_instance12, materials=materials)
@ -330,7 +339,9 @@ class TestRoofRecommendations:
assert not roof_recommender12.recommendations
def test_flat_limited_insulation(self):
property_instance13 = Property(id=12, address="fake", postcode="fake")
epc_record = EPCRecord()
epc_record.prepared_epc = {"county": "Tyne and Wear"}
property_instance13 = Property(id=12, address="fake", postcode="fake", epc_record=epc_record)
property_instance13.age_band = "D"
property_instance13.insulation_floor_area = 40
property_instance13.perimeter = 40
@ -342,7 +353,6 @@ class TestRoofRecommendations:
'is_loft': False, 'is_flat': True, 'is_thatched': False, 'is_at_rafters': False, 'is_assumed': True,
'has_dwelling_above': False, 'is_valid': True, 'insulation_thickness': 'below average'
}
property_instance13.data = {"county": "Tyne and Wear"}
roof_recommender13 = RoofRecommendations(property_instance=property_instance13, materials=materials)
@ -362,7 +372,9 @@ class TestRoofRecommendations:
"Insulate the home's flat roof with 150mm of Ecotherm Eco-Versal General Purpose Insulation Board"
def test_property_above(self):
property_instance14 = Property(id=0, address="fake", postcode="fake")
epc_record = EPCRecord()
epc_record.prepared_epc = {"county": "Suffolk"}
property_instance14 = Property(id=0, address="fake", postcode="fake", epc_record=epc_record)
property_instance14.age_band = "F"
property_instance14.insulation_floor_area = 100
property_instance14.roof = {
@ -373,7 +385,6 @@ class TestRoofRecommendations:
'is_assumed': False, 'has_dwelling_above': True, 'is_valid': True,
'insulation_thickness': None
}
property_instance14.data = {"county": "Suffolk"}
roof_recommender14 = RoofRecommendations(property_instance=property_instance14, materials=materials)