From c6b182d346dcf6d3b1cb98956aa3066067f00757 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 16 Jun 2022 13:33:31 +0300 Subject: Add more UI tests - Test upload with missing or invalid data - Test triggering the parsing of the file --- tests/qc_app/test_parse.py | 48 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) (limited to 'tests/qc_app/test_parse.py') diff --git a/tests/qc_app/test_parse.py b/tests/qc_app/test_parse.py index 41d2c26..0a62df4 100644 --- a/tests/qc_app/test_parse.py +++ b/tests/qc_app/test_parse.py @@ -1,12 +1,42 @@ -import pytest - -def test_parse_with_existing_file(client, monkeypatch): - monkeypatch.setattr( - "qc_app.jobs.uuid4", lambda : "934c55d8-396e-4959-90e1-2698e9205758") - resp = client.get( - "/parse/parse?filename=no_data_errors.tsv&filetype=average") - print(resp.status) - print(resp.data) +"""Test the 'parse' module in the web-ui""" +import redis + +from qc_app.jobs import job +from tests.conftest import uploadable_file_object + +def module_uuid4(): + "module patch for the `uuid.uuid4()` function" + return "934c55d8-396e-4959-90e1-2698e9205758" + +def test_parse_with_existing_uploaded_file(client, redis_server, monkeypatch): + """ + GIVEN: 1. A flask application testing client + 2. A valid file, and filetype + WHEN: The file is uploaded, and the parsing triggered + THEN: Ensure that: + 1. the system redirects to the job/parse status page + 2. the job is placed on redis for processing + """ + monkeypatch.setattr("qc_app.jobs.uuid4", module_uuid4) + # Upload a file + filename = "no_data_errors.tsv" + filetype = "average" + client.post( + "/", data={ + "filetype": filetype, + "qc_text_file": uploadable_file_object(filename)}) + # Checks + resp = client.get(f"/parse/parse?filename={filename}&filetype={filetype}") assert resp.status_code == 302 assert b'Redirecting...' in resp.data assert b'/parse/status/934c55d8-396e-4959-90e1-2698e9205758' in resp.data + + with redis.Redis.from_url(redis_server, decode_responses=True) as rconn: + the_job = job(rconn, module_uuid4()) + + assert the_job["job_id"] == module_uuid4() + assert the_job["filename"] == filename + assert the_job["command"] == " ".join([ + "python3", "-m", "scripts.worker", filetype, + f"{client.application.config['UPLOAD_FOLDER']}/{filename}", redis_server, + module_uuid4()]) -- cgit v1.2.3