-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
test_qa.py
208 lines (161 loc) · 5.66 KB
/
test_qa.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
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
from .conftest import API_PREFIX, HOST_PREFIX
import requests
import time
from datetime import datetime
qa_run_id = None
def test_run_qa(crawler_crawl_id, crawler_auth_headers, default_org_id):
r = requests.post(
f"{API_PREFIX}/orgs/{default_org_id}/crawls/{crawler_crawl_id}/qa/start",
headers=crawler_auth_headers,
)
assert r.status_code == 200
data = r.json()
assert data["started"]
global qa_run_id
qa_run_id = data["started"]
def test_run_qa_already_running(crawler_crawl_id, crawler_auth_headers, default_org_id):
r = requests.post(
f"{API_PREFIX}/orgs/{default_org_id}/crawls/{crawler_crawl_id}/qa/start",
headers=crawler_auth_headers,
)
assert r.status_code == 400
assert r.json()["detail"] == "qa_already_running"
def test_active_qa(crawler_crawl_id, crawler_auth_headers, default_org_id):
r = requests.get(
f"{API_PREFIX}/orgs/{default_org_id}/crawls/{crawler_crawl_id}/qa/activeQA",
headers=crawler_auth_headers,
)
data = r.json()
qa = data["qa"]
assert qa
assert qa["state"]
assert qa["started"]
assert not qa["finished"]
def test_qa_list(crawler_crawl_id, crawler_auth_headers, default_org_id):
r = requests.get(
f"{API_PREFIX}/orgs/{default_org_id}/crawls/{crawler_crawl_id}/qa",
headers=crawler_auth_headers,
)
data = r.json()
assert len(data) == 1
qa = data[0]
assert qa
assert qa["state"]
assert qa["started"]
assert not qa["finished"]
def test_wait_for_complete(crawler_crawl_id, crawler_auth_headers, default_org_id):
count = 0
completed = False
while count < 24:
r = requests.get(
f"{API_PREFIX}/orgs/{default_org_id}/crawls/{crawler_crawl_id}/qa/activeQA",
headers=crawler_auth_headers,
)
data = r.json()
if not data["qa"]:
completed = True
break
time.sleep(5)
count += 1
assert completed
def test_qa_completed(crawler_crawl_id, crawler_auth_headers, default_org_id):
r = requests.get(
f"{API_PREFIX}/orgs/{default_org_id}/crawls/{crawler_crawl_id}/qa",
headers=crawler_auth_headers,
)
data = r.json()
assert len(data) == 1
qa = data[0]
assert qa
assert qa["state"] == "complete"
assert qa["started"]
assert qa["finished"]
assert qa["stats"]["found"] == 1
assert qa["stats"]["done"] == 1
assert qa["crawlExecSeconds"] > 0
def test_qa_org_stats(crawler_crawl_id, crawler_auth_headers, default_org_id):
r = requests.get(
f"{API_PREFIX}/orgs/{default_org_id}/crawls/{crawler_crawl_id}",
headers=crawler_auth_headers,
)
crawl_stats = r.json()
assert crawl_stats["qaCrawlExecSeconds"] > 0
r = requests.get(
f"{API_PREFIX}/orgs/{default_org_id}",
headers=crawler_auth_headers,
)
org_stats = r.json()
yymm = datetime.utcnow().strftime("%Y-%m")
assert org_stats["qaCrawlExecSeconds"][yymm] > 0
assert org_stats["qaUsage"][yymm] > 0
def test_qa_page_data(crawler_crawl_id, crawler_auth_headers, default_org_id):
r = requests.get(
f"{API_PREFIX}/orgs/{default_org_id}/crawls/{crawler_crawl_id}/qa/{qa_run_id}/pages",
headers=crawler_auth_headers,
)
data = r.json()
assert len(data["items"]) == 1
page = data["items"][0]
page_id = page["id"]
assert page_id
assert page["title"] == "Webrecorder"
assert page["url"] == "https://webrecorder.net/"
assert page["qa"]["textMatch"] == 1.0
assert page["qa"]["screenshotMatch"] == 1.0
assert page["qa"]["resourceCounts"] == {
"crawlGood": 15,
"crawlBad": 0,
"replayGood": 15,
"replayBad": 1,
}
r = requests.get(
f"{API_PREFIX}/orgs/{default_org_id}/crawls/{crawler_crawl_id}/qa/{qa_run_id}/pages/{page_id}",
headers=crawler_auth_headers,
)
page = r.json()
assert page["id"]
assert page["title"] == "Webrecorder"
assert page["url"] == "https://webrecorder.net/"
assert page["qa"]["textMatch"] == 1.0
assert page["qa"]["screenshotMatch"] == 1.0
assert page["qa"]["resourceCounts"] == {
"crawlGood": 15,
"crawlBad": 0,
"replayGood": 15,
"replayBad": 1,
}
def test_qa_replay(crawler_crawl_id, crawler_auth_headers, default_org_id):
r = requests.get(
f"{API_PREFIX}/orgs/{default_org_id}/crawls/{crawler_crawl_id}/qa/{qa_run_id}/replay.json",
headers=crawler_auth_headers,
)
data = r.json()
assert len(data["resources"]) == 1
assert data["resources"][0]["path"]
def test_run_qa_not_running(crawler_crawl_id, crawler_auth_headers, default_org_id):
r = requests.post(
f"{API_PREFIX}/orgs/{default_org_id}/crawls/{crawler_crawl_id}/qa/stop",
headers=crawler_auth_headers,
)
assert r.status_code == 400
assert r.json()["detail"] == "qa_not_running"
def test_delete_qa_run(crawler_crawl_id, crawler_auth_headers, default_org_id):
r = requests.post(
f"{API_PREFIX}/orgs/{default_org_id}/crawls/{crawler_crawl_id}/qa/delete",
json={"qa_run_ids": [qa_run_id]},
headers=crawler_auth_headers,
)
assert r.status_code == 200
assert r.json()["deleted"] == True
# deleted from finished qa list
r = requests.get(
f"{API_PREFIX}/orgs/{default_org_id}/crawls/{crawler_crawl_id}/qa",
headers=crawler_auth_headers,
)
assert len(r.json()) == 0
# deleted from pages
r = requests.get(
f"{API_PREFIX}/orgs/{default_org_id}/crawls/{crawler_crawl_id}/qa/{qa_run_id}/pages",
headers=crawler_auth_headers,
)
assert len(r.json()["items"]) == 0