aboutsummaryrefslogtreecommitdiff
path: root/tests/uploader/test_progress_indication.py
blob: 14a10509b402e17d8e46c28066d20b677981d47e (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
"Test that the progress indication works correctly"

def test_with_non_existing_job(client, redis_conn_with_fresh_job): # pylint: disable=[unused-argument]
    """
    GIVEN: 1. A flask application testing client
           2. A redis instance with a fresh, unstarted job
    WHEN: The parsing progress page is loaded for a non existing job
    THEN: Ensure that the page:
          1. Has a meta tag to redirect it to the index page after 5 seconds
          2. Has text indicating that the job does not exist
    """
    job_id = "non-existent-job-id"
    resp = client.get(f"/parse/status/{job_id}")
    assert resp.status_code == 400
    assert (
        b"No job, with the id '<em>non-existent-job-id</em>' was found!"
        in resp.data)
    assert b'<meta http-equiv="refresh" content="5;url=/upload">' in resp.data

def test_with_unstarted_job(client, job_id, redis_conn_with_fresh_job): # pylint: disable=[unused-argument]
    """
    GIVEN: 1. A flask application testing client
           2. A redis instance with a fresh, unstarted job
    WHEN: The parsing progress page is loaded
    THEN: Ensure that the page:
          1. Has a meta tag to refresh it after 5 seconds
          2. Has a progress indicator with zero progress
    """
    resp = client.get(f"/parse/status/{job_id}")
    assert b'<meta http-equiv="refresh" content="5">' in resp.data
    assert (
        b'<progress id="job_' + (f'{job_id}').encode("utf8") + b'"') in resp.data
    assert b'value="0.0"' in resp.data
    assert b'0.0</progress>' in resp.data

def test_with_in_progress_no_error_job(
        client, job_id, redis_conn_with_in_progress_job_no_errors): # pylint: disable=[unused-argument]
    """
    GIVEN: 1. A flask application testing client
           2. A redis instance with a job in progress, with no errors found in
              the file so far
    WHEN: The parsing progress page is loaded
    THEN: Ensure that the page:
          1. Has a meta tag to refresh it after 5 seconds
          2. Has a progress indicator with the percent of the file processed
             indicated
    """
    resp = client.get(f"/parse/status/{job_id}")
    assert b'<meta http-equiv="refresh" content="5">' in resp.data
    assert (
        b'<progress id="job_' + (f'{job_id}').encode("utf8") + b'"') in resp.data
    assert b'value="0.32242342"' in resp.data
    assert b'32.242342</progress>' in resp.data
    assert (
        b'<span >No errors found so far</span>'
        in resp.data)
    assert b"<table" not in resp.data

def test_with_in_progress_job_with_errors(
        client, job_id, redis_conn_with_in_progress_job_some_errors): # pylint: disable=[unused-argument]
    """
    GIVEN: 1. A flask application testing client
           2. A redis instance with a job in progress, with some errors found in
              the file so far
    WHEN: The parsing progress page is loaded
    THEN: Ensure that the page:
          1. Has a meta tag to refresh it after 5 seconds
          2. Has a progress indicator with the percent of the file processed
             indicated
          3. Has a table showing the errors found so far
    """
    resp = client.get(f"/parse/status/{job_id}")
    assert b'<meta http-equiv="refresh" content="5">' in resp.data
    assert (
        b'<progress id="job_' + (f'{job_id}').encode("utf8") + b'"') in resp.data
    assert b'value="0.4534245"' in resp.data
    assert b'45.34245</progress>' in resp.data
    assert (
        b'<p class="alert-danger">We have found the following errors so far</p>'
        in resp.data)
    assert b'table class="table reports-table">' in resp.data
    assert b'Duplicate Header' in resp.data
    assert b'Invalid Value' in resp.data

def test_with_completed_job_no_errors(
        client, job_id, redis_conn_with_completed_job_no_errors): # pylint: disable=[unused-argument]
    """
    GIVEN: 1. A flask application testing client
           2. A redis instance with a completed job, with no errors found in
              the file so far
    WHEN: The parsing progress page is loaded
    THEN: Ensure that the response is a redirection to the results page
    """
    resp = client.get(f"/parse/status/{job_id}")
    assert resp.status_code == 302
    assert f"/parse/results/{job_id}".encode("utf8") in resp.data

def test_with_completed_job_some_errors(
        client, job_id, redis_conn_with_completed_job_no_errors): # pylint: disable=[unused-argument]
    """
    GIVEN: 1. A flask application testing client
           2. A redis instance with a completed job, with some errors found in
              the file so far
    WHEN: The parsing progress page is loaded
    THEN: Ensure that the response is a redirection to the results page
    """
    resp = client.get(f"/parse/status/{job_id}")
    assert resp.status_code == 302
    assert f"/parse/results/{job_id}".encode("utf8") in resp.data