2023-09-15 20:58:54 -07:00
|
|
|
from homeharvest import scrape_property
|
|
|
|
|
|
|
|
|
2023-10-04 18:25:01 -07:00
|
|
|
def test_realtor_pending_or_contingent():
|
2024-04-16 12:55:44 -07:00
|
|
|
pending_or_contingent_result = scrape_property(location="Surprise, AZ", listing_type="pending")
|
2023-10-04 18:25:01 -07:00
|
|
|
|
2024-05-31 22:17:29 -07:00
|
|
|
regular_result = scrape_property(location="Surprise, AZ", listing_type="for_sale", exclude_pending=True)
|
2023-10-04 18:25:01 -07:00
|
|
|
|
2024-04-16 12:55:44 -07:00
|
|
|
assert all([result is not None for result in [pending_or_contingent_result, regular_result]])
|
2023-10-04 18:25:01 -07:00
|
|
|
assert len(pending_or_contingent_result) != len(regular_result)
|
|
|
|
|
|
|
|
|
2023-10-05 11:43:00 -07:00
|
|
|
def test_realtor_pending_comps():
|
|
|
|
pending_comps = scrape_property(
|
|
|
|
location="2530 Al Lipscomb Way",
|
|
|
|
radius=5,
|
|
|
|
past_days=180,
|
|
|
|
listing_type="pending",
|
|
|
|
)
|
|
|
|
|
|
|
|
for_sale_comps = scrape_property(
|
|
|
|
location="2530 Al Lipscomb Way",
|
|
|
|
radius=5,
|
|
|
|
past_days=180,
|
|
|
|
listing_type="for_sale",
|
|
|
|
)
|
|
|
|
|
|
|
|
sold_comps = scrape_property(
|
|
|
|
location="2530 Al Lipscomb Way",
|
|
|
|
radius=5,
|
|
|
|
past_days=180,
|
|
|
|
listing_type="sold",
|
|
|
|
)
|
|
|
|
|
|
|
|
results = [pending_comps, for_sale_comps, sold_comps]
|
|
|
|
assert all([result is not None for result in results])
|
|
|
|
|
|
|
|
#: assert all lengths are different
|
|
|
|
assert len(set([len(result) for result in results])) == len(results)
|
|
|
|
|
|
|
|
|
2023-10-18 16:32:43 -07:00
|
|
|
def test_realtor_sold_past():
|
|
|
|
result = scrape_property(
|
|
|
|
location="San Diego, CA",
|
|
|
|
past_days=30,
|
|
|
|
listing_type="sold",
|
|
|
|
)
|
|
|
|
|
|
|
|
assert result is not None and len(result) > 0
|
|
|
|
|
|
|
|
|
2023-10-02 13:58:47 -07:00
|
|
|
def test_realtor_comps():
|
|
|
|
result = scrape_property(
|
2023-10-04 08:11:53 -07:00
|
|
|
location="2530 Al Lipscomb Way",
|
|
|
|
radius=0.5,
|
2023-10-04 21:35:14 -07:00
|
|
|
past_days=180,
|
2023-10-04 08:11:53 -07:00
|
|
|
listing_type="sold",
|
2023-10-02 13:58:47 -07:00
|
|
|
)
|
|
|
|
|
2023-10-03 15:05:17 -07:00
|
|
|
assert result is not None and len(result) > 0
|
|
|
|
|
|
|
|
|
|
|
|
def test_realtor_last_x_days_sold():
|
2024-04-16 12:55:44 -07:00
|
|
|
days_result_30 = scrape_property(location="Dallas, TX", listing_type="sold", past_days=30)
|
2023-10-03 15:05:17 -07:00
|
|
|
|
2024-04-16 12:55:44 -07:00
|
|
|
days_result_10 = scrape_property(location="Dallas, TX", listing_type="sold", past_days=10)
|
2023-10-03 15:05:17 -07:00
|
|
|
|
2024-04-16 12:55:44 -07:00
|
|
|
assert all([result is not None for result in [days_result_30, days_result_10]]) and len(days_result_30) != len(
|
|
|
|
days_result_10
|
|
|
|
)
|
2023-10-02 13:58:47 -07:00
|
|
|
|
|
|
|
|
2023-11-03 16:35:41 -07:00
|
|
|
def test_realtor_date_range_sold():
|
|
|
|
days_result_30 = scrape_property(
|
|
|
|
location="Dallas, TX", listing_type="sold", date_from="2023-05-01", date_to="2023-05-28"
|
|
|
|
)
|
|
|
|
|
|
|
|
days_result_60 = scrape_property(
|
|
|
|
location="Dallas, TX", listing_type="sold", date_from="2023-04-01", date_to="2023-06-10"
|
|
|
|
)
|
|
|
|
|
2024-04-16 12:55:44 -07:00
|
|
|
assert all([result is not None for result in [days_result_30, days_result_60]]) and len(days_result_30) < len(
|
|
|
|
days_result_60
|
|
|
|
)
|
2023-11-03 16:35:41 -07:00
|
|
|
|
|
|
|
|
2023-10-03 23:33:53 -07:00
|
|
|
def test_realtor_single_property():
|
|
|
|
results = [
|
|
|
|
scrape_property(
|
|
|
|
location="15509 N 172nd Dr, Surprise, AZ 85388",
|
|
|
|
listing_type="for_sale",
|
|
|
|
),
|
|
|
|
scrape_property(
|
|
|
|
location="2530 Al Lipscomb Way",
|
|
|
|
listing_type="for_sale",
|
2023-10-04 08:11:53 -07:00
|
|
|
),
|
2023-10-03 23:33:53 -07:00
|
|
|
]
|
|
|
|
|
|
|
|
assert all([result is not None for result in results])
|
|
|
|
|
|
|
|
|
2023-09-15 20:58:54 -07:00
|
|
|
def test_realtor():
|
2023-09-16 13:39:03 -07:00
|
|
|
results = [
|
2023-09-18 13:43:44 -07:00
|
|
|
scrape_property(
|
|
|
|
location="2530 Al Lipscomb Way",
|
|
|
|
listing_type="for_sale",
|
|
|
|
),
|
2024-11-03 15:23:07 -08:00
|
|
|
scrape_property(
|
|
|
|
location="Phoenix, AZ", listing_type="for_rent", limit=1000
|
|
|
|
), #: does not support "city, state, USA" format
|
|
|
|
scrape_property(
|
|
|
|
location="Dallas, TX", listing_type="sold", limit=1000
|
|
|
|
), #: does not support "city, state, USA" format
|
2023-10-03 22:21:16 -07:00
|
|
|
scrape_property(location="85281"),
|
2023-09-16 13:39:03 -07:00
|
|
|
]
|
2023-09-15 20:58:54 -07:00
|
|
|
|
2023-09-16 13:39:03 -07:00
|
|
|
assert all([result is not None for result in results])
|
2023-09-18 20:28:03 -07:00
|
|
|
|
2023-11-03 16:35:41 -07:00
|
|
|
|
2024-03-06 15:31:06 -08:00
|
|
|
def test_realtor_city():
|
2024-11-03 15:23:07 -08:00
|
|
|
results = scrape_property(location="Atlanta, GA", listing_type="for_sale", limit=1000)
|
|
|
|
|
|
|
|
assert results is not None and len(results) > 0
|
|
|
|
|
|
|
|
|
|
|
|
def test_realtor_land():
|
|
|
|
results = scrape_property(location="Atlanta, GA", listing_type="for_sale", property_type=["land"], limit=1000)
|
2024-03-06 15:31:06 -08:00
|
|
|
|
|
|
|
assert results is not None and len(results) > 0
|
|
|
|
|
|
|
|
|
2023-11-03 16:35:41 -07:00
|
|
|
def test_realtor_bad_address():
|
|
|
|
bad_results = scrape_property(
|
2024-04-16 12:55:44 -07:00
|
|
|
location="abceefg ju098ot498hh9",
|
|
|
|
listing_type="for_sale",
|
|
|
|
)
|
2024-09-06 15:49:07 -07:00
|
|
|
|
2023-11-03 16:35:41 -07:00
|
|
|
if len(bad_results) == 0:
|
2023-09-18 20:28:03 -07:00
|
|
|
assert True
|
|
|
|
|
2024-03-03 09:45:28 -08:00
|
|
|
|
|
|
|
def test_realtor_foreclosed():
|
2024-04-16 12:55:44 -07:00
|
|
|
foreclosed = scrape_property(location="Dallas, TX", listing_type="for_sale", past_days=100, foreclosure=True)
|
2024-03-03 09:45:28 -08:00
|
|
|
|
2024-04-16 12:55:44 -07:00
|
|
|
not_foreclosed = scrape_property(location="Dallas, TX", listing_type="for_sale", past_days=100, foreclosure=False)
|
2024-03-03 09:45:28 -08:00
|
|
|
|
|
|
|
assert len(foreclosed) != len(not_foreclosed)
|
|
|
|
|
2024-04-16 12:55:44 -07:00
|
|
|
|
|
|
|
def test_realtor_agent():
|
2024-08-20 05:19:15 -07:00
|
|
|
scraped = scrape_property(location="Detroit, MI", listing_type="for_sale", limit=1000, extra_property_data=False)
|
|
|
|
assert scraped["agent_name"].nunique() > 1
|
2024-05-02 09:04:49 -07:00
|
|
|
|
|
|
|
|
|
|
|
def test_realtor_without_extra_details():
|
|
|
|
results = [
|
|
|
|
scrape_property(
|
2024-08-20 05:19:15 -07:00
|
|
|
location="00741",
|
|
|
|
listing_type="sold",
|
|
|
|
limit=10,
|
2024-05-02 09:04:49 -07:00
|
|
|
extra_property_data=False,
|
|
|
|
),
|
|
|
|
scrape_property(
|
2024-08-20 05:19:15 -07:00
|
|
|
location="00741",
|
|
|
|
listing_type="sold",
|
|
|
|
limit=10,
|
|
|
|
extra_property_data=True,
|
2024-05-02 09:04:49 -07:00
|
|
|
),
|
|
|
|
]
|
|
|
|
|
2024-05-14 19:13:04 -07:00
|
|
|
assert not results[0].equals(results[1])
|
2024-05-12 18:49:44 -07:00
|
|
|
|
|
|
|
|
|
|
|
def test_pr_zip_code():
|
|
|
|
results = scrape_property(
|
|
|
|
location="00741",
|
|
|
|
listing_type="for_sale",
|
|
|
|
)
|
|
|
|
|
|
|
|
assert results is not None and len(results) > 0
|
2024-05-31 22:17:29 -07:00
|
|
|
|
|
|
|
|
|
|
|
def test_exclude_pending():
|
|
|
|
results = scrape_property(
|
|
|
|
location="33567",
|
|
|
|
listing_type="pending",
|
|
|
|
exclude_pending=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert results is not None and len(results) > 0
|
2024-06-06 15:24:12 -07:00
|
|
|
|
|
|
|
|
|
|
|
def test_style_value_error():
|
|
|
|
results = scrape_property(
|
|
|
|
location="Alaska, AK",
|
|
|
|
listing_type="sold",
|
|
|
|
extra_property_data=False,
|
2024-08-13 10:44:11 -07:00
|
|
|
limit=1000,
|
2024-06-06 15:24:12 -07:00
|
|
|
)
|
|
|
|
|
2024-08-13 10:44:11 -07:00
|
|
|
assert results is not None and len(results) > 0
|
|
|
|
|
|
|
|
|
|
|
|
def test_primary_image_error():
|
|
|
|
results = scrape_property(
|
|
|
|
location="Spokane, PA",
|
|
|
|
listing_type="for_rent", # or (for_sale, for_rent, pending)
|
|
|
|
past_days=360,
|
|
|
|
radius=3,
|
|
|
|
extra_property_data=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert results is not None and len(results) > 0
|
|
|
|
|
|
|
|
|
|
|
|
def test_limit():
|
|
|
|
over_limit = 876
|
|
|
|
extra_params = {"limit": over_limit}
|
|
|
|
|
|
|
|
over_results = scrape_property(
|
|
|
|
location="Waddell, AZ",
|
|
|
|
listing_type="for_sale",
|
|
|
|
**extra_params,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert over_results is not None and len(over_results) <= over_limit
|
|
|
|
|
|
|
|
under_limit = 1
|
|
|
|
under_results = scrape_property(
|
|
|
|
location="Waddell, AZ",
|
|
|
|
listing_type="for_sale",
|
|
|
|
limit=under_limit,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert under_results is not None and len(under_results) == under_limit
|
|
|
|
|
|
|
|
|
|
|
|
def test_apartment_list_price():
|
|
|
|
results = scrape_property(
|
|
|
|
location="Spokane, WA",
|
|
|
|
listing_type="for_rent", # or (for_sale, for_rent, pending)
|
|
|
|
extra_property_data=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert results is not None
|
|
|
|
|
|
|
|
results = results[results["style"] == "APARTMENT"]
|
|
|
|
|
|
|
|
#: get percentage of results with atleast 1 of any column not none, list_price, list_price_min, list_price_max
|
2024-11-03 15:23:07 -08:00
|
|
|
assert (
|
|
|
|
len(results[results[["list_price", "list_price_min", "list_price_max"]].notnull().any(axis=1)]) / len(results)
|
|
|
|
> 0.5
|
|
|
|
)
|
2024-08-23 10:47:45 -07:00
|
|
|
|
|
|
|
|
|
|
|
def test_builder_exists():
|
|
|
|
listing = scrape_property(
|
|
|
|
location="18149 W Poston Dr, Surprise, AZ 85387",
|
|
|
|
extra_property_data=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert listing is not None
|
|
|
|
assert listing["builder_name"].nunique() > 0
|
2024-09-06 15:49:07 -07:00
|
|
|
|
|
|
|
|
|
|
|
def test_phone_number_matching():
|
|
|
|
searches = [
|
|
|
|
scrape_property(
|
|
|
|
location="Phoenix, AZ",
|
|
|
|
listing_type="for_sale",
|
|
|
|
limit=100,
|
|
|
|
),
|
|
|
|
scrape_property(
|
|
|
|
location="Phoenix, AZ",
|
|
|
|
listing_type="for_sale",
|
|
|
|
limit=100,
|
|
|
|
),
|
|
|
|
]
|
|
|
|
|
|
|
|
assert all([search is not None for search in searches])
|
|
|
|
|
|
|
|
#: random row
|
|
|
|
row = searches[0][searches[0]["agent_phones"].notnull()].sample()
|
|
|
|
|
|
|
|
#: find matching row
|
|
|
|
matching_row = searches[1].loc[searches[1]["property_url"] == row["property_url"].values[0]]
|
|
|
|
|
|
|
|
#: assert phone numbers are the same
|
|
|
|
assert row["agent_phones"].values[0] == matching_row["agent_phones"].values[0]
|