-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_crawl.py
More file actions
75 lines (62 loc) · 1.74 KB
/
test_crawl.py
File metadata and controls
75 lines (62 loc) · 1.74 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
from python_testing_crawler import (
Crawler,
Rule,
Request,
Ignore,
Allow,
)
GET = "GET"
POST = "POST"
ALL_ELEMENTS_RULE_SET = [
Rule('.*', '/.*', GET, Request())
]
SUBMIT_GET_FORMS_RULE_SET = [
Rule("form", '.*', GET, Request())
]
SUBMIT_POST_FORMS_RULE_SET = [
Rule("form", '.*', POST, Request())
]
def _crawl(client):
crawler = Crawler(
client=client,
initial_paths=['/'],
rules=(
ALL_ELEMENTS_RULE_SET
+ SUBMIT_GET_FORMS_RULE_SET
+ SUBMIT_POST_FORMS_RULE_SET
+ [
# don't logout
Rule(".*", r"/auth/logout", GET, Ignore()),
# allow 400 on create and update
Rule(".*", r"/create", POST, Allow([400])),
Rule(".*", r"/\d+/update", POST, Allow([400])),
]
),
)
crawler.crawl()
return crawler
def test_crawl_without_auth(client, auth):
crawler = _crawl(client)
def test_crawl(client, auth):
auth.login()
crawler = _crawl(client)
def test_other_crawl(client, auth):
auth.login()
crawler = Crawler(
client=client,
initial_paths=['/'],
rules=(
ALL_ELEMENTS_RULE_SET
+ SUBMIT_GET_FORMS_RULE_SET
+ SUBMIT_POST_FORMS_RULE_SET
+ [
# don't logout
Rule(".*", r"/auth/logout", GET, Ignore()),
# submit some data to create
Rule(".*", r"/create", POST, Request(params={"title": "A Title", "body": "body text"})),
# add the missing body when updating
Rule(".*", r"/\d+/update", POST, Request(params={"body": "updated body"})),
]
),
)
crawler.crawl()