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 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