-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtest_components.py
More file actions
224 lines (171 loc) · 5.52 KB
/
test_components.py
File metadata and controls
224 lines (171 loc) · 5.52 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import datetime
from web_poet import RequestUrl
from zyte_common_items import (
Address,
AggregateRating,
Amenity,
BaseSalary,
Breadcrumb,
BusinessPlaceMetadata,
Header,
HiringOrganization,
JobLocation,
JobPostingMetadata,
Link,
Metadata,
NamedLink,
OpeningHoursItem,
ParentPlace,
ProbabilityMetadata,
ProbabilityRequest,
Reactions,
RealEstateArea,
Request,
SocialMediaPostAuthor,
SocialMediaPostMetadata,
StarRating,
Url,
)
def test_aggregated_rating_optional_fields():
AggregateRating(bestRating=5.0)
AggregateRating(ratingValue=2.5)
AggregateRating(reviewCount=123)
def test_breadcrumb_optional_fields():
Breadcrumb(name="foo")
Breadcrumb(url="https://example.com")
def test_link_optional_fields():
Link(text="foo")
Link(url="https://example.com")
def test_metadata_default_values():
metadata = Metadata()
assert metadata.dateDownloaded is None
assert metadata.get_date_downloaded_parsed() is None
assert metadata.probability == 1.0
def test_metadata_get_date_downloaded():
metadata = Metadata(dateDownloaded="2024-04-11T15:06:02Z")
dt = metadata.get_date_downloaded_parsed()
assert dt == datetime.datetime(
year=2024,
month=4,
day=11,
hour=15,
minute=6,
second=2,
microsecond=0,
tzinfo=datetime.timezone.utc,
)
def test_named_link_optional_fields():
NamedLink(name="foo")
NamedLink(url="https://example.com")
def test_business_place_metadata_default_values():
metadata = BusinessPlaceMetadata()
assert metadata.dateDownloaded is None
assert metadata.probability == 1.0
assert metadata.searchText is None
def test_address():
Address(addressRaw="2440 Hoonani Rd, Koloa, HI 96756, US")
Address(streetAddress="2440 Hoonani Rd, Koloa, HI 96756")
Address(addressCity="Koloa")
Address(addressLocality="Poipu")
Address(addressRegion="Kauaʻi County")
Address(addressCountry="US")
Address(postalCode="96756")
Address(postalCodeAux="HI")
Address(latitude=21.8768183)
Address(longitude=-159.3620652)
def test_amenity():
Amenity(name="WiFi", value=True)
Amenity(name="WiFi", value=False)
def test_star_rating():
StarRating(raw="4-star hotel")
StarRating(ratingValue=4)
def test_parent_place():
ParentPlace(name="Gateway Plaza", placeId="ChIJCVDfcEKuEmsR7_zYc0_GBtQ")
def test_opening_hours():
OpeningHoursItem(dayOfWeek="Sunday", opens="9:00", closes="12:00")
def test_real_estate_area():
RealEstateArea(value=123.45, unitCode="SQMT", raw="123.45 square meters")
RealEstateArea(
value=123.45, unitCode="SQMT", raw="123.45 square meters", areaType="LOT"
)
def test_headers():
Header(name="Connection", value="keep-alive")
Header(name="Content-Type", value="text/html; charset=utf-8")
def test_probability_request():
ProbabilityRequest(url="https://example.com")
headers = [
Header(name="Content-Type", value="application/x-www-form-urlencoded"),
Header(name="Host", value="foo.example"),
]
request = ProbabilityRequest(
name="Post Test",
url="https://example.com/test",
method="POST",
body="ZmllbGQxPXZhbHVlMSZmaWVsZDI9dmFsdWUy",
headers=headers,
metadata=ProbabilityMetadata(probability=0.5),
)
assert request.get_probability() == 0.5
assert request.notes is None
request = ProbabilityRequest(
name="Get with RequestURL object",
url=RequestUrl("https://example.com/test"),
notes={"type": "test request", "id": 782},
)
assert request.url == "https://example.com/test"
assert request.get_probability() is None
assert request.notes == {"type": "test request", "id": 782}
def test_request():
Request(url="https://example.com")
headers = [
Header(name="Content-Type", value="application/x-www-form-urlencoded"),
Header(name="Host", value="foo.example"),
]
request = Request(
name="Post Test",
url="https://example.com/test",
method="POST",
body="ZmllbGQxPXZhbHVlMSZmaWVsZDI9dmFsdWUy",
headers=headers,
)
assert request.notes is None
request = Request(
name="Get with RequestURL object",
url=RequestUrl("https://example.com/test"),
notes={"type": "test request", "id": 782},
)
assert request.url == "https://example.com/test"
assert request.notes == {"type": "test request", "id": 782}
def test_job_location():
JobLocation(raw="New York, NY")
def test_base_salary():
BaseSalary(
raw="$53,000-$55,000 a year",
valueMin="53000",
valueMax="55000",
rateType="yearly",
currencyRaw="$",
currency="USD",
)
def test_hiring_organization():
HiringOrganization(name="Example Inc.", nameRaw="Example Inc. USA", id="12345")
def test_job_posting_metadata():
JobPostingMetadata(
dateDownloaded="2020-01-01", probability=0.5, searchText="Software Engineer"
)
def test_reactions():
Reactions(reposts=1, likes=2, dislikes=3)
def test_social_media_post_author():
SocialMediaPostAuthor(
numberOfFollowers=5,
numberOfFollowing=5,
dateAccountCreated="2020-01-01",
location="New York, NY",
isVerified=True,
)
def test_social_media_post_metadata():
SocialMediaPostMetadata(
dateDownloaded="2020-01-01", probability=0.5, searchText="Extract Summit"
)
def test_url():
Url(url="https://example.com")