示例#1
0
def test_setup(client):
    """
    Setup booking test by registering user and add cars.

    :param client: Flask app client
    :type client: Flask app instance
    """
    # Register user (includes login)
    with open("src/MasterCSS/tests/testImages/" + \
                "example.jpg", "rb") as user_image:
        user_image_read = BytesIO(user_image.read())
    response = client.post('/register',
                           data=dict(username="******",
                                     password="******",
                                     email="*****@*****.**",
                                     firstname="alex",
                                     lastname="witedja",
                                     phonenumber="04325672682",
                                     usertype="ADMIN",
                                     image=(user_image_read, 'example.jpg')))

    # Add 2 cars
    with open("src/MasterCSS/tests/testImages/car1.jpg", "rb") as car1_image:
        car1_image_read = BytesIO(car1_image.read())
    response = client.post(CAR_MANAGEMENT_API_URL + '/add',
                           data=dict(
                               make="Honda Civic",
                               seats="2",
                               bodytype="Sedan",
                               home_coordinates="(-37.812082, 144.983072)",
                               fueltype="Petrol",
                               colour="Blue",
                               costperhour='12',
                               totaldistance='0',
                               numberplate="LOL123",
                               image=(car1_image_read, 'car1.jpg'),
                               agent_id="1"),
                           content_type='multipart/form-data')

    with open("src/MasterCSS/tests/testImages/car2.jpg", "rb") as car2_image:
        car2_image_read = BytesIO(car2_image.read())
    client.post(CAR_MANAGEMENT_API_URL + '/add',
                data=dict(make="Honda Civic",
                          seats="2",
                          fueltype="Diesel",
                          bodytype="Sedan",
                          home_coordinates="(-37.812082, 144.983072)",
                          colour="Blue",
                          costperhour='12',
                          totaldistance='0',
                          numberplate="BAB111",
                          image=(car2_image_read, 'car1.jpg'),
                          agent_id="2"),
                content_type='multipart/form-data')
def test_admin_add_admin(client):
    """
    Test admin add account feature: adding another admin.

    :param client: Flask app client
    :type client: Flask app instance
    """
    with open("src/MasterCSS/tests/" + "testImages/example.jpg",
              "rb") as user_image:
        user_image_read = BytesIO(user_image.read())

    response = client.post('/register',
                           data=dict(username="******",
                                     password="******",
                                     email="*****@*****.**",
                                     firstname="admin2",
                                     lastname="admin2",
                                     phonenumber="01231234567890",
                                     usertype="ADMIN",
                                     image=(user_image_read, 'example.jpg')),
                           follow_redirects=True)

    # Should render the new user's details
    assert b'<td>5</td>' in response.data
    assert b'admin2' in response.data
def test_admin_add_manager(client):
    """
    Test admin add account feature: adding a manager.

    :param client: Flask app client
    :type client: Flask app instance
    """
    with open("src/MasterCSS/tests/" + "testImages/example.jpg",
              "rb") as user_image:
        user_image_read = BytesIO(user_image.read())

    response = client.post('/register',
                           data=dict(username="******",
                                     password="******",
                                     email="*****@*****.**",
                                     firstname="manager",
                                     lastname="manager",
                                     phonenumber="123578123",
                                     usertype="MANAGER",
                                     image=(user_image_read, 'example.jpg')),
                           follow_redirects=True)

    # Should render the new user's details
    assert b'<td>4</td>' in response.data
    assert b'manager' in response.data
示例#4
0
def test_login_invalid(client):
    """
    Test login with invalid password

    :param client: Flask app client
    :type client: Flask app instance
    """
    response = client.post('/login',
                           data=dict(username="******", password="******"),
                           follow_redirects=True)
    assert b'Password mismatch!' in response.data
示例#5
0
def test_login_unregistered(client):
    """
    Test login with unregistered user

    :param client: Flask app client
    :type client: Flask app instance
    """
    response = client.post('/login',
                           data=dict(username="******",
                                     password="******"),
                           follow_redirects=True)
    assert b'User not found!' in response.data
示例#6
0
def test_filter_after_book(client):
    """
    Filter car after book. booked car should not be seen.

    :param client: Flask app client
    :type client: Flask app instance
    """
    response = client.post(BOOKING_API_URL + '/confirm',
                           data=dict(
                               pickup_datetime=PICKUP_DATE,
                               return_datetime=RETURN_DATE,
                               car_id=1,
                           ),
                           content_type='multipart/form-data')

    response = client.post(CAR_API_URL + '/filter',
                           data=dict(datetimes=PICKUP_AND_RETURN),
                           content_type='multipart/form-data')

    assert b'Honda CR-V' in response.data
    assert b'Honda Civic' not in response.data
