diff options
Diffstat (limited to 'tests/qc_app/test_entry.py')
-rw-r--r-- | tests/qc_app/test_entry.py | 97 |
1 files changed, 30 insertions, 67 deletions
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'<h2 class="heading">expression data</h2>', True), + (b'<a href="/upload"', False), + (b'upload expression data</a>', 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'<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"' 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'<input type="submit" value="upload file"' in response.data + # samples/cases data UI elements + (b'<h2 class="heading">samples/cases</h2>', True), + (b'<a href="/samples/upload/species"', False), + (b'upload samples/cases', True), -def test_post_notifies_errors_if_no_data_is_provided(client): + # R/qtl2 data UI elements + (b'<h2 class="heading">r/qtl2 bundles</h2>', True), + (b'<a href="/upload/rqtl2/select-species"', False), + (b'upload r/qtl2 bundle', True) + )) +def test_landing_page_has_sections(client, dataitem, lower): """ 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 + WHEN: the index page is requested + THEN: ensure the page has the expected UI elements """ - response = client.post("/", data={}) - assert response.status_code == 400 - assert b'Invalid file type provided.' in response.data - assert b'No file was uploaded.' in response.data + resp = client.get("/") + assert resp.status_code == 200 + assert dataitem in (resp.data.lower() if lower else resp.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( - "/", 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&filename=no_data_errors.tsv&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): +def test_landing_page_fails_with_post(client): """ 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 + WHEN: the index page is requested with the "POST" method + THEN: ensure the system fails """ - response = client.post("/", data=request_data) - assert response.status_code == 400 - assert error_message in response.data + resp = client.post("/") + assert resp.status_code == 405 + assert ( + b'<h1>405: The method is not allowed for the requested URL.</h1>' + in resp.data) |