diff options
author | Frederick Muriuki Muriithi | 2024-10-17 10:26:15 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-10-17 11:32:28 -0500 |
commit | 85215361b561d332cab954ea68438a2d442c96d8 (patch) | |
tree | 90a3115843770f5e3806762695223a7115a71d99 /tests/uploader/test_uploads_with_zip_files.py | |
parent | 9db2d0986619bf801e2308ee55e4340d9f050376 (diff) | |
download | gn-uploader-85215361b561d332cab954ea68438a2d442c96d8.tar.gz |
Rename test module.
Diffstat (limited to 'tests/uploader/test_uploads_with_zip_files.py')
-rw-r--r-- | tests/uploader/test_uploads_with_zip_files.py | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/tests/uploader/test_uploads_with_zip_files.py b/tests/uploader/test_uploads_with_zip_files.py new file mode 100644 index 0000000..1506cfa --- /dev/null +++ b/tests/uploader/test_uploads_with_zip_files.py @@ -0,0 +1,84 @@ +"""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("/upload", + data={ + "filetype": "average", + "qc_text_file": uploadable_file_object("empty.zip")}, + follow_redirects=True) + assert len(resp.history) == 1 + redirect = resp.history[0] + assert redirect.status_code == 302 + assert redirect.location == "/upload" + + assert resp.status_code == 200 + 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( + "/upload", + data={ + "filetype": "average", + "qc_text_file": uploadable_file_object("multiple_files.zip")}, + follow_redirects=True) + assert len(resp.history) == 1 + redirect = resp.history[0] + assert redirect.status_code == 302 + assert redirect.location == "/upload" + + assert resp.status_code == 200 + 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("/upload", data={ + "speciesid": 1, + "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?speciesid=1&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( + "/upload", + data={ + "filetype": "average", + "qc_text_file": uploadable_file_object("non_tsv.zip")}, + follow_redirects=True) + assert len(resp.history) == 1 + redirect = resp.history[0] + assert redirect.status_code == 302 + assert redirect.location == "/upload" + + assert resp.status_code == 200 + assert (b"Expected the member text file in the uploaded zip file to " + b"be a tab-separated file.") in resp.data |