Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Jan 30, 2021. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
Latest commit
69 lines (50 loc) · 2.09 KB
/
Copy pathapp.py
File metadata and controls
69 lines (50 loc) · 2.09 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
importrequests
importsys
importtime
importos
defmain():
trigger_url=sys.argv[1]
trigger_resp=requests.get(trigger_url)
iftrigger_resp.ok:
trigger_json=trigger_resp.json().get("data", {})
test_runs=trigger_json.get("runs", [])
print"Started {} test runs.".format(len(test_runs))
results= {}
whilelen(results.keys()) <len(test_runs):
time.sleep(1)
forrunintest_runs:
test_run_id=run.get("test_run_id")
ifnottest_run_idinresults:
result=_get_result(run)
ifresult.get("result") in ["pass", "fail"]:
results[test_run_id] =result
pass_count=sum([r.get("result") =="pass"forrinresults.values()])
fail_count=sum([r.get("result") =="fail"forrinresults.values()])
iffail_count>0:
print"{} test runs passed. {} test runs failed.".format(pass_count, fail_count)
exit(1)
print"All test runs passed."
def_get_result(test_run):
# generate Personal Access Token at https://www.runscope.com/applications
ifnot"RUNSCOPE_ACCESS_TOKEN"inos.environ:
print"Please set the environment variable RUNSCOPE_ACCESS_TOKEN. You can get an access token by going to https://www.runscope.com/applications"
exit(1)
API_TOKEN=os.environ["RUNSCOPE_ACCESS_TOKEN"]
opts= {
"base_url": "https://api.runscope.com",
"bucket_key": test_run.get("bucket_key"),
"test_id": test_run.get("test_id"),
"test_run_id": test_run.get("test_run_id")
}
result_url="{base_url}/buckets/{bucket_key}/tests/{test_id}/results/{test_run_id}".format(**opts)
print"Getting result: {}".format(result_url)
headers= {
"Authorization": "Bearer {}".format(API_TOKEN),
"User-Agent": "python-trigger-sample"
}
result_resp=requests.get(result_url, headers=headers)
ifresult_resp.ok:
returnresult_resp.json().get("data")
returnNone
if__name__=='__main__':
main()