INPRO: Bugfixing and better returns
This commit is contained in:
+33
-34
@@ -7,14 +7,7 @@ from os import stat, getuid
|
||||
|
||||
def check_sanity():
|
||||
check_database_permissions()
|
||||
check_random()
|
||||
check_verse_of_the_day()
|
||||
check_find()
|
||||
check_define()
|
||||
check_search()
|
||||
check_show()
|
||||
check_seq()
|
||||
check_shortcode()
|
||||
|
||||
|
||||
def check_database_permissions():
|
||||
dependancies = ['data/seq.db', "data/shortcodes.db"]
|
||||
@@ -22,35 +15,41 @@ def check_database_permissions():
|
||||
for dependancy in dependancies:
|
||||
if stat(dependancy).st_uid != current_uid:
|
||||
raise PermissionError(dependancy)
|
||||
|
||||
def check_random():
|
||||
#TODO: Ensure random returns a verse
|
||||
pass
|
||||
|
||||
def check_verse_of_the_day():
|
||||
#TODO: Ensure VOTD returns a verse, the same, at least twice
|
||||
pass
|
||||
def check_queries(url=None):
|
||||
try:
|
||||
import requests
|
||||
except ImportError:
|
||||
raise ImportError("You must install the requests python3 module")
|
||||
endpoints: list = 'show find search seq status votd random define'.split(" ")
|
||||
viewarguments: list = 'rich plain json'.split(" ")
|
||||
with open("tools/search_keywords.txt") as f:
|
||||
keywords = f.read().splitlines()
|
||||
|
||||
def check_find():
|
||||
#TODO: Ensure that a varaity of queries don't cause an error (need to define a few)
|
||||
pass
|
||||
log = []
|
||||
|
||||
def check_define():
|
||||
#TODO: Ensure a few words that are in the dictionary (and those that are not) and those misspelled, give correct responses
|
||||
pass
|
||||
baseurl = "http://localhost:1611"
|
||||
if url:
|
||||
baseurl = url
|
||||
|
||||
def check_search():
|
||||
#TODO: Ensure that blanket searches with different syntaxes resolve correctly
|
||||
pass
|
||||
for endpoint in endpoints:
|
||||
for viewargument in viewarguments:
|
||||
for keyword in keywords:
|
||||
testurl = f"{baseurl}/{endpoint}?view={viewargument}&kw={keyword}"
|
||||
r = requests.get(testurl)
|
||||
log.append([testurl, r.status_code])
|
||||
|
||||
def check_show():
|
||||
#TODO: Ensure that many types of verse syntaxes correctly resolve.
|
||||
pass
|
||||
with open("tools/sanity_results.txt", 'r+') as logfile:
|
||||
for logged in log:
|
||||
if logged[1] != 200:
|
||||
logfile.write(f"{logged[1]} - {logged[0]}\n")
|
||||
|
||||
def check_seq():
|
||||
#TODO: Begin a new sequence and check that it does not give us an error
|
||||
pass
|
||||
|
||||
def check_shortcode():
|
||||
#TODO: make a new shortcode for a search and then try to resolve it.
|
||||
pass
|
||||
if __name__ == "__main__":
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser("Endpoint testing for your kjv api.")
|
||||
parser.add_argument('url', type=str, nargs='?', help="like http://localhost:1611")
|
||||
args = parser.parse_args()
|
||||
if not args.url:
|
||||
print("Trying default http://localhost:1611")
|
||||
url = "http://localhost:1611"
|
||||
check_queries(url=args.url)
|
||||
Reference in New Issue
Block a user