aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-06-22 11:09:13 +0300
committerFrederick Muriuki Muriithi2022-06-22 11:09:13 +0300
commita87ec5a580a209fa516b2cb623ac6cdc6407b2d9 (patch)
tree93b622042afe43866518c0cd4c39496ce987b7a2 /tests
parent3bd3049fd403886a9653aa7c2fbd1639926420ea (diff)
downloadgn-uploader-a87ec5a580a209fa516b2cb623ac6cdc6407b2d9.tar.gz
Test the results pages
Diffstat (limited to 'tests')
-rw-r--r--tests/conftest.py43
-rw-r--r--tests/qc_app/test_results_page.py68
2 files changed, 110 insertions, 1 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index 90d8264..be5f9f2 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -103,7 +103,7 @@ def redis_conn_with_completed_job_no_errors(redis_url, job_id): # pylint: disabl
the_job = {
"job_id": job_id, "command": "some_test_command",
"status": "success", "filename": "/path/to/some/file.tsv",
- "percent": 100
+ "percent": 100, "errors": jsonpickle.encode(tuple())
}
with redis.Redis.from_url(redis_url, decode_responses=True) as rconn:
rconn.hset(name=job_id, mapping=the_job)
@@ -127,3 +127,44 @@ def redis_conn_with_completed_job_some_errors(redis_url, job_id): # pylint: disa
yield rconn
rconn.hdel(job_id, *the_job.keys())
rconn.delete(job_id)
+
+@pytest.fixture(scope="function")
+def uploads_dir(client): # pylint: disable=[redefined-outer-name]
+ """Returns the configured, uploads directory, creating it if it does not
+ exist."""
+ the_dir = client.application.config["UPLOAD_FOLDER"]
+ if not os.path.exists(the_dir):
+ os.mkdir(the_dir)
+
+ return the_dir
+
+@pytest.fixture(scope="function")
+def jobs_errors_dir(uploads_dir): # pylint: disable=[redefined-outer-name]
+ """Returns the configured, jobs errors directory, creating it if it does not
+ exist."""
+ the_dir = f"{uploads_dir}/job_errors"
+ if not os.path.exists(the_dir):
+ os.mkdir(the_dir)
+
+ return the_dir
+
+@pytest.fixture(scope="function")
+def stderr_with_output(jobs_errors_dir, job_id): # pylint: disable=[redefined-outer-name]
+ """Creates a sample worker error file with some content"""
+ filepath = f"{jobs_errors_dir}/job_{job_id}.error"
+ with open(filepath, "w", encoding="utf8") as error_file:
+ error_file.write("This is an non-empty error file.")
+ error_file.flush()
+ yield filepath
+
+ os.remove(filepath)
+
+@pytest.fixture(scope="function")
+def stderr_with_no_output(jobs_errors_dir, job_id): # pylint: disable=[redefined-outer-name]
+ """Creates a sample worker error file with no content"""
+ filepath = f"{jobs_errors_dir}/job_{job_id}.error"
+ with open(filepath, "w", encoding="utf-8") as error_file:
+ error_file.flush()
+ yield filepath
+
+ os.remove(filepath)
diff --git a/tests/qc_app/test_results_page.py b/tests/qc_app/test_results_page.py
new file mode 100644
index 0000000..57f1531
--- /dev/null
+++ b/tests/qc_app/test_results_page.py
@@ -0,0 +1,68 @@
+"Test results page"
+
+def test_results_with_stderr_output(
+ client, job_id, stderr_with_output, # pylint: disable=[unused-argument]
+ redis_conn_with_in_progress_job_no_errors): # pylint: disable=[unused-argument]
+ """
+ GIVEN: 1. A flask application testing client
+ 2. A file with content to simulate the stderr output
+ 3. A sample job to prevent the "No such job" error message
+ WHEN: The parsing progress page is loaded for a non existing job
+ THEN: Ensure that the page:
+ 1. Redirects to a job failure display page
+ 2. The job failure display page:
+ a) indicates that this is a worker failure
+ b) provides some debugging information
+ """
+ # Maybe get rid of the use of a stderr file, and check for actual exceptions
+ resp = client.get(f"/parse/status/{job_id}", follow_redirects=True)
+ assert len(resp.history) == 1
+ assert b'<h1 class="heading">Worker Failure</h1>' in resp.data
+ assert b'<h4>Debugging Information</h4>' in resp.data
+ assert (
+ f"<li><strong>job id</strong>: {job_id}</li>".encode("utf8")
+ in resp.data)
+
+def test_results_with_completed_job_no_errors(
+ client, job_id, stderr_with_no_output, # pylint: disable=[unused-argument]
+ redis_conn_with_completed_job_no_errors): # pylint: disable=[unused-argument]
+ """
+ GIVEN: 1. A flask application testing client
+ 2. A redis instance with a completed job, with no errors found in
+ the file
+ 3. A file with no contents to simulate no stderr output
+ WHEN: The parsing progress page is loaded
+ THEN: Ensure that:
+ 1. the system redirects to the results page
+ 2. the results page indicates that there are no errors in the file
+ being processed
+ """
+ resp = client.get(f"/parse/status/{job_id}", follow_redirects=True)
+ assert len(resp.history) == 1
+ assert (
+ b'<span class="alert-success">No errors found in the file</span>'
+ in resp.data)
+
+def test_results_with_completed_job_some_errors(
+ client, job_id, stderr_with_no_output, # pylint: disable=[unused-argument]
+ redis_conn_with_completed_job_some_errors): # pylint: disable=[unused-argument]
+ """
+ GIVEN: 1. A flask application testing client
+ 2. A redis instance with a completed job, with some errors found in
+ the file
+ 3. A file with no contents to simulate no stderr output
+ WHEN: The parsing progress page is loaded
+ THEN: Ensure that:
+ 1. the system redirects to the results page
+ 2. the results page displays the errors found
+ """
+ resp = client.get(f"/parse/status/{job_id}", follow_redirects=True)
+ assert len(resp.history) == 1
+ assert (
+ b'<p class="alert-error">We found the following errors</p>'
+ in resp.data)
+ assert b'<table class="reports-table">' in resp.data
+ assert b'Duplicate Header' in resp.data
+ assert b'<td>Heading &#39;DupHead&#39; is repeated</td>' in resp.data
+ assert b'Invalid Value' in resp.data
+ assert b'<td>Invalid value &#39;ohMy&#39;</td>' in resp.data