aboutsummaryrefslogtreecommitdiff
path: root/tests/qc_app/test_parse.py
blob: 0a62df4e5349fa50f7d6b6e296a7e64b107f86ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""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()])