2023-09-15 20:58:54 -07:00
|
|
|
from homeharvest import scrape_property
|
2023-09-18 20:59:49 -07:00
|
|
|
from homeharvest.exceptions import (
|
|
|
|
InvalidListingType,
|
|
|
|
NoResultsFound,
|
|
|
|
)
|
2023-09-15 20:58:54 -07:00
|
|
|
|
|
|
|
|
2023-10-04 18:25:01 -07:00
|
|
|
def test_realtor_pending_or_contingent():
|
|
|
|
pending_or_contingent_result = scrape_property(
|
|
|
|
location="Surprise, AZ",
|
|
|
|
pending_or_contingent=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
regular_result = scrape_property(
|
|
|
|
location="Surprise, AZ",
|
|
|
|
pending_or_contingent=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert all([result is not None for result in [pending_or_contingent_result, regular_result]])
|
|
|
|
assert len(pending_or_contingent_result) != len(regular_result)
|
|
|
|
|
|
|
|
|
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 18:06:06 -07:00
|
|
|
property_younger_than=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():
|
|
|
|
days_result_30 = scrape_property(
|
2023-10-04 18:06:06 -07:00
|
|
|
location="Dallas, TX", listing_type="sold", property_younger_than=30
|
2023-10-03 15:05:17 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
days_result_10 = scrape_property(
|
2023-10-04 18:06:06 -07:00
|
|
|
location="Dallas, TX", listing_type="sold", property_younger_than=10
|
2023-10-03 15:05:17 -07:00
|
|
|
)
|
|
|
|
|
2023-10-04 08:11:53 -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-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",
|
|
|
|
),
|
|
|
|
scrape_property(
|
2023-10-03 22:21:16 -07:00
|
|
|
location="Phoenix, AZ", listing_type="for_rent"
|
2023-09-18 13:43:44 -07:00
|
|
|
), #: does not support "city, state, USA" format
|
|
|
|
scrape_property(
|
2023-10-03 22:21:16 -07:00
|
|
|
location="Dallas, TX", listing_type="sold"
|
2023-09-18 13:43:44 -07:00
|
|
|
), #: 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
|
|
|
|
|
|
|
bad_results = []
|
|
|
|
try:
|
|
|
|
bad_results += [
|
|
|
|
scrape_property(
|
|
|
|
location="abceefg ju098ot498hh9",
|
|
|
|
listing_type="for_sale",
|
|
|
|
)
|
|
|
|
]
|
2023-10-04 12:04:05 -07:00
|
|
|
except (InvalidListingType, NoResultsFound):
|
2023-09-18 20:28:03 -07:00
|
|
|
assert True
|
|
|
|
|
|
|
|
assert all([result is None for result in bad_results])
|