From 9ff12c643feadc353f29fe8dac4b9819caf1779c Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 13 Jun 2024 15:54:17 -0500 Subject: Fix tests and issues caught by tests. --- tests/qc_app/test_entry.py | 97 +++++++++-------------------- tests/qc_app/test_parse.py | 6 +- tests/qc_app/test_progress_indication.py | 24 +++---- tests/qc_app/test_results_page.py | 6 +- tests/qc_app/test_uploads_with_zip_files.py | 49 +++++++++++---- 5 files changed, 84 insertions(+), 98 deletions(-) (limited to 'tests/qc_app') diff --git a/tests/qc_app/test_entry.py b/tests/qc_app/test_entry.py index bfe56ec..0c614a5 100644 --- a/tests/qc_app/test_entry.py +++ b/tests/qc_app/test_entry.py @@ -1,80 +1,43 @@ """Test the entry module in the web-ui""" import pytest -from tests.conftest import uploadable_file_object +@pytest.mark.parametrize( + "dataitem,lower", + ( + # expression data UI elements + (b'

expression data

', True), + (b'', False), -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'
' in response.data - ## filetype elements - assert b'samples/cases', True), + (b'r/qtl2 bundles', True), + (b'405: The method is not allowed for the requested URL.' + in resp.data) diff --git a/tests/qc_app/test_parse.py b/tests/qc_app/test_parse.py index 187af76..3915a4d 100644 --- a/tests/qc_app/test_parse.py +++ b/tests/qc_app/test_parse.py @@ -30,7 +30,7 @@ def test_parse_with_existing_uploaded_file(#pylint: disable=[too-many-arguments] filename = "no_data_errors.tsv" filetype = "average" client.post( - "/", data={ + "/upload", data={ "speciesid": speciesid, "filetype": filetype, "qc_text_file": uploadable_file_object(filename)}) @@ -81,7 +81,7 @@ def test_parse_with_non_uploaded_file(client, filename, uri, error_msgs): ## Conditionally upload files if filename and filename != "non_existent.file": client.post( - "/", data={ + "/upload", data={ "filetype": "average", "qc_text_file": uploadable_file_object(filename)}) # Trigger @@ -89,7 +89,7 @@ def test_parse_with_non_uploaded_file(client, filename, uri, error_msgs): ## Check that there was exactly one redirect assert len(resp.history) == 1 and resp.history[0].status_code == 302 ## Check that redirect is to home page and is successful - assert resp.request.path == "/" + assert resp.request.path == "/upload" assert resp.status_code == 200 ## Check that error(s) are displayed for error_msg in error_msgs: diff --git a/tests/qc_app/test_progress_indication.py b/tests/qc_app/test_progress_indication.py index 8eba970..14a1050 100644 --- a/tests/qc_app/test_progress_indication.py +++ b/tests/qc_app/test_progress_indication.py @@ -15,7 +15,7 @@ def test_with_non_existing_job(client, redis_conn_with_fresh_job): # pylint: dis assert ( b"No job, with the id 'non-existent-job-id' was found!" in resp.data) - assert b'' in resp.data + assert b'' in resp.data def test_with_unstarted_job(client, job_id, redis_conn_with_fresh_job): # pylint: disable=[unused-argument] """ @@ -29,9 +29,9 @@ def test_with_unstarted_job(client, job_id, redis_conn_with_fresh_job): # pylint resp = client.get(f"/parse/status/{job_id}") assert b'' in resp.data assert ( - b'0.0') in resp.data + b'' in resp.data def test_with_in_progress_no_error_job( client, job_id, redis_conn_with_in_progress_job_no_errors): # pylint: disable=[unused-argument] @@ -48,9 +48,9 @@ def test_with_in_progress_no_error_job( resp = client.get(f"/parse/status/{job_id}") assert b'' in resp.data assert ( - b'32.242342') in resp.data + b'' in resp.data assert ( b'No errors found so far' in resp.data) @@ -72,13 +72,13 @@ def test_with_in_progress_job_with_errors( resp = client.get(f"/parse/status/{job_id}") assert b'' in resp.data assert ( - b'45.34245') in resp.data + b'' in resp.data assert ( - b'

We have found the following errors so far

' + b'

We have found the following errors so far

' in resp.data) - assert b'table class="reports-table">' in resp.data + assert b'table class="table reports-table">' in resp.data assert b'Duplicate Header' in resp.data assert b'Invalid Value' in resp.data diff --git a/tests/qc_app/test_results_page.py b/tests/qc_app/test_results_page.py index 57f1531..bb596d7 100644 --- a/tests/qc_app/test_results_page.py +++ b/tests/qc_app/test_results_page.py @@ -56,12 +56,12 @@ def test_results_with_completed_job_some_errors( 1. the system redirects to the results page 2. the results page displays the errors found """ - resp = client.get(f"/parse/status/{job_id}", follow_redirects=True) + resp = client.get(f"/parse/status/{job_id}", follow_redirects=True);import sys;print(resp.data, file=sys.stderr) assert len(resp.history) == 1 assert ( - b'

We found the following errors

' + b'

We found the following errors

' in resp.data) - assert b'' in resp.data + assert b'
' in resp.data assert b'Duplicate Header' in resp.data assert b'' in resp.data assert b'Invalid Value' in resp.data diff --git a/tests/qc_app/test_uploads_with_zip_files.py b/tests/qc_app/test_uploads_with_zip_files.py index fb101ad..1506cfa 100644 --- a/tests/qc_app/test_uploads_with_zip_files.py +++ b/tests/qc_app/test_uploads_with_zip_files.py @@ -8,10 +8,17 @@ def test_upload_zipfile_with_zero_files(client): 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 + 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 @@ -22,10 +29,18 @@ def test_upload_zipfile_with_multiple_files(client): 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 + 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 @@ -35,7 +50,7 @@ def test_upload_zipfile_with_one_tsv_file(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={ + resp = client.post("/upload", data={ "speciesid": 1, "filetype": "average", "qc_text_file": uploadable_file_object("average.tsv.zip")}) @@ -53,9 +68,17 @@ def test_upload_zipfile_with_one_non_tsv_file(client): 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 + 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 -- cgit v1.2.3
Heading 'DupHead' is repeated