import pytest import os from backend.SearchEpc import SearchEpc # Replace with your actual module name from dotenv import load_dotenv load_dotenv(dotenv_path="backend/.env") EPC_AUTH_TOKEN = os.getenv("EPC_AUTH_TOKEN") class TestSearchEpcIntegration: @pytest.mark.parametrize( "address, postcode, uprn, skip_os, expected_partial_address", [ # Test case 1: Valid address and postcode, skipping OS # In this case, the property is an individual flat but the uprn associated to the # EPC is for the building as a whole, possibly because there was a conversion of sorts ("Garden Flat, 48 Bedminster Parade", "BS3 4HS", 308249, True, "260907a5431fa073d193cc6bbec51fbf1ba9a61845ab2503f85aa19ce3ed6afd", 1), # Test case 2: Another valid address and postcode # In this case, the newest EPC, does not have a uprn associated to it. If we did a search by # uprn, we would get an old EPC ("Flat 8, Hainton House", "DN32 9AQ", 10090082018, True, "bd1149a20a73397184f07a9955f872424826e70f4870c058d71be887766ee1f8", 3), ], ) def test_find_property(self, address, postcode, uprn, skip_os, lmk_key, n_old_epcs): """ Integration test for `find_property`, making actual API calls. """ # Provide your actual API keys or tokens here os_api_key = "" # Initialize the SearchEpc instance epc_searcher = SearchEpc( address1=address, postcode=postcode, uprn=uprn, auth_token=EPC_AUTH_TOKEN, os_api_key=os_api_key, ) # Execute the method epc_searcher.find_property(skip_os=skip_os) # We check that we have the correct epc assert epc_searcher.newest_epc["lmk-key"] == lmk_key assert epc_searcher.newest_epc["uprn"] == uprn assert len(epc_searcher.older_epcs) == n_old_epcs def test_search_housenumber(self): eg1 = 'Flat A11, Mortimer House, Grendon Road, Exeter' res1 = SearchEpc.get_house_number(eg1, None) assert res1 == "A11" eg2 = 'Flat A9, Mortimer House, Grendon Road, Exeter, EX1 2NL' res2 = SearchEpc.get_house_number(eg2, None) assert res2 == "A9"