def test_login_as_admin(client):
    """
    Test logging in as admin.

    :param client: Flask app client
    :type client: Flask app instance
    """
    client.get('/logout')
    response = client.post('/login',
                           data=dict(username="******", password="******"),
                           follow_redirects=True)

    assert b'Welcome example!' in response.data
示例#8
0
def test_add_car(client):
    """
    Test adding 2 cars into system to populate data.

    :param client: Flask app client
    :type client: Flask app instance
    """
    with open("src/MasterCSS/tests/testImages/car1.jpg", "rb") as car1_image:
        car1_image_read = BytesIO(car1_image.read())
    response = client.post(CAR_MANAGEMENT_API_URL + '/add',
                           data=dict(
                               make="Honda Civic",
                               seats="2",
                               bodytype="Sedan",
                               home_coordinates="(-37.812082, 144.983072)",
                               fueltype="Petrol",
                               colour="Blue",
                               costperhour='12',
                               totaldistance='0',
                               numberplate="LOL123",
                               image=(car1_image_read, 'car1.jpg'),
                               agent_id="1"),
                           content_type='multipart/form-data')

    with open("src/MasterCSS/tests/testImages/car2.jpg", "rb") as car2_image:
        car2_image_read = BytesIO(car2_image.read())
    client.post(CAR_MANAGEMENT_API_URL + '/add',
                data=dict(make="Honda CR-V",
                          seats="4",
                          fueltype="Diesel",
                          bodytype="SUV",
                          home_coordinates="(-37.806708, 144.968947)",
                          colour="Red",
                          costperhour='18',
                          totaldistance='0',
                          numberplate="BAB111",
                          image=(car2_image_read, 'car2.jpg'),
                          agent_id="2"),
                content_type='multipart/form-data')
示例#9
0
def test_login_valid(client):
    """
    Test login with registered user

    :param client: Flask app client
    :type client: Flask app instance
    """
    response = client.post('/login',
                           data=dict(username="******",
                                     password="******",
                                     follow_redirect=True),
                           follow_redirects=True)
    assert b'Let\'s book you a car!' in response.data
示例#10
0
def test_login_deleted_admin(client):
    """
    Test admin delete account feature: logging in as a deleted admin.

    :param client: Flask app client
    :type client: Flask app instance
    """
    client.get('/logout')
    response = client.post('/login',
                           data=dict(username="******", password="******"),
                           follow_redirects=True)

    assert b'User not found!' in response.data
示例#11
0
def test_login_as_manager(client):
    """
    Test admin add account feature: logging in as manager.

    :param client: Flask app client
    :type client: Flask app instance
    """
    client.get('/logout')
    response = client.post('/login',
                           data=dict(username="******", password="******"),
                           follow_redirects=True)

    assert b'Welcome manager!' in response.data
示例#12
0
def test_login_customer(client):
    """
    Test admin add account feature: logging in as customer.

    :param client: Flask app client
    :type client: Flask app instance
    """
    client.get('/logout')
    response = client.post('/login',
                           data=dict(username="******", password="******"),
                           follow_redirects=True)

    assert b'Let\'s book you a car!' in response.data
示例#13
0
def test_filter_invalid(client):
    """
    Filter cars with invalid datetime.

    :param client: Flask app client
    :type client: Flask app instance
    """
    response = client.post(
        CAR_API_URL + '/filter',
        data=dict(datetimes="19/06/2020 20:00 - 17/06/2020 03:00"),
        content_type='multipart/form-data')

    # Checks if Err message is rendered.
    assert b'Invalid date range! Please try again.' in response.data
示例#14
0
def test_engineer_view_pending(client):
    """
    View pending. resolved issues are not shown.

    :param client: Flask app client
    :type client: Flask app instance
    """
    client.get('/logout')
    client.post(
        '/login',
        data=dict(
            username="******",
            password="******"
        ),
        follow_redirects=True
    )
    response = client.get(ISSUE_API_URL + '/pending')

    assert b'<h1 class="title">Hey engineer these' + \
    b' are the issues still waiting for an engineer.</h1>' \
    in response.data

    # No resolved issues should be shown.
    assert b'<td>Resolved</td>' not in response.data
