forked from perseids-project/morphsvc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
createtests.py
35 lines (32 loc) · 1.24 KB
/
createtests.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
import os, requests, sys, re
from urllib import parse
fixture = os.path.join(os.path.dirname(__file__), 'tests', 'r1')
failed = os.path.join(os.path.dirname(__file__), 'tests', 'failed')
success = os.path.join(os.path.dirname(__file__), 'tests', 'success')
errors = os.path.join(os.path.dirname(__file__), 'tests', 'errors')
#host = "http://bsp.perseids.org/bsp/morphologyservice"
host = "http://localhost:5000"
in_file = open(fixture, 'r')
out_failed = open(failed, 'w')
out_success = open(success, 'w')
out_errored = open(errors, 'w')
for line in in_file.readlines():
#line = parse.unquote(line)
url = host + line.strip()
print(url)
resp = requests.get(url, headers= { 'Accept': 'application/json'})
resp.encoding = "utf-8"
print(resp.text)
p = re.compile("Body",flags=re.M)
parsed = resp.json()
try:
resp.raise_for_status()
if p.search(resp.text):
out_success.write("Request=" + line + "\nResponse=\n")
out_success.write(resp.text + "\n")
else:
out_failed.write("Request=" + line + "\nResponse=\n")
out_failed.write(resp.text + "\n")
except:
out_errored.write("Request=" + line + "\nResponse=\n")
out_errored.write(resp.text + "\n")