diff options
author | Frederick Muriuki Muriithi | 2022-06-16 13:33:31 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2022-06-16 13:33:31 +0300 |
commit | c6b182d346dcf6d3b1cb98956aa3066067f00757 (patch) | |
tree | 4f40b729aea86ce8da93fa4da6244d186f0e87c1 /tests/qc_app/test_parse.py | |
parent | d2605cb72d7cdbc7d3cc633b94a451c0acd2edbb (diff) | |
download | gn-uploader-c6b182d346dcf6d3b1cb98956aa3066067f00757.tar.gz |
Add more UI tests
- Test upload with missing or invalid data
- Test triggering the parsing of the file
Diffstat (limited to 'tests/qc_app/test_parse.py')
-rw-r--r-- | tests/qc_app/test_parse.py | 48 |
1 files changed, 39 insertions, 9 deletions
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()]) |