aboutsummaryrefslogtreecommitdiff
path: root/tests/qc_app
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-06-15 08:05:11 +0300
committerFrederick Muriuki Muriithi2022-06-15 08:05:11 +0300
commit6760d322637a3d875242a66e9c1a784866d7df1d (patch)
tree9c789b3f25cb1b1c04dc7974f9aab0ffcb6acdf4 /tests/qc_app
parentc2fa70ec8503d10b990575a547036bfd70a53825 (diff)
downloadgn-uploader-6760d322637a3d875242a66e9c1a784866d7df1d.tar.gz
Setup test fixtures and initial tests for web-UI
Diffstat (limited to 'tests/qc_app')
-rw-r--r--tests/qc_app/test_entry.py55
-rw-r--r--tests/qc_app/test_parse.py12
2 files changed, 67 insertions, 0 deletions
diff --git a/tests/qc_app/test_entry.py b/tests/qc_app/test_entry.py
new file mode 100644
index 0000000..d2908ee
--- /dev/null
+++ b/tests/qc_app/test_entry.py
@@ -0,0 +1,55 @@
+"""Test the entry module in the web-ui"""
+import io
+
+def test_basic_elements_present_in_index_page(client):
+ """
+ GIVEN: A flask application testing client
+ WHEN: the index page is requested with the "POST" method and no datat
+ THEN: verify that the response contains error notifications
+ """
+ response = client.get("/")
+ assert response.status_code == 200
+ ## form present
+ assert b'<form action="/"' 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">select file</label>' 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'<input type="submit" value="upload file"' in response.data
+
+def test_post_notifies_errors_if_no_data_is_provided(client):
+ response = client.post("/", data={})
+ assert (
+ b'<span class="alert alert-error">Invalid file type provided.</span>'
+ in response.data)
+ assert (
+ b'<span class="alert alert-error">No file was uploaded.</span>'
+ 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: ....
+ """
+ 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")
+ })
+
+ 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)
diff --git a/tests/qc_app/test_parse.py b/tests/qc_app/test_parse.py
new file mode 100644
index 0000000..41d2c26
--- /dev/null
+++ b/tests/qc_app/test_parse.py
@@ -0,0 +1,12 @@
+import pytest
+
+def test_parse_with_existing_file(client, monkeypatch):
+ monkeypatch.setattr(
+ "qc_app.jobs.uuid4", lambda : "934c55d8-396e-4959-90e1-2698e9205758")
+ resp = client.get(
+ "/parse/parse?filename=no_data_errors.tsv&filetype=average")
+ print(resp.status)
+ print(resp.data)
+ assert resp.status_code == 302
+ assert b'Redirecting...' in resp.data
+ assert b'/parse/status/934c55d8-396e-4959-90e1-2698e9205758' in resp.data