aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-06-17 08:06:37 +0300
committerFrederick Muriuki Muriithi2022-06-17 08:06:37 +0300
commit6cd32daccf78b40560b96d5c93a1077831b5daf9 (patch)
tree01a657c21f821536e3a137fbc3a717b2d83dc4bc /tests
parentc6b182d346dcf6d3b1cb98956aa3066067f00757 (diff)
downloadgn-uploader-6cd32daccf78b40560b96d5c93a1077831b5daf9.tar.gz
Test endpoint '/parse/parse'
* Ensure error messages are displayed if a request is made to the '/parse/parse' endpoint with invalid, or missing data.
Diffstat (limited to 'tests')
-rw-r--r--tests/qc_app/test_parse.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/qc_app/test_parse.py b/tests/qc_app/test_parse.py
index 0a62df4..b7bf938 100644
--- a/tests/qc_app/test_parse.py
+++ b/tests/qc_app/test_parse.py
@@ -1,6 +1,8 @@
"""Test the 'parse' module in the web-ui"""
import redis
+import pytest
+
from qc_app.jobs import job
from tests.conftest import uploadable_file_object
@@ -40,3 +42,52 @@ def test_parse_with_existing_uploaded_file(client, redis_server, monkeypatch):
"python3", "-m", "scripts.worker", filetype,
f"{client.application.config['UPLOAD_FOLDER']}/{filename}", redis_server,
module_uuid4()])
+
+@pytest.mark.parametrize(
+ "filename,uri,error_msgs",
+ (("non_existent.file",
+ "/parse/parse?filename=non_existent.file&filename=average",
+ [(b'<span class="alert alert-error">Selected file does not exist '
+ b'(any longer)</span>')]),
+ ("non_existent.file",
+ "/parse/parse?filename=non_existent.file&filename=standard-error",
+ [(b'<span class="alert alert-error">Selected file does not exist '
+ b'(any longer)</span>')]),
+ ("non_existent.file",
+ "/parse/parse?filename=non_existent.file&filename=percival",
+ [(b'<span class="alert alert-error">Selected file does not exist '
+ b'(any longer)</span>'),
+ b'<span class="alert alert-error">Invalid filetype provided</span>']),
+ ("no_data_errors.tsv",
+ "/parse/parse?filename=no_data_errors.tsv&filename=percival",
+ [b'<span class="alert alert-error">Invalid filetype provided</span>']),
+ ("no_data_errors.tsv",
+ "/parse/parse?filename=no_data_errors.tsv",
+ [b'<span class="alert alert-error">No filetype provided</span>']),
+ (None, "/parse/parse",
+ [b'<span class="alert alert-error">No file provided</span>',
+ b'<span class="alert alert-error">No filetype provided</span>'])))
+def test_parse_with_non_uploaded_file(client, filename, uri, error_msgs):
+ """
+ GIVEN: 1. A flask application testing client
+ 2. A valid filetype
+ 3. A filename to a file that has not been uploaded yet
+ WHEN: The parsing triggered
+ THEN: Ensure that the appropriate errors are displayed
+ """
+ ## Conditionally upload files
+ if filename and filename != "non_existent.file":
+ client.post(
+ "/", data={
+ "filetype": "average",
+ "qc_text_file": uploadable_file_object(filename)})
+ # Trigger
+ resp = client.get(uri,follow_redirects=True)
+ ## Check that there was exactly one redirect
+ assert len(resp.history) == 1 and resp.history[0].status_code == 302
+ ## Check that redirect is to home page and is successful
+ assert resp.request.path == "/"
+ assert resp.status_code == 200
+ ## Check that error(s) are displayed
+ for error_msg in error_msgs:
+ assert error_msg in resp.data