From 6cd32daccf78b40560b96d5c93a1077831b5daf9 Mon Sep 17 00:00:00 2001
From: Frederick Muriuki Muriithi
Date: Fri, 17 Jun 2022 08:06:37 +0300
Subject: Test endpoint '/parse/parse'
* Ensure error messages are displayed if a request is made to the
'/parse/parse' endpoint with invalid, or missing data.
---
tests/qc_app/test_parse.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
(limited to 'tests/qc_app')
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'Selected file does not exist '
+ b'(any longer)')]),
+ ("non_existent.file",
+ "/parse/parse?filename=non_existent.file&filename=standard-error",
+ [(b'Selected file does not exist '
+ b'(any longer)')]),
+ ("non_existent.file",
+ "/parse/parse?filename=non_existent.file&filename=percival",
+ [(b'Selected file does not exist '
+ b'(any longer)'),
+ b'Invalid filetype provided']),
+ ("no_data_errors.tsv",
+ "/parse/parse?filename=no_data_errors.tsv&filename=percival",
+ [b'Invalid filetype provided']),
+ ("no_data_errors.tsv",
+ "/parse/parse?filename=no_data_errors.tsv",
+ [b'No filetype provided']),
+ (None, "/parse/parse",
+ [b'No file provided',
+ b'No filetype provided'])))
+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
--
cgit v1.2.3