mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
62 lines
2 KiB
Python
62 lines
2 KiB
Python
import pytest
|
|
from unittest.mock import Mock
|
|
from epc_api.client import EpcClient
|
|
from model_data.Property import Property
|
|
|
|
# Define some test data
|
|
mock_epc_response = {
|
|
"rows": [
|
|
{
|
|
"inspection-date": "2023-06-01",
|
|
"some-other-key": "some-value",
|
|
# add other keys as necessary
|
|
},
|
|
{
|
|
"inspection-date": "2023-05-01",
|
|
"some-other-key": "some-other-value",
|
|
# add other keys as necessary
|
|
}
|
|
]
|
|
}
|
|
|
|
# Create a mock EPC client
|
|
mock_client = Mock(spec=EpcClient())
|
|
mock_client.domestic.search.return_value = mock_epc_response
|
|
mock_client.auth_token = "mocked_auth_token"
|
|
|
|
|
|
class TestProperty:
|
|
@pytest.fixture
|
|
def property_instance(self):
|
|
return Property("AB12CD", "Test Address", epc_client=mock_client)
|
|
|
|
def test_init(self):
|
|
inst1 = Property("AB12CD", "Test Address", epc_client=mock_client)
|
|
# Should be mocked auth token
|
|
assert inst1.epc_client.auth_token == "mocked_auth_token"
|
|
|
|
inst2 = Property("AB12CD", "Test Address")
|
|
assert inst2.epc_client.auth_token
|
|
|
|
inst3 = Property("AB12CD", "Test Address", data={"some": "data"})
|
|
assert inst3.data == {"some": "data"}
|
|
|
|
data = inst3.search_address_epc()
|
|
assert data is None
|
|
|
|
def test_search_address_epc(self, property_instance):
|
|
# Call the method to test
|
|
property_instance.search_address_epc()
|
|
|
|
# Verify that the correct data is being returned
|
|
assert property_instance.data == mock_epc_response["rows"][0]
|
|
|
|
def test_search_address_epc_multiple_results(self, property_instance):
|
|
# Modify the mock response to return two results with the same date
|
|
mock_epc_response["rows"].append({
|
|
"inspection-date": "2023-06-01",
|
|
"some-other-key": "duplicate-date"
|
|
})
|
|
|
|
with pytest.raises(Exception, match="More than one result found for this address - investigate me"):
|
|
property_instance.search_address_epc()
|