aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-06-14 10:48:14 -0500
committerFrederick Muriuki Muriithi2024-06-14 10:48:14 -0500
commitf0804091e3dca1d422a6ba4594967168fb7df537 (patch)
treee2500306d42bbc83fc4fa568e9457e25594c8792 /tests
parent5a25419adc3759aade8c2c49a1aea8835f337549 (diff)
downloadgn-uploader-f0804091e3dca1d422a6ba4594967168fb7df537.tar.gz
Commit missing test.
Diffstat (limited to 'tests')
-rw-r--r--tests/qc_app/test_expression_data_pages.py93
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/qc_app/test_expression_data_pages.py b/tests/qc_app/test_expression_data_pages.py
new file mode 100644
index 0000000..6e073fb
--- /dev/null
+++ b/tests/qc_app/test_expression_data_pages.py
@@ -0,0 +1,93 @@
+"""Test expression data path"""
+import pytest
+
+from tests.conftest import uploadable_file_object
+
+def test_basic_elements_present_in_index_page(client):
+ """
+ GIVEN: A flask application testing client
+ WHEN: the index page is requested with the "GET" method and no data
+ THEN: verify that the response contains error notifications
+ """
+ response = client.get("/upload")
+ assert response.status_code == 200
+ ## form present
+ assert b'<form action="/upload"' in response.data
+ assert b'method="POST"' in response.data
+ assert b'enctype="multipart/form-data"' in response.data
+ assert b'</form>' in response.data
+ ## filetype elements
+ assert b'<input type="radio" name="filetype"' in response.data
+ assert b'id="filetype_standard_error"' in response.data
+ assert b'id="filetype_average"' in response.data
+ ## file upload elements
+ assert b'<label for="file_upload"' in response.data
+ assert b'select file' in response.data
+ assert b'<input type="file" name="qc_text_file"' in response.data
+ assert b'id="file_upload"' in response.data
+ ## submit button
+ assert b'<button type="submit"' 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("/upload", data={}, follow_redirects=True)
+ assert len(response.history) == 1
+ redirect = response.history[0]
+ assert redirect.status_code == 302
+ assert redirect.location == "/upload"
+
+
+ assert response.status_code == 200
+ assert b'Invalid file type provided.' in response.data
+ assert b'No file was uploaded.' in response.data
+
+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: ensure the system redirects to the parse endpoint with the filename
+ and filetype
+ """
+ response = client.post(
+ "/upload", data={
+ "speciesid": 1,
+ "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?speciesid=1&amp;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'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("/upload", data=request_data, follow_redirects=True)
+ assert len(response.history) == 1
+ redirect = response.history[0]
+ assert redirect.status_code == 302
+ assert redirect.location == "/upload"
+
+ assert response.status_code == 200
+ assert error_message in response.data