def test_get_postal_code(api_client): with requests_mock.mock() as m: m.get( get_api_url("postcodes/7315AD"), text=read_file("single_postal_code.json"), ) data = api_client.get_postal_code(postal_code="7315AD") assert data["postcode"] == "7315AD"
def test_get_address(api_client): with requests_mock.mock() as m: m.get( get_api_url("addresses/0855200000046355"), text=read_file("single_address.json"), ) data = api_client.get_address(address_id="0855200000046355") assert data["postcode"] == "5038EA"
def test_get_all_postal_codes_area(api_client): with requests_mock.mock() as m: m.get( get_api_url("postcodes?postcodeArea=7313"), text=read_file("postal_code_list_area.json"), ) data = api_client.get_all_postal_codes(area="7313")["results"] assert data[0]["postcode"] == "7513AA"
def test_get_all_addresses_from_id(api_client): with requests_mock.mock() as m: m.get( get_api_url("addresses?from[id]=0503200000060096"), text=read_file("address_list_from_id.json"), ) data = api_client.get_all_addresses( from_id="0503200000060096")["results"] assert data[0]["id"] == "0553200000001332"
def test_get_all_addresses_with_postal_code_and_number(api_client): with requests_mock.mock() as m: m.get( get_api_url("addresses?postcode=6545CA&number=5"), text=read_file("address_list_postal_code_and_number.json"), ) data = api_client.get_all_addresses(postal_code="6545CA", number=5)["results"] assert data[0]["postcode"] == "6545CA" assert data[0]["number"] == 5
def test_get_all_postal_codes_from_postal_code(api_client): with requests_mock.mock() as m: m.get( get_api_url( "postcodes?from[postcode]=7315AA&from[postcodeArea]=7315"), text=read_file("postal_code_list_from_postal_code.json"), ) data = api_client.get_all_postal_codes( from_postal_code="7315AA")["results"] assert data[0]["postcode"] == "7315BB"
def test_get_all_addresses(api_client): with requests_mock.mock() as m: m.get(get_api_url("addresses"), text=read_file("address_list.json")) data = api_client.get_all_addresses(postal_code="5038EA")["results"] assert data[0]["postcode"] == "5038EA"
def test_get_all_postal_codes(api_client): with requests_mock.mock() as m: m.get(get_api_url("postcodes"), text=read_file("postal_code_list.json")) data = api_client.get_all_postal_codes()["results"] assert data[0]["postcode"] == "7315AA"
def test_get_postal_code_not_found(api_client): with pytest.raises(ResourceNotFoundException), requests_mock.mock() as m: m.get(get_api_url("postcodes/1234AB"), status_code=404) api_client.get_postal_code(postal_code="1234AB")