From 13ba222e4a04c514d10c35caafb5297309914d4c Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Fri, 30 Mar 2018 07:49:01 +0000 Subject: Tests: all tests run --- test/requests/link_checker.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'test/requests') diff --git a/test/requests/link_checker.py b/test/requests/link_checker.py index 256bf6ef..5adbf9a9 100644 --- a/test/requests/link_checker.py +++ b/test/requests/link_checker.py @@ -25,10 +25,16 @@ def get_links(doc): , doc.cssselect("a"))) def verify_link(link): + if link[0] == "#": + # local link on page + return + print("verifying "+link) try: - result = requests.get(link, timeout=20) + result = requests.get(link, timeout=20, verify=False) if result.status_code == 200: print(link+" ==> OK") + elif result.status_code == 307: + print(link+" ==> REDIRECT") else: print("ERROR: link `"+link+"` failed with status " , result.status_code) @@ -37,7 +43,7 @@ def verify_link(link): def check_page(host, start_url): print("") - print("Checking links in page `"+start_url+"`") + print("Checking links host "+host+" in page `"+start_url+"`") doc = parse(start_url).getroot() links = get_links(doc) internal_links = filter(is_internal_link, links) -- 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') 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 From 1d1446a0452cdbb0b86d8235a3f0c53c89669275 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Fri, 30 Mar 2018 08:25:57 +0000 Subject: Testing: removed test assertion (oops) --- test/requests/link_checker.py | 1 - 1 file changed, 1 deletion(-) (limited to 'test/requests') diff --git a/test/requests/link_checker.py b/test/requests/link_checker.py index 0f81caa4..64553ed8 100644 --- a/test/requests/link_checker.py +++ b/test/requests/link_checker.py @@ -27,7 +27,6 @@ def get_links(doc): , doc.cssselect("a"))) def verify_link(link): - assert(DO_FAIL) if link[0] == "#": # local link on page return -- cgit v1.2.3