Esempio n. 1
0
def test_get_all_cars(client):
    identity = {'username': '******'}
    token = ""
    with app.test_request_context("/cars/all"):
        token = create_access_token(identity=identity)
        res = client.get("/cars/all",
                         headers={"Authorization": "Bearer {}".format(token)})
        assert res.status_code == 200
Esempio n. 2
0
def test_search_car_by_make(client):
    identity = {'username': '******'}
    token = ""
    make = "Toyota"
    route = "/cars/search?make={}".format(make)
    with app.test_request_context(route):
        token = create_access_token(identity=identity)
        res = client.get(route,
                         headers={"Authorization": "Bearer {}".format(token)})
        assert res.status_code == 200
Esempio n. 3
0
def test_get_car_detail(client):
    identity = {'username': '******'}
    token = ""
    car_number = "KK0001"
    route = '/cars/detail/{}'.format(car_number)
    with app.test_request_context(route):
        token = create_access_token(identity=identity)
        res = client.get(route,
                         headers={"Authorization": "Bearer {}".format(token)})
        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_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_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_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
Esempio n. 8
0
def test_available_cars(client):
    # occupied rang: "2020-06-05/2020-06-12"
    identity = {'username': '******'}
    token = ""
    time_range = "2020-06-05/2020-06-12"

    with app.test_request_context("cars/available"):
        token = create_access_token(identity=identity)
        res = client.get(
            "cars/available",
            data=dict(time_range="2020-06-05/2020-06-12"),
            headers={"Authorization": "Bearer {}".format(token)},
        )
        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
Esempio n. 10
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