示例#15
0
def test_delete_admin_self(client):
    """
    Test admin delete account feature: deleting admin oneself (shouldn't work)

    :param client: Flask app client
    :type client: Flask app instance
    """
    client.get('/logout')
    response = client.post('/login',
                           data=dict(username="******", password="******"),
                           follow_redirects=True)
    response = client.get('/users/remove/1')

    assert b'<td>1</td>' in response.data
    assert b'example' in response.data
示例#16
0
def test_delete_manager(client):
    """
    Test admin delete account feature: deleting a manager.

    :param client: Flask app client
    :type client: Flask app instance
    """
    client.get('/logout')
    response = client.post('/login',
                           data=dict(username="******", password="******"),
                           follow_redirects=True)
    response = client.get('/users/remove/4')

    assert b'<td>4</td>' not in response.data
    assert b'manager' not in response.data
示例#17
0
def test_cancel_booking(client):
    """
    Test cancel is successful.

    :param client: Flask app client
    :type client: Flask app instance
    """
    response = client.post(BOOKING_API_URL + '/cancel',
                           data=dict(booking_id=1),
                           content_type='multipart/form-data',
                           follow_redirects=True)

    assert b'Confirmed' not in response.data
    # Make sure cancel button is not rendered
    assert b'button is-danger' not in response.data
    assert b'Canceled' in response.data
示例#18
0
def test_view_car_booking(client):
    """
    Test view booking details when the car is available.

    :param client: Flask app client
    :type client: Flask app instance
    """
    response = client.post(BOOKING_API_URL + '/book',
                           data=dict(
                               pickup_datetime=PICKUP_DATE,
                               return_datetime=RETURN_DATE,
                               car_id=1,
                           ),
                           content_type='multipart/form-data')

    assert b'Available!' in response.data
示例#19
0
def test_create_issue2(client):
    """
    Adds an issue and see if it's reflected in the app.

    :param client: Flask app client
    :type client: Flask app instance
    """
    response = client.post(
        ISSUE_API_URL + '/create/1',
        data=dict(
            title="Example issue 2",
            description="Engine maintenance"
        ),
        follow_redirects=True
    )
    
    assert b'<td>2</td>' in response.data
示例#20
0
def test_create_issue1(client):
    """
    Adds an issue and see if it's reflected in the app.

    :param client: Flask app client
    :type client: Flask app instance
    """
    response = client.post(
        ISSUE_API_URL + '/create/1',
        data=dict(
            title="Example issue 1",
            description="Wheel was punctured by nail."
        ),
        follow_redirects=True
    )
    # Checks if there issue is created.
    assert b'<td>1</td>' in response.data
示例#21
0
def test_confirm_booking(client):
    """
    Test confirm booking should show booking confirmed message.

    :param client: Flask app client
    :type client: Flask app instance
    """
    response = client.post(BOOKING_API_URL + '/confirm',
                           data=dict(
                               pickup_datetime=PICKUP_DATE,
                               return_datetime=RETURN_DATE,
                               car_id=1,
                           ),
                           content_type='multipart/form-data')

    assert response.status_code == 200
    assert b'Your booking has been confirmed, thank you!' in response.data
示例#22
0
def test_search_not_found(client):
    """
    Search car that doesn't exist

    :param client: Flask app client
    :type client: Flask app instance
    """
    response = client.post(CAR_API_URL + '/search',
                           data=dict(make="Hahaha",
                                     seats="100",
                                     fueltype="Sunlight",
                                     colour="Transparent",
                                     pickup_coordinates="(1, 1)",
                                     bodytype="Big foot",
                                     pickup_time=PICKUP_DATE,
                                     return_time=RETURN_DATE))

    assert b'Honda Civic' not in response.data
    assert b'Honda CR-V' not in response.data
示例#23
0
def test_search_make(client):
    """
    Search cars based on make

    :param client: Flask app client
    :type client: Flask app instance
    """
    response = client.post(CAR_API_URL + '/search',
                           data=dict(make="Honda Civic",
                                     seats="Any",
                                     fueltype="Any",
                                     colour="Any",
                                     pickup_coordinates="Any",
                                     bodytype="Any",
                                     pickup_time=PICKUP_DATE,
                                     return_time=RETURN_DATE))

    assert b'Honda Civic' in response.data
    assert b'Honda CR-V' not in response.data
