-
Notifications
You must be signed in to change notification settings - Fork 115
/
test_rm.py
116 lines (102 loc) · 4.36 KB
/
test_rm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import pandas as pd
import pytest
from rightmove_webscraper import RightmoveData
base_url = "https://www.rightmove.co.uk/"
required_columns = {"address", "agent_url", "number_bedrooms", "postcode", "price", "search_date", "type", "url"}
def test_sale_residential():
"""Test a search on residential properties for sale."""
url = f"{base_url}property-for-sale/find.html?searchType=SALE&locationIdentifier=REGION%5E94346&insId=1"
rm = RightmoveData(url)
assert isinstance(rm.average_price, float)
assert isinstance(rm.get_results, pd.DataFrame)
assert required_columns.issubset(set(rm.get_results.columns))
assert len(rm.get_results) > 0
assert isinstance(rm.page_count, int)
assert rm.rent_or_sale == "sale"
assert isinstance(rm.results_count, int)
assert isinstance(rm.results_count_display, int)
assert url == rm.url
df = rm.summary()
assert isinstance(df, pd.DataFrame)
assert {"number_bedrooms", "count", "mean"}.issubset(set(df.columns))
assert len(df) > 0
for c in required_columns:
df = rm.summary(by=c)
assert isinstance(df, pd.DataFrame)
assert {c, "count", "mean"}.issubset(set(df.columns))
assert len(df) > 0
def test_rent_residential():
"""Test a search on residential properties for rent."""
url = f"{base_url}property-to-rent/find.html?searchType=RENT&locationIdentifier=REGION%5E94346"
rm = RightmoveData(url)
assert isinstance(rm.average_price, float)
assert isinstance(rm.get_results, pd.DataFrame)
assert required_columns.issubset(set(rm.get_results.columns))
assert len(rm.get_results) > 0
assert isinstance(rm.page_count, int)
assert rm.rent_or_sale == "rent"
assert isinstance(rm.results_count, int)
assert isinstance(rm.results_count_display, int)
assert url == rm.url
df = rm.summary()
assert isinstance(df, pd.DataFrame)
assert {"number_bedrooms", "count", "mean"}.issubset(set(df.columns))
assert len(df) > 0
for c in required_columns:
df = rm.summary(by=c)
assert isinstance(df, pd.DataFrame)
assert {c, "count", "mean"}.issubset(set(df.columns))
assert len(df) > 0
def test_sale_commercial():
"""Test a search on commercial properties for sale."""
url = f"{base_url}commercial-property-for-sale/find.html?searchType=SALE&locationIdentifier=REGION%5E70417"
rm = RightmoveData(url)
assert isinstance(rm.average_price, float)
assert isinstance(rm.get_results, pd.DataFrame)
assert required_columns.issubset(set(rm.get_results.columns))
assert len(rm.get_results) > 0
assert isinstance(rm.page_count, int)
assert rm.rent_or_sale == "sale-commercial"
assert isinstance(rm.results_count, int)
assert isinstance(rm.results_count_display, int)
assert url == rm.url
df = rm.summary()
assert isinstance(df, pd.DataFrame)
assert {"type", "count", "mean"}.issubset(set(df.columns))
assert len(df) > 0
for c in required_columns:
if c == "number_bedrooms":
continue
df = rm.summary(by=c)
assert isinstance(df, pd.DataFrame)
assert {c, "count", "mean"}.issubset(set(df.columns))
assert len(df) > 0
def test_rent_commercial():
"""Test a search on commercial properties for rent."""
url = f"{base_url}commercial-property-to-let/find.html?searchType=RENT&locationIdentifier=REGION%5E70417"
rm = RightmoveData(url)
assert isinstance(rm.average_price, float)
assert isinstance(rm.get_results, pd.DataFrame)
assert required_columns.issubset(set(rm.get_results.columns))
assert len(rm.get_results) > 0
assert isinstance(rm.page_count, int)
assert rm.rent_or_sale == "rent-commercial"
assert isinstance(rm.results_count, int)
assert isinstance(rm.results_count_display, int)
assert url == rm.url
df = rm.summary()
assert isinstance(df, pd.DataFrame)
assert {"type", "count", "mean"}.issubset(set(df.columns))
assert len(df) > 0
for c in required_columns:
if c == "number_bedrooms":
continue
df = rm.summary(by=c)
assert isinstance(df, pd.DataFrame)
assert {c, "count", "mean"}.issubset(set(df.columns))
assert len(df) > 0
def test_bad_url():
"""Test a bad URL raises a value error."""
bad_url = "https://www.rightmove.co.uk/property"
with pytest.raises(ValueError):
_ = RightmoveData(bad_url)