aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMuriithi Frederick Muriuki2018-03-09 18:12:58 +0300
committerPjotr Prins2018-03-26 09:29:29 +0000
commit428371a67a7c742e239d96914a96558171f9f59e (patch)
treeeed0d4c3f6961aee924539579a372e8ee5cb89c5
parent07b792f0898d7ecec94b938aa3081e6aa64bc435 (diff)
downloadgenenetwork2-428371a67a7c742e239d96914a96558171f9f59e.tar.gz
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.
-rwxr-xr-xtest/requests/test-website.py60
1 files changed, 51 insertions, 9 deletions
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)