From 3eef6d582245c80e274c9e135028de90788a712b Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 22 Jun 2022 11:09:48 +0300 Subject: Test zipfiles uploads: commit forgotten tests --- tests/qc_app/test_uploads_with_zip_files.py | 60 +++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 tests/qc_app/test_uploads_with_zip_files.py (limited to 'tests/qc_app') diff --git a/tests/qc_app/test_uploads_with_zip_files.py b/tests/qc_app/test_uploads_with_zip_files.py new file mode 100644 index 0000000..2a43a2d --- /dev/null +++ b/tests/qc_app/test_uploads_with_zip_files.py @@ -0,0 +1,60 @@ +"""Test the upload of zip files""" +from tests.conftest import uploadable_file_object + +def test_upload_zipfile_with_zero_files(client): + """ + GIVEN: A flask application testing client + WHEN: A zip file with no files is uploaded + THEN: Ensure that the system responds with the appropriate error message and + status code + """ + resp = client.post("/", data={ + "filetype": "average", + "qc_text_file": uploadable_file_object("empty.zip")}) + assert resp.status_code == 400 + assert (b"Expected exactly one (1) member file within the uploaded zip " + b"file. Got 0 member files.") in resp.data + +def test_upload_zipfile_with_multiple_files(client): + """ + GIVEN: A flask application testing client + WHEN: A zip file with more than one file is uploaded + THEN: Ensure that the system responds with the appropriate error message and + status code + """ + resp = client.post("/", data={ + "filetype": "average", + "qc_text_file": uploadable_file_object("multiple_files.zip")}) + assert resp.status_code == 400 + assert (b"Expected exactly one (1) member file within the uploaded zip " + b"file. Got 3 member files.") in resp.data + +def test_upload_zipfile_with_one_tsv_file(client): + """ + GIVEN: A flask application testing client + WHEN: A zip file with exactly one valid TSV file is uploaded + THEN: Ensure that the system redirects to the correct next URL + """ + resp = client.post("/", data={ + "filetype": "average", + "qc_text_file": uploadable_file_object("average.tsv.zip")}) + assert resp.status_code == 302 + assert b"Redirecting..." in resp.data + assert ( + b"/parse/parse?filename=average.tsv.zip&filetype=average" + in resp.data) + +def test_upload_zipfile_with_one_non_tsv_file(client): + """ + GIVEN: A flask application testing client + WHEN: A zip file with exactly one file, which is not a valid TSV, is + uploaded + THEN: Ensure that the system responds with the appropriate error message and + status code + """ + resp = client.post("/", data={ + "filetype": "average", + "qc_text_file": uploadable_file_object("non_tsv.zip")}) + assert resp.status_code == 400 + assert (b"Expected the member text file in the uploaded zip file to " + b"be a tab-separated file.") in resp.data -- cgit v1.2.3