From 375935b23778148eba40ebce4a4f4def823aa3f0 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Thu, 15 Feb 2018 15:00:47 +0000 Subject: Requests added --- test/requests/test-website.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 test/requests/test-website.py (limited to 'test/requests/test-website.py') diff --git a/test/requests/test-website.py b/test/requests/test-website.py new file mode 100755 index 00000000..d02b71aa --- /dev/null +++ b/test/requests/test-website.py @@ -0,0 +1,20 @@ +# Run with something like +# +# env GN2_PROFILE=/home/wrk/opt/gn-latest ./bin/genenetwork2 ./etc/default_settings.py -c ../test/requests/test-website.py http://localhost:5003 +# +# Mostly to pick up the Guix GN2_PROFILE and python modules + +import requests as req +import sys + +print "Mechanical Rob firing up..." + +if len(sys.argv)<1: + raise "Problem with arguments" + +url = sys.argv[1] +print url + +r = req.get(url) + +print r -- cgit v1.2.3 From 428371a67a7c742e239d96914a96558171f9f59e Mon Sep 17 00:00:00 2001 From: Muriithi Frederick Muriuki Date: Fri, 9 Mar 2018 18:12:58 +0300 Subject: Use argparse to handle arguments * Use argparse to handle commandline arguments. * Create initial layout of how the code might end up - lots of the code is currently commented out. --- test/requests/test-website.py | 60 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 9 deletions(-) (limited to 'test/requests/test-website.py') diff --git a/test/requests/test-website.py b/test/requests/test-website.py index d02b71aa..9637b87f 100755 --- a/test/requests/test-website.py +++ b/test/requests/test-website.py @@ -3,18 +3,60 @@ # env GN2_PROFILE=/home/wrk/opt/gn-latest ./bin/genenetwork2 ./etc/default_settings.py -c ../test/requests/test-website.py http://localhost:5003 # # Mostly to pick up the Guix GN2_PROFILE and python modules +from __future__ import print_function +from link_checker import check_links +import argparse -import requests as req -import sys +print("Mechanical Rob firing up...") -print "Mechanical Rob firing up..." +def run_all(args_obj, parser): + print("") + print("Running all tests.") + check_links(args_obj, parser) + # TODO: Add other functions as they are created. -if len(sys.argv)<1: - raise "Problem with arguments" +def print_help(args_obj, parser): + print(parser.format_help()) -url = sys.argv[1] -print url +def dummy(args_obj, parser): + print("Not implemented yet.") -r = req.get(url) -print r +desc = """ +This is Mechanical-Rob - an automated web server tester for + Genenetwork.org +""" +parser = argparse.ArgumentParser(description=desc) + +parser.add_argument("-d", "--database", metavar="DB", type=str + , default="db_webqtl_s" + , help="Use database (default db_webqtl_s)") + +parser.add_argument("host", metavar="HOST", type=str + , default="http://localhost:5003" + , help="The url to the web server") + +parser.add_argument("-a", "--all", dest="accumulate", action="store_const" + , const=run_all, default=print_help + , help="Runs all tests.") + +parser.add_argument("-l", "--link-checker", dest="accumulate" + , action='store_const', const=check_links, default=print_help + , help="Checks for dead links.") + +# parser.add_argument("-n", "--navigation", dest="accumulate" +# , action="store_const", const=check_navigation, default=print_help +# , help="Checks for navigation.") + +# parser.add_argument("-m", "--mapping", dest="accumulate" +# , action="store_const", const=check_mapping, default=print_help +# , help="Checks for mapping.") + +# parser.add_argument("-s", "--skip-broken", dest="accumulate" +# , action="store_const", const=dummy, default=print_help +# , help="Skip tests that are known to be broken.") + +args = parser.parse_args() +# print("The arguments object: ", args) + +args.accumulate(args, parser) -- cgit v1.2.3 From 8ff3dbd9bd5737b6cd0df8d279a70073c40786ec Mon Sep 17 00:00:00 2001 From: Muriithi Frederick Muriuki Date: Wed, 14 Mar 2018 02:16:59 +0300 Subject: Add tests for main web functionality --- test/requests/main_web_functionality.py | 40 +++++++++++++++++++++++++++++++++ test/requests/test-website.py | 7 ++++++ 2 files changed, 47 insertions(+) create mode 100644 test/requests/main_web_functionality.py (limited to 'test/requests/test-website.py') diff --git a/test/requests/main_web_functionality.py b/test/requests/main_web_functionality.py new file mode 100644 index 00000000..f6b32340 --- /dev/null +++ b/test/requests/main_web_functionality.py @@ -0,0 +1,40 @@ +from __future__ import print_function +import re +import requests +from lxml.html import parse +from requests.exceptions import ConnectionError + +def check_home(url): + doc = parse(url).getroot() + search_button = doc.cssselect("#btsearch") + assert(search_button[0].value == "Search") + print("OK") + +def check_search_page(host): + data = dict( + species="mouse" + , group="BXD" + , type="Hippocampus mRNA" + , dataset="HC_M2_0606_P" + , search_terms_or="" + , search_terms_and="MEAN=(15 16) LRS=(23 46)") + result = requests.get(host+"/search", params=data) + found = result.text.find("/show_trait?trait_id=1435395_s_at&dataset=HC_M2_0606_P") + assert(found >= 0) + print("OK") + check_traits_page(host, "/show_trait?trait_id=1435395_s_at&dataset=HC_M2_0606_P") + +def check_traits_page(host, traits_url): + from link_checker import check_page + doc = parse(host+traits_url).getroot() + traits_form = doc.forms[1] + assert(traits_form.fields["corr_dataset"] == "HC_M2_0606_P") + print("OK") + check_page(host, host+traits_url) + +def check_main_web_functionality(args_obj, parser): + print("") + print("Checking main web functionality...") + host = args_obj.host + check_home(host) + check_search_page(host) diff --git a/test/requests/test-website.py b/test/requests/test-website.py index 9637b87f..f65c3fc8 100755 --- a/test/requests/test-website.py +++ b/test/requests/test-website.py @@ -4,6 +4,7 @@ # # Mostly to pick up the Guix GN2_PROFILE and python modules from __future__ import print_function +from main_web_functionality import check_main_web_functionality from link_checker import check_links import argparse @@ -12,6 +13,7 @@ print("Mechanical Rob firing up...") def run_all(args_obj, parser): print("") print("Running all tests.") + check_main_web_functionality(args_obj, parser) check_links(args_obj, parser) # TODO: Add other functions as they are created. @@ -44,6 +46,11 @@ parser.add_argument("-l", "--link-checker", dest="accumulate" , action='store_const', const=check_links, default=print_help , help="Checks for dead links.") +parser.add_argument("-f", "--main-functionality", dest="accumulate" + , action='store_const', const=check_main_web_functionality + , default=print_help + , help="Checks for main web functionality.") + # parser.add_argument("-n", "--navigation", dest="accumulate" # , action="store_const", const=check_navigation, default=print_help # , help="Checks for navigation.") -- cgit v1.2.3 From c3fab61242796ef4b7544d784fceb39f4545828e Mon Sep 17 00:00:00 2001 From: Muriithi Frederick Muriuki Date: Sun, 18 Mar 2018 08:56:03 +0300 Subject: Initialise mapping tests * Add mapping tests, and build the first of the tests. --- test/requests/mapping_tests.py | 43 ++++++++++++++++++++++++++++++++++++++++++ test/requests/test-website.py | 14 ++++++++------ 2 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 test/requests/mapping_tests.py (limited to 'test/requests/test-website.py') diff --git a/test/requests/mapping_tests.py b/test/requests/mapping_tests.py new file mode 100644 index 00000000..fd20df11 --- /dev/null +++ b/test/requests/mapping_tests.py @@ -0,0 +1,43 @@ +from __future__ import print_function +import re +import json +import requests +from lxml.html import fromstring + +def get_data(list_item): + try: + value = list_item[1] + except: + value = None + #print("list_item:", list_item, "==>", value) + return value + +def load_data_from_file(): + filename = "../test/data/input/mapping/1435395_s_at_HC_M2_0606_P.json" + file_handle = open(filename, "r") + file_data = json.loads(file_handle.read().encode("utf-8")) + return file_data + +def check_pylmm_tool_selection(host, data): + data["method"] = "pylmm" + page = requests.post(host+"/marker_regression", data=data) + doc = fromstring(page.text) + form = doc.forms[1] + assert form.fields["dataset"] == "HC_M2_0606_P" + assert form.fields["value:BXD1"] == "15.034" # Check value in the file + +def check_R_qtl_tool_selection(host, data): + pass + +def check_CIM_tool_selection(host, data): + pass + +def check_mapping(args_obj, parser): + print("") + print("Checking mapping") + + host = args_obj.host + data = load_data_from_file() + check_pylmm_tool_selection(host, data) + check_R_qtl_tool_selection(host, data) + check_CIM_tool_selection(host, data) diff --git a/test/requests/test-website.py b/test/requests/test-website.py index f65c3fc8..2bef6eb1 100755 --- a/test/requests/test-website.py +++ b/test/requests/test-website.py @@ -4,9 +4,10 @@ # # Mostly to pick up the Guix GN2_PROFILE and python modules from __future__ import print_function -from main_web_functionality import check_main_web_functionality -from link_checker import check_links import argparse +from link_checker import check_links +from mapping_tests import check_mapping +from main_web_functionality import check_main_web_functionality print("Mechanical Rob firing up...") @@ -15,6 +16,7 @@ def run_all(args_obj, parser): print("Running all tests.") check_main_web_functionality(args_obj, parser) check_links(args_obj, parser) + check_mapping(args_obj, parser) # TODO: Add other functions as they are created. def print_help(args_obj, parser): @@ -51,14 +53,14 @@ parser.add_argument("-f", "--main-functionality", dest="accumulate" , default=print_help , help="Checks for main web functionality.") +parser.add_argument("-m", "--mapping", dest="accumulate" + , action="store_const", const=check_mapping, default=print_help + , help="Checks for mapping.") + # parser.add_argument("-n", "--navigation", dest="accumulate" # , action="store_const", const=check_navigation, default=print_help # , help="Checks for navigation.") -# parser.add_argument("-m", "--mapping", dest="accumulate" -# , action="store_const", const=check_mapping, default=print_help -# , help="Checks for mapping.") - # parser.add_argument("-s", "--skip-broken", dest="accumulate" # , action="store_const", const=dummy, default=print_help # , help="Skip tests that are known to be broken.") -- cgit v1.2.3 From c4d3f406fb01f81b2b952a622f2f7bb0967c8c91 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Fri, 30 Mar 2018 08:14:02 +0000 Subject: Add --fail argument to test runner --- test/requests/link_checker.py | 9 ++++++++- test/requests/test-website.py | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'test/requests/test-website.py') diff --git a/test/requests/link_checker.py b/test/requests/link_checker.py index 5adbf9a9..0f81caa4 100644 --- a/test/requests/link_checker.py +++ b/test/requests/link_checker.py @@ -4,6 +4,8 @@ import requests from lxml.html import parse from requests.exceptions import ConnectionError +DO_FAIL=False # fail on error + def is_root_link(link): pattern = re.compile("^/$") return pattern.match(link) @@ -25,6 +27,7 @@ def get_links(doc): , doc.cssselect("a"))) def verify_link(link): + assert(DO_FAIL) if link[0] == "#": # local link on page return @@ -38,8 +41,12 @@ def verify_link(link): else: print("ERROR: link `"+link+"` failed with status " , result.status_code) + if DO_FAIL: + raise Exception("Failed verify") except ConnectionError as ex: print("ERROR: ", link, ex) + if DO_FAIL: + raise ex def check_page(host, start_url): print("") @@ -48,7 +55,7 @@ def check_page(host, start_url): links = get_links(doc) internal_links = filter(is_internal_link, links) external_links = filter(lambda x: not is_internal_link(x), links) - external_links.append("http://somenon-existentsite.brr") + # external_links.append("http://somenon-existentsite.brr") for link in internal_links: verify_link(host+link) diff --git a/test/requests/test-website.py b/test/requests/test-website.py index 2bef6eb1..118c9df1 100755 --- a/test/requests/test-website.py +++ b/test/requests/test-website.py @@ -8,12 +8,16 @@ import argparse from link_checker import check_links from mapping_tests import check_mapping from main_web_functionality import check_main_web_functionality +import link_checker +import sys print("Mechanical Rob firing up...") def run_all(args_obj, parser): print("") print("Running all tests.") + print(args_obj) + link_checker.DO_FAIL = args_obj.fail check_main_web_functionality(args_obj, parser) check_links(args_obj, parser) check_mapping(args_obj, parser) @@ -32,6 +36,8 @@ This is Mechanical-Rob - an automated web server tester for """ parser = argparse.ArgumentParser(description=desc) +parser.add_argument("--fail", help="Fail and stop on any error", action="store_true") + parser.add_argument("-d", "--database", metavar="DB", type=str , default="db_webqtl_s" , help="Use database (default db_webqtl_s)") -- cgit v1.2.3