aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPjotr Prins2020-07-27 09:13:38 +0100
committerGitHub2020-07-27 09:13:38 +0100
commit56ad14434435133b9ef90870f50a52bd158bd6ba (patch)
tree16e0936453576a1c73ea4eff1ae959a32a98348e
parent918dcce5f42fcbe9327eb30bac06a69000a1fc8b (diff)
parent68bd586b05ae5f3cb90829d2a108901b5b1d87a6 (diff)
downloadgenenetwork2-56ad14434435133b9ef90870f50a52bd158bd6ba.tar.gz
Merge branch 'testing' into testing
-rw-r--r--README.md38
-rw-r--r--doc/testing.org66
-rw-r--r--test/unittest/__init__.py0
-rw-r--r--test/unittest/base/__init__.py0
-rw-r--r--test/unittest/base/test_general_object.py21
5 files changed, 82 insertions, 43 deletions
diff --git a/README.md b/README.md
index a2a4625a..46264252 100644
--- a/README.md
+++ b/README.md
@@ -41,7 +41,17 @@ Also mariadb and redis need to be running, see
## Testing
-We are building 'Mechanical Rob' automated testing using Python.
+To have tests pass, the redis and mariadb instance should be running, because of
+asserts sprinkled in the code base(these will be removed in due time).
+
+#### Mechanical Rob
+We are building 'Mechanical Rob' automated testing using Python
+[requests](https://github.com/genenetwork/genenetwork2/tree/testing/test/requests)
+which can be run with:
+
+```sh
+env GN2_PROFILE=~/opt/gn-latest ./bin/genenetwork2 ./etc/default_settings.py -c ../test/requests/test-website.py -a http://localhost:5003
+```
The GN2_PROFILE is the Guix profile that contains all
dependencies. The ./bin/genenetwork2 script sets up the environment
@@ -49,6 +59,32 @@ and executes test-website.py in a Python interpreter. The -a switch
says to run all tests and the URL points to the running GN2 http
server.
+#### Unit tests
+
+To run unittests, first `cd` into the genenetwork2 directory:
+
+```sh
+# You can use the coverage tool to run the tests
+# You could omit the -v which makes the output verbose
+runcmd coverage run -m unittest discover -v
+
+# Alternatively, you could run the unittests using:
+runpython -m unittest discover -v
+
+# To generate a report in wqflask/coverage_html_report/:
+runcmd coverage html
+```
+
+The `runcmd` and `runpython` are shell aliases defined in the following way:
+
+```sh
+alias runpython="env GN2_PROFILE=~/opt/gn-latest TMPDIR=/tmp SERVER_PORT=5004 GENENETWORK_FILES=/gnu/data/gn2_data/ ./bin/genenetwork2
+
+alias runcmd="time env GN2_PROFILE=~/opt/gn-latest TMPDIR=//tmp SERVER_PORT=5004 GENENETWORK_FILES=/gnu/data/gn2_data/ ./bin/genenetwork2 ./etc/default_settings.py -cli"
+```
+
+Replace some of the env variables as per your use case.
+
## Documentation
User documentation can be found
diff --git a/doc/testing.org b/doc/testing.org
index 1d5cc8b8..d5ab117d 100644
--- a/doc/testing.org
+++ b/doc/testing.org
@@ -1,43 +1,67 @@
#+TITLE: Testing GN2
* Table of Contents :TOC:
- - [[#introduction][Introduction]]
- - [[#run-tests][Run tests]]
- - [[#setup][Setup]]
- - [[#running][Running]]
+- [[#introduction][Introduction]]
+- [[#run-tests][Run tests]]
+ - [[#setup][Setup]]
+ - [[#running][Running]]
* Introduction
-For integration testing we currently use the brilliant Ruby Mechanize
-gem against the small database; a setup we call mechanical Rob because
-it emulates someone clicking through the website and checking results.
+For integration testing, we currently use [[https://github.com/genenetwork/genenetwork2/tree/testing/test/requests][Mechanica Rob]] against the
+small [[https://github.com/genenetwork/genenetwork2/blob/testing/doc/database.org][database]]; a setup we call Mechanical Rob because it emulates
+someone clicking through the website and checking results.
-These scripts invoke calls to a running webserver and test the
-response. If a page changes or is broken tests will break and we are
-informed. In principle, Mechanical Rob is run before code merges are
-committed to the main server.
+These scripts invoke calls to a running webserver and test the response.
+If a page changes or breaks, tests will fail. In principle, Mechanical
+Rob runs before code merges get committed to the main server.
-In the future we may move to Python mechanize - it'll be easy to mix
-the Ruby and Python versions.
+For unit tests, we use python's =unittest= framework. Coverage reports
+get generated using [[https://coverage.readthedocs.io/en/coverage-5.2.1/][coverage.py]] which you could also use to run
+unit tests. When adding new functionality, it is advisable to add
+unit tests.
* Run tests
** Setup
-Mechanize is not yet included in Guix deployment.
+Everything required for testing is already package with guix:
+: ./pre-ins-env guix package -i genenetwork2 -p ~/opt/genenetwork2
** Running
-Run the tests from the root of the genenetwork2 source tree as, for
-example,
+Run the tests from the root of the genenetwork2 source tree as. Ensure
+that Redis and Mariadb are running.
-: ./bin/test-website http://localhost:5003/ (default)
+To run Mechanical Rob:
+: time env GN2_PROFILE=~/opt/genenetwork2 TMPDIR=~/tmp SERVER_PORT=5004 GENENETWORK_FILES=/gnu/data/gn2_data/ ./bin/genenetwork2 ./etc/default_settings.py -c ~/projects/genenetwork2/test/requests/test-website.py -a http://localhost:5004
-If you are using the small deployment database you can use
+Use these aliases for the following examples.
-: ./bin/test-website --skip -n
+#+begin_src sh
+alias runpython="env GN2_PROFILE=~/opt/gn-latest TMPDIR=/tmp SERVER_PORT=5004 GENENETWORK_FILES=/gnu/data/gn2_data/ ./bin/genenetwork2
-To run individual tests on localhost you can do
+alias runcmd="time env GN2_PROFILE=~/opt/gn-latest TMPDIR=//tmp SERVER_PORT=5004 GENENETWORK_FILES=/gnu/data/gn2_data/ ./bin/genenetwork2 ./etc/default_settings.py -cli"
+#+end_src
-: ruby -Itest -Itest/lib test/lib/mapping.rb --name="/Mapping/"
+You could use them in your =.bashrc= or =.zshrc= file.
+
+To run unit tests:
+
+: runpython -m unittest discover -v
+
+Or alternatively using the coverage tool:
+
+: runcmd coverage run -m unittest discover -v
+
+To generate a html coverage report in =wqflask/coverage_html_report/=
+
+: runcmd coverage html
+
+To output the report to =STDOUT=:
+
+: runcmd coverage report
+
+All the configs for running the coverage tool are in
+=wqflask/.coveragerc=
diff --git a/test/unittest/__init__.py b/test/unittest/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/test/unittest/__init__.py
+++ /dev/null
diff --git a/test/unittest/base/__init__.py b/test/unittest/base/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/test/unittest/base/__init__.py
+++ /dev/null
diff --git a/test/unittest/base/test_general_object.py b/test/unittest/base/test_general_object.py
deleted file mode 100644
index 699cb079..00000000
--- a/test/unittest/base/test_general_object.py
+++ /dev/null
@@ -1,21 +0,0 @@
-import unittest
-
-from base.GeneralObject import GeneralObject
-
-
-class TestGeneralObjectTests(unittest.TestCase):
- """
- Test the GeneralObject base class
- """
-
- def test_object_contents(self):
- """Test whether base contents are stored properly"""
- test_obj = GeneralObject("a", "b", "c")
- self.assertEqual("abc", ''.join(test_obj.contents))
-
- def test_object_dict(self):
- """Test whether the base class is printed properly"""
- test_obj = GeneralObject("a", name="test", value=1)
- self.assertEqual(str(test_obj), "value = 1\nname = test\n")
- self.assertEqual(
- repr(test_obj), "value = 1\nname = test\ncontents = ['a']\n")