def test_user_profile(client):
    identity = {'username': '******'}
    token = ""
    with app.test_request_context('/users/me'):
        token = create_access_token(identity=identity)
        res = client.get('/users/me',
                         headers={"Authorization": "Bearer {}".format(token)})
        result = utils.convert_byte_to_dict(res.data)
        assert result['username'] == 'user01'
        assert res.status_code == 200
def test_token_refresh(client):
    identity = {'username': '******'}
    token = ""
    with app.test_request_context('/auth/refresh'):
        token = create_refresh_token(identity=identity)
        res = client.post('/auth/refresh',
                          headers={"Authorization": "Bearer {}".format(token)})
        result = utils.convert_byte_to_dict(res.data)
        assert result['access_token'] != None
        assert res.status_code == 201
def test_my_booked_cars(client):
    identity = {'username': '******'}
    token = ""
    with app.test_request_context('/bookings/me'):
        token = create_access_token(identity=identity)
        res = client.get('/bookings/me',
                         headers={"Authorization": "Bearer {}".format(token)})
        result = utils.convert_byte_to_dict(res.data)
        assert len(result) != 0
        assert res.status_code == 200
def test_register_user_invalid(client):
    res = client.post("/users/register",
                      data=dict(username='******', password='******', email='user02'))
    result = utils.convert_byte_to_dict(res.data)
    result = result['message']
    assert result['username'].startswith('Value does not match')
    assert result['password'].startswith('Value does not match')
    assert result['first_name'].startswith('Missing required parameter')
    assert result['last_name'].startswith('Missing required parameter')
    assert result['email'].startswith('Value does not match')
    assert res.status_code == 400
def test_cancel_booking(client):
    identity = {'username': '******'}
    token = ""
    booking_id = 1
    route = '/bookings/cancel/{}'.format(booking_id)
    with app.test_request_context(route):
        token = create_access_token(identity=identity)
        res = client.delete(
            route, headers={"Authorization": "Bearer {}".format(token)})
        result = utils.convert_byte_to_dict(res.data)
        assert result['message'].startswith("Your booking")
        assert res.status_code == 200
def test_add_booking_invalid(client):
    # booking_period format: 2013-01-01/2013-01-01
    identity = {'username': '******'}
    token = ""
    car_number = "KK0001"
    booking_period = "2020-06-07/2020-06-14"
    with app.test_request_context('/bookings/new'):
        token = create_access_token(identity=identity)
        res = client.post(
            '/bookings/new',
            data=dict(car_number=car_number, booking_period=booking_period),
            headers={"Authorization": "Bearer {}".format(token)},
        )
        result = utils.convert_byte_to_dict(res.data)
        assert result['message'].startswith("Car")
        assert res.status_code == 403
Exemplo n.º 7
0
def test_add_new_car(client):
    identity = {'username': '******'}
    token = ""
    with app.test_request_context('/cars/new'):
        token = create_access_token(identity=identity)
        res = client.post(
            "/cars/new",
            data=dict(
                car_number='KK0002',
                make='Mazda',
                body_type='Sedan',
                colour='black',
                seats=5,
                cost_per_hour="12.0",
            ),
            headers={"Authorization": "Bearer {}".format(token)},
        )
        result = utils.convert_byte_to_dict(res.data)
        # print(result)
        # print("*****************")
        assert result['message'] != None
def test_new_login_valid(client):
    res = client.post('/auth/new',
                      data=dict(username='******', password='******'))
    result = utils.convert_byte_to_dict(res.data)
    assert result['access_token'] != None
    assert res.status_code == 201