fixed all tests

This commit is contained in:
Khalim Conn-Kowlessar 2024-01-19 19:44:38 +00:00
parent bbb4892437
commit 4adfa0bb62

View file

@ -1,9 +1,9 @@
import pandas as pd
import pytest
from unittest.mock import Mock
from epc_api.client import EpcClient
from backend.Property import Property
from etl.epc_clean.EpcClean import EpcClean
from etl.epc.Record import EPCRecord
# Define some test data
mock_epc_response = {
@ -196,12 +196,21 @@ class TestProperty:
@pytest.fixture(autouse=True)
def property_instance(self, mock_cleaner):
property_instance = Property(id=1, postcode="AB12CD", address="Test Address", data=mock_epc_response["rows"][0])
epc_record = EPCRecord()
epc_record.prepared_epc = mock_epc_response["rows"][0]
property_instance = Property(id=1, postcode="AB12CD", address="Test Address", epc_record=epc_record)
property_instance.number_of_floors = 2
property_instance.number_of_rooms = 5
property_instance.floor_area = 100
property_instance.floor_height = 2.5
return property_instance
@pytest.fixture(autouse=True)
def property_instance_dupe_data(self):
property_instance_dupe_data = Property(id=2, postcode="AB12CD", address="Test Address")
epc_record = EPCRecord()
epc_record.prepared_epc = mock_epc_response_dupe["rows"][0]
property_instance_dupe_data = Property(id=2, postcode="AB12CD", address="Test Address", epc_record=epc_record)
return property_instance_dupe_data
# @pytest.fixture
@ -271,15 +280,17 @@ class TestProperty:
return mock_cleaner
def test_init(self):
inst1 = Property(0, postcode="AB12CD", address="Test Address")
epc_record = EPCRecord()
epc_record.prepared_epc = {"uprn": 1}
inst1 = Property(0, postcode="AB12CD", address="Test Address", epc_record=epc_record)
assert inst1.data is None
assert inst1.data is not None
inst2 = Property(3, "AB12CD", "Test Address")
inst2 = Property(3, "AB12CD", "Test Address", epc_record=epc_record)
assert inst2.id == 3
inst3 = Property(4, "AB12CD", "Test Address", data={"some": "data", "uprn": 123})
assert inst3.data == {"some": "data", "uprn": 123}
inst3 = Property(4, "AB12CD", "Test Address", epc_record=epc_record)
assert inst3.data == {"uprn": 1}
def test_get_components(
self, property_instance, mock_cleaner, mock_photo_supply_lookup, mock_floor_area_decile_thresholds
@ -372,7 +383,9 @@ class TestProperty:
property_instance.get_components(cleaned, mock_photo_supply_lookup, mock_floor_area_decile_thresholds)
def test_set_spatial(self):
prop = Property(1, postcode="AB12CD", address="Test Address")
epc_record = EPCRecord()
epc_record.prepared_epc = mock_epc_response["rows"][0]
prop = Property(1, postcode="AB12CD", address="Test Address", epc_record=epc_record)
spatial1 = pd.DataFrame([{
'X_COORDINATE': 411143.0, 'Y_COORDINATE': 281701.0, 'LATITUDE': 52.4331896, 'LONGITUDE': -1.8375238,
@ -386,7 +399,7 @@ class TestProperty:
assert prop.is_heritage
assert prop.restricted_measures
prop2 = Property(1, "AB12CD", "Test Address")
prop2 = Property(1, "AB12CD", "Test Address", epc_record=epc_record)
spatial2 = pd.DataFrame([{
'X_COORDINATE': 411143.0, 'Y_COORDINATE': 281701.0, 'LATITUDE': 52.4331896, 'LONGITUDE': -1.8375238,
@ -403,8 +416,9 @@ class TestProperty:
def test_set_floor_level(self):
# In this case, we have a flat which looks looks it's on the first floor, but it's actually on the ground
# floor, so we should set floor_level to 0
prop = Property(1, postcode="AB12CD", address="Test Address")
prop.data = {'floor-level': '01', 'property-type': 'Flat'}
epc_record = EPCRecord()
epc_record.prepared_epc = {'floor-level': '01', 'property-type': 'Flat'}
prop = Property(1, postcode="AB12CD", address="Test Address", epc_record=epc_record)
prop.floor = {
'original_description': 'Solid, no insulation (assumed)', 'clean_description': 'Solid, no insulation',
'thermal_transmittance': None, 'thermal_transmittance_unit': None, 'is_assumed': True,
@ -419,8 +433,9 @@ class TestProperty:
# This property is labelled as being on the ground floor but actually has another property below
# so we set floor level to 1
prop2 = Property(1, postcode="AB12CD", address="Test Address")
prop2.data = {'floor-level': 'Ground', 'property-type': 'Flat'}
epc_record = EPCRecord()
epc_record.prepared_epc = {'floor-level': 'Ground', 'property-type': 'Flat'}
prop2 = Property(1, postcode="AB12CD", address="Test Address", epc_record=epc_record)
prop2.floor = {
'original_description': '(Another dwelling below)', 'clean_description': 'Solid, no insulation',
'thermal_transmittance': None, 'thermal_transmittance_unit': None, 'is_assumed': False,
@ -434,8 +449,9 @@ class TestProperty:
assert prop2.floor_level == 1
# this property is correctly labelled as being on the 2nd floor
prop3 = Property(1, postcode="AB12CD", address="Test Address")
prop3.data = {'floor-level': '02', 'property-type': 'Flat'}
epc_record = EPCRecord()
epc_record.prepared_epc = {'floor-level': '02', 'property-type': 'Flat'}
prop3 = Property(1, postcode="AB12CD", address="Test Address", epc_record=epc_record)
prop3.floor = {
'original_description': '(Another dwelling below)', 'clean_description': 'Solid, no insulation',
'thermal_transmittance': None, 'thermal_transmittance_unit': None, 'is_assumed': False,
@ -449,8 +465,9 @@ class TestProperty:
assert prop3.floor_level == 2
# Example of a house
prop4 = Property(1, postcode="AB12CD", address="Test Address")
prop4.data = {'floor-level': '', 'property-type': 'House'}
epc_record = EPCRecord()
epc_record.prepared_epc = {'floor-level': '', 'property-type': 'House'}
prop4 = Property(1, postcode="AB12CD", address="Test Address", epc_record=epc_record)
prop4.floor = {
'original_description': '(Another dwelling below)', 'clean_description': 'Solid, no insulation',
'thermal_transmittance': None, 'thermal_transmittance_unit': None, 'is_assumed': False,