-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathtest.py
68 lines (61 loc) · 2.26 KB
/
test.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
from cerberus import Validator
import pytest
import indeed
# enable cache?
indeed.BASE_CONFIG["cache"] = True
@pytest.mark.asyncio
@pytest.mark.flaky(reruns=3, reruns_delay=30)
async def test_search_scraping():
url = "https://www.indeed.com/jobs?q=python&l=Texas"
result_search = await indeed.scrape_search(url, max_results=20)
schema = {
"jobkey": {"type": "string"},
"jobLocationCity": {"type": "string"},
"jobLocationState": {"type": "string"},
"company": {"type": "string"},
"companyRating": {"type": "float"},
"companyReviewCount": {"type": "integer"},
"displayTitle": {"type": "string"},
}
validator = Validator(schema, allow_unknown=True)
for item in result_search:
if not validator.validate(item):
raise Exception({"item": item, "errors": validator.errors})
@pytest.mark.asyncio
@pytest.mark.flaky(reruns=3, reruns_delay=30)
async def test_job_scraping():
jobs = ["9100493864fe1d6e", "5361f22542fe4a95"]
result = await indeed.scrape_jobs(jobs)
assert len(result) == 2
for r in result:
schema = {
"jobTitle": {"type": "string"},
"subtitle": {"type": "string"},
"jobType": {"type": "string"},
"companyName": {"type": "string"},
"description": {"type": "string", "minlength": 100},
"companyImagesModel": {
"type": "dict",
"schema": {
"logoUrl": {"type": "string", "nullable": True},
},
},
"companyReviewModel": {
"type": "dict",
"nullable": True,
"schema": {
"desktopCompanyLink": {"type": "string"},
"companyName": {"type": "string"},
"ratingsModel": {
"type": "dict",
"schema": {
"count": {"type": "integer"},
"rating": {"type": "float"},
},
},
},
},
}
validator = Validator(schema, allow_unknown=True)
if not validator.validate(r):
raise Exception({"item": r, "errors": validator.errors})