"""Test the entry module in the web-ui""" import pytest from tests.conftest import uploadable_file_object 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'Invalid file type provided.' in response.data) assert ( b'No file was uploaded.' 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: 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): """ 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 """ response = client.post("/", data=request_data) assert response.status_code == 400 assert error_message in response.data