示例#1
0
def test_login_with_wrong_crecentials():
    '''test that login guards against wrong credentials'''

    client = app.test_client()

    response = test_helper.login(client, '*****@*****.**', 'wrongpassword')

    assert b'Please check your login details and try again.' in response.data
示例#2
0
def test_export_report_with_invalid_date():
    '''Test behaviour of export_report route when called with invalid date'''

    client = app.test_client()

    test_helper.login(client)

    response = client.get('/export-report/invalid-date')

    assert response.status_code == 400
示例#3
0
def test_that_logout_route_is_protected():

    client = app.test_client()

    # ensure that user is logged out
    test_helper.logout(client)

    response = client.post('/logout', follow_redirects=True)

    # redirects to login page
    assert b'Login' in response.data
示例#4
0
def check_protected_route(route):
    '''tests that route is protected'''

    client = app.test_client()

    # ensure that user is logged out
    test_helper.logout(client)

    response = client.get(route, follow_redirects=True)

    # redirects to login page
    assert b'Login' in response.data
示例#5
0
def test_index_with_invalid_date():
    '''Test index route with invalid date'''

    client = app.test_client()

    test_helper.login(client)

    response = client.get('/invalid-date')

    expected_error = b'Invalid date string, provide date like (YYYY-mm-dd) e.g "2019-08-12"'

    assert response.status_code == 200
    assert expected_error in response.data
示例#6
0
def test_export_report_with_valid_date():
    '''Test export report route when given valid date'''

    client = app.test_client()

    test_helper.login(client)

    response = client.get('/export-report/2019-08-12')

    assert response.status_code == 200

    empty_file_response = b'\r\n'
    non_empty_file_headers = b'project_name,project_id,project_duration,username,\
        user_id,org_id,org_name,org_duration,date'

    # check for empty and non empty because i do not know which date might have data
    assert empty_file_response in response.data or non_empty_file_headers in response.datas
示例#7
0
def test_index_with_valid_date():
    '''Test index route with valid date'''

    client = app.test_client()

    test_helper.login(client)

    date = '2019-08-12'
    response = client.get(f'/{date}')

    search_string = f'<span><strong>Current Report Date:</strong> {date}</span>'

    assert response.status_code == 200
    assert response.data.decode('utf-8').find(search_string) != -1

    # verify that it does not produce error message
    assert b'Invalid date string, provide date like' not in response.data
示例#8
0
def test_index_route_defaults_to_previous_day():
    '''Test that index route defaults to previous date'''

    client = app.test_client()

    test_helper.login(client)

    response = client.get('/')

    a_day = 1
    date = helpers.format_date(datetime.now() - timedelta(a_day))

    search_string = f'<span><strong>Current Report Date:</strong> {date}</span>'

    assert response.status_code == 200
    assert response.data.decode('utf-8').find(search_string) != -1

    # verify that it does not produce error message
    assert b'Invalid date string, provide date like' not in response.data