-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_app.py
36 lines (31 loc) · 1.26 KB
/
test_app.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
import pytest
import requests
import json
import urllib.parse
import subprocess
def callHowDoI(testQuery):
# x = requests.post("http://localhost:5000/test", params={"testquery": testQuery})
cmd = "http -f POST http://localhost:5000/test?testquery={}".format(urllib.parse.quote(testQuery))
res = subprocess.check_output(cmd, shell=True)
# get rid of the b' on the front of the string
res = res.decode('utf-8')
jsonRes = json.loads(res)
return jsonRes["status"]
def test_func():
testQueries = [
{"query":"howdoi get gmail","shouldFail": False},
{"query":"howdoi learn java","shouldFail": False},
{"query":"howdoi compile c code","shouldFail": False},
{"query":"howdii run faster","shouldFail": True},
{"query":"howdoi exit vim","shouldFail": False},
{"query":"when is half life 3 coming out","shouldFail": True},
{"query":"howdoi install gentoo","shouldFail": False},
{"query":"h``owdoi love vim","shouldFail": True},
{"query":"-ho[wdoi love vim","shouldFail": True}
]
for test in testQueries:
response = callHowDoI(test["query"])
if test["shouldFail"]:
assert response == "error"
else:
assert response == "success"