示例#24
0
def test_register_valid(client):
    """
    Test register with valid values

    :param client: Flask app client
    :type client: Flask app instance
    """
    with open("src/MasterCSS/tests/testImages/" + \
                "example.jpg", "rb") as user_image:
        user_image_read = BytesIO(user_image.read())
    response = client.post('/register',
                           data=dict(username="******",
                                     password="******",
                                     email="*****@*****.**",
                                     firstname="alex",
                                     lastname="witedja",
                                     phonenumber="04325672682",
                                     image=(user_image_read, 'example.jpg')))
    assert response.status_code == 302
示例#25
0
def test_register_invalid(client):
    """
    Test register with invalid values

    :param client: Flask app client
    :type client: Flask app instance
    """
    with open("src/MasterCSS/tests/testImages/" + \
                "example.jpg", "rb") as user_image:
        user_image_read = BytesIO(user_image.read())
    response = client.post('/register',
                           data=dict(username="******",
                                     password="******",
                                     email="*****@*****.**",
                                     firstname="a",
                                     lastname="a",
                                     phonenumber="a",
                                     image=(user_image_read, 'example.jpg')))
    assert b'Invalid' in response.data
示例#26
0
def test_search(client):
    """
    Search car with more than one fields as parameter

    :param client: Flask app client
    :type client: Flask app instance
    """
    response = client.post(CAR_API_URL + '/search',
                           data=dict(
                               make="",
                               seats="Any",
                               fueltype="Diesel",
                               colour="Red",
                               pickup_coordinates="(-37.806708, 144.968947)",
                               bodytype="SUV",
                               pickup_time=PICKUP_DATE,
                               return_time=RETURN_DATE))

    assert b'Honda Civic' not in response.data
    assert b'Honda CR-V' in response.data
示例#27
0
def test_setup(client):
    """
    Setup car test by registering user and add cars.

    :param client: Flask app client
    :type client: Flask app instance
    """
    # Register an admin user (includes login)
    with open("src/MasterCSS/tests/" + "testImages/example.jpg",
              "rb") as user_image:
        user_image_read = BytesIO(user_image.read())
    response = client.post('/register',
                           data=dict(username="******",
                                     password="******",
                                     email="*****@*****.**",
                                     firstname="alex",
                                     lastname="witedja",
                                     phonenumber="04325672682",
                                     usertype="ADMIN",
                                     image=(user_image_read, 'example.jpg')))
示例#28
0
def test_view_booking(client):
    """
    Test view booking is showing correct booking information.

    :param client: Flask app client
    :type client: Flask app instance
    """
    response = client.post(BOOKING_API_URL + '/view',
                           data=dict(booking_id=1),
                           content_type='multipart/form-data')

    assert b'Booking ID: 1' in response.data
    assert b'Car ID: </strong> 1' in response.data
    assert b'User ID: </strong> 1' in response.data
    assert b'Pickup time: </strong> ' + \
        str.encode(PICKUP_DATE.strftime(
            DEFAULT_DATETIME_FORMAT)) in response.data
    assert b'Return time: </strong> ' + \
        str.encode(RETURN_DATE.strftime(
            DEFAULT_DATETIME_FORMAT)) in response.data
    assert b'Canceled' in response.data  # previous test canceled this booking.
示例#29
0
def test_change_car_detail(client):
    """
    Test changing details of a car

    :param client: Flask app client
    :type client: Flask app instance
    """
    response = client.post(CAR_MANAGEMENT_API_URL + '/1/modify',
                           data=dict(
                               make="Honda Civic",
                               seats="2",
                               bodytype="Sedan",
                               fueltype="Diesel",
                               home_coordinates="(-37.812082, 144.983072)",
                               colour="Blue",
                               costperhour='12',
                               totaldistance='0',
                               numberplate="AHA456",
                               agent_id="2"),
                           follow_redirects=True)

    assert b'AHA456' in response.data
示例#30
0
def test_filter_cars(client):
    """
    Filter available cars with valid date time.

    :param client: Flask app client
    :type client: Flask app instance
    """
    response = client.post(CAR_API_URL + '/filter',
                           data=dict(datetimes=PICKUP_AND_RETURN),
                           content_type='multipart/form-data')

    # Checks correct template rendered
    assert b'Congrats!' in response.data

    # Checks if the date time is captured properly
    assert b'<code>' + str.encode(PICKUP_DATE.strftime(
        DEFAULT_DATETIME_FORMAT)) + b'</code> to <code>' + str.encode(
            RETURN_DATE.strftime(
                DEFAULT_DATETIME_FORMAT)) + b'</code>' in response.data

    # Test if the previously added cars exists.
    assert b'Honda CR-V' in response.data
    assert b'Honda Civic' in response.data