about summary refs log tree commit diff
path: root/tests/qc_app/test_entry.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/qc_app/test_entry.py')
-rw-r--r--tests/qc_app/test_entry.py47
1 files changed, 38 insertions, 9 deletions
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'<input type="submit" value="upload file"' in response.data
 
 def test_post_notifies_errors_if_no_data_is_provided(client):
+    """
+    GIVEN: A flask application testing client
+    WHEN: the index page is requested with the "POST" method and with no
+          data provided
+    THEN: ensure the system responds woit the appropriate error messages
+    """
     response = client.post("/", data={})
+    assert response.status_code == 200
     assert (
         b'<span class="alert alert-error">Invalid file type provided.</span>'
         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&amp;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'<span class="alert alert-error">Invalid file type provided.</span>'),
+     ({"filetype": "average"},
+      b'<span class="alert alert-error">No file was uploaded.</span>'),
+     ({"filetype": "standard-error"},
+      b'<span class="alert alert-error">No file was uploaded.</span>')))
+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