aboutsummaryrefslogtreecommitdiff
path: root/tests/uploader/test_uploads_with_zip_files.py
blob: 1506cfa7edbe2d0c2c5ef71f9b98f47d11104ff3 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""Test the upload of zip files"""
from tests.conftest import uploadable_file_object

def test_upload_zipfile_with_zero_files(client):
    """
    GIVEN: A flask application testing client
    WHEN: A zip file with no files is uploaded
    THEN: Ensure that the system responds with the appropriate error message and
          status code
    """
    resp = client.post("/upload",
                       data={
                           "filetype": "average",
                           "qc_text_file": uploadable_file_object("empty.zip")},
                       follow_redirects=True)
    assert len(resp.history) == 1
    redirect = resp.history[0]
    assert redirect.status_code == 302
    assert redirect.location == "/upload"

    assert resp.status_code == 200
    assert (b"Expected exactly one (1) member file within the uploaded zip "
            b"file. Got 0 member files.") in resp.data

def test_upload_zipfile_with_multiple_files(client):
    """
    GIVEN: A flask application testing client
    WHEN: A zip file with more than one file is uploaded
    THEN: Ensure that the system responds with the appropriate error message and
          status code
    """
    resp = client.post(
        "/upload",
        data={
            "filetype": "average",
            "qc_text_file": uploadable_file_object("multiple_files.zip")},
        follow_redirects=True)
    assert len(resp.history) == 1
    redirect = resp.history[0]
    assert redirect.status_code == 302
    assert redirect.location == "/upload"

    assert resp.status_code == 200
    assert (b"Expected exactly one (1) member file within the uploaded zip "
            b"file. Got 3 member files.") in resp.data

def test_upload_zipfile_with_one_tsv_file(client):
    """
    GIVEN: A flask application testing client
    WHEN: A zip file with exactly one valid TSV file is uploaded
    THEN: Ensure that the system redirects to the correct next URL
    """
    resp = client.post("/upload", data={
        "speciesid": 1,
        "filetype": "average",
        "qc_text_file": uploadable_file_object("average.tsv.zip")})
    assert resp.status_code == 302
    assert b"Redirecting..." in resp.data
    assert (
        b"/parse/parse?speciesid=1&filename=average.tsv.zip&filetype=average"
        in resp.data)

def test_upload_zipfile_with_one_non_tsv_file(client):
    """
    GIVEN: A flask application testing client
    WHEN: A zip file with exactly one file, which is not a valid TSV, is
          uploaded
    THEN: Ensure that the system responds with the appropriate error message and
          status code
    """
    resp = client.post(
        "/upload",
        data={
            "filetype": "average",
            "qc_text_file": uploadable_file_object("non_tsv.zip")},
        follow_redirects=True)
    assert len(resp.history) == 1
    redirect = resp.history[0]
    assert redirect.status_code == 302
    assert redirect.location == "/upload"

    assert resp.status_code == 200
    assert (b"Expected the member text file in the uploaded zip file to "
            b"be a tab-separated file.") in resp.data