From c6b182d346dcf6d3b1cb98956aa3066067f00757 Mon Sep 17 00:00:00 2001
From: Frederick Muriuki Muriithi
Date: Thu, 16 Jun 2022 13:33:31 +0300
Subject: Add more UI tests
- Test upload with missing or invalid data
- Test triggering the parsing of the file
---
tests/qc_app/test_entry.py | 47 +++++++++++++++++++++++++++++++++++++---------
1 file changed, 38 insertions(+), 9 deletions(-)
(limited to 'tests/qc_app/test_entry.py')
diff --git a/tests/qc_app/test_entry.py b/tests/qc_app/test_entry.py
index d2908ee..31c43e1 100644
--- a/tests/qc_app/test_entry.py
+++ b/tests/qc_app/test_entry.py
@@ -1,5 +1,7 @@
"""Test the entry module in the web-ui"""
-import io
+import pytest
+
+from tests.conftest import uploadable_file_object
def test_basic_elements_present_in_index_page(client):
"""
@@ -26,7 +28,14 @@ def test_basic_elements_present_in_index_page(client):
assert b'Invalid file type provided.'
in response.data)
@@ -39,17 +48,37 @@ def test_post_with_correct_data(client):
GIVEN: A flask application testing client
WHEN: the index page is requested with the "POST" method and with the
appropriate data provided
- THEN: ....
- """
- with open("tests/test_data/no_data_errors.tsv", "br") as test_file:
- response = client.post(
- "/", data={
- "filetype": "average",
- "qc_text_file": (io.BytesIO(test_file.read()), "no_data_errors.tsv")
- })
+ THEN: ensure the system redirects to the parse endpoint with the filename
+ and filetype
+ """
+ response = client.post(
+ "/", data={
+ "filetype": "average",
+ "qc_text_file": uploadable_file_object("no_data_errors.tsv")
+ })
assert response.status_code == 302
assert b'Redirecting...' in response.data
assert (
b'/parse/parse?filename=no_data_errors.tsv&filetype=average'
in response.data)
+
+@pytest.mark.parametrize(
+ "request_data,error_message",
+ (({"filetype": "invalid_choice",
+ "qc_text_file": uploadable_file_object("no_data_errors.tsv")},
+ b'Invalid file type provided.'),
+ ({"filetype": "average"},
+ b'No file was uploaded.'),
+ ({"filetype": "standard-error"},
+ b'No file was uploaded.')))
+def test_post_with_missing_or_invalid_data(client, request_data,error_message):
+ """
+ GIVEN: A flask application testing client
+ WHEN: the index page is requested with the "POST" method and with data
+ either being missing or invalid
+ THEN: ensure that the system responds with the appropriate error message
+ """
+ response = client.post("/", data=request_data)
+ assert response.status_code == 200
+ assert error_message in response.data
--
cgit v1.2.3