mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-12 13:29:04 +00:00
Added unit tests for property
This commit is contained in:
parent
3847331e9d
commit
0e9f43e3c8
1 changed files with 62 additions and 0 deletions
62
epc_data/tests/test_property.py
Normal file
62
epc_data/tests/test_property.py
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
import pytest
|
||||||
|
from unittest.mock import Mock
|
||||||
|
from epc_api.client import EpcClient
|
||||||
|
from epc_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 Non
|
||||||
|
|
||||||
|
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()
|
||||||
Loading…
Add table
Reference in a new issue