Model/recommendations/tests/test_lighting_recommendations.py
2024-10-07 11:03:52 +01:00

58 lines
2.7 KiB
Python

import pytest
from etl.epc.Record import EPCRecord
from backend.Property import Property
from recommendations.LightingRecommendations import LightingRecommendations
from recommendations.tests.test_data.materials import materials
class TestLightingRecommendations:
def test_init_invalid_materials(self):
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}
# Test for invalid materials
with pytest.raises(ValueError):
LightingRecommendations(input_property0, [])
def test_recommend_no_action_needed(self):
# Case where no recommendation is needed
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}
lr = LightingRecommendations(input_property1, materials)
lr.recommend()
assert lr.recommendation == []
def test_recommend_action_needed(self):
# Case where recommendation is needed
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
lr = LightingRecommendations(input_property1, materials)
lr.recommend()
assert len(lr.recommendation) == 1
assert lr.recommendation == [
{
'phase': 0, 'parts': [], 'type': 'low_energy_lighting', 'measure_type': 'low_energy_lighting',
'description': 'Install low energy lighting in 4 outlets', 'starting_u_value': None,
'new_u_value': None,
'already_installed': False, 'sap_points': 0.4, 'kwh_savings': 219.0, 'co2_equivalent_savings': 0.035478,
'description_simulation': {
'lighting-energy-eff': 'Very Good',
'lighting-description': 'Low energy lighting in all fixed outlets',
'low-energy-lighting': 100
},
'total': 240.24, 'subtotal': 200.20000000000002,
'vat': 40.040000000000006, 'contingency': 14.3, 'preliminaries': 14.3, 'material': 80.0, 'profit': 28.6,
'labour_hours': 3.2, 'labour_days': 0.4, 'labour_cost': 63.0, 'survey': False
}
]