예제 #1
0
    def test_get_booking_ok(self, client, db):
        Utils.insert_reservation()
        response = client.get("/book/1", follow_redirects=True)
        assert response.status_code == 200
        assert response.json["id"] == 1

        Utils.delete_all_reservations()
예제 #2
0
    def test_checkin_ko(self, client, db):
        reservation = Utils.insert_reservation()

        response = client.get("/book/{}/checkin".format(reservation.id + 1,
                                                        follow_redirects=True))
        assert response.status_code == 404
        Utils.delete_all_reservations()
예제 #3
0
    def test_reservation_to_json_ok(self):
        reservation = Utils.insert_reservation()
        reservation2 = Utils.insert_reservation(people_number=4)
        all_reservations = [reservation, reservation2]

        json_array = BookingService.reservations_to_json(all_reservations,
                                                         what="simple")

        assert len(all_reservations) == len(json_array)
예제 #4
0
    def test_delete_booking_ok(self, client, db):
        reservation = Utils.insert_reservation()
        response = client.delete(
            "/book/{}?user_id={}".format(reservation.id,
                                         reservation.customer_id),
            follow_redirects=True,
        )
        assert response.status_code == 200

        Utils.delete_all_reservations()
예제 #5
0
    def test_get_booking__with_dates_ok(self, client, db):
        Utils.insert_reservation()
        response = client.get(
            "/book/1?fromDate=2021-04-27T12:00:00Z?toDate=2021-04-27T13:00:00Z",
            follow_redirects=True,
        )
        assert response.status_code == 200
        assert response.json["id"] == 1

        Utils.delete_all_reservations()
예제 #6
0
    def test_get_free_tables_ok(self):
        tables = Utils.create_tables_json()
        Utils.insert_reservation(people_number=2)

        py_datetime = datetime.datetime(year=2021,
                                        month=4,
                                        day=27,
                                        hour=12,
                                        minute=30)
        free_tables = BookingService.get_free_tables(tables, 4, py_datetime,
                                                     30)

        # STILL TWO TABLES FREE
        assert len(free_tables) == 2

        Utils.delete_all_reservations()
예제 #7
0
    def test_check_utils_functions(self):
        tables = Utils.create_tables_json()

        Utils.insert_reservation()
        assert Utils.check_number_of_reseservation() == 1
        Utils.delete_all_reservations()
        assert Utils.check_number_of_reseservation() == 0
예제 #8
0
    def test_check_restaurant_openings_ok(self):
        openings = Utils.create_openings_json()
        py_datetime = datetime.datetime(year=2021,
                                        month=4,
                                        day=27,
                                        hour=12,
                                        minute=30)

        # filter opening by week_day
        opening = BookingService.filter_openings(openings,
                                                 py_datetime.weekday())
        assert len(opening) == 1

        # transform opening found in a OpeningHourModel
        openings = Utils.openings_json_to_model(opening)

        # check if the restaurant is open
        result = BookingService.check_restaurant_openings(
            openings[0], py_datetime)
        assert result == True
예제 #9
0
    def test_get_free_tables_ko(self):
        tables = Utils.create_tables_json()
        Utils.insert_reservation(people_number=2)
        Utils.insert_reservation(people_number=3, table_id=2)
        Utils.insert_reservation(people_number=5, table_id=1)

        py_datetime = datetime.datetime(year=2021,
                                        month=4,
                                        day=27,
                                        hour=12,
                                        minute=30)
        free_tables = BookingService.get_free_tables(tables, 4, py_datetime,
                                                     30)

        # NO MORE TABLES
        assert len(free_tables) != 1

        Utils.delete_all_reservations()
예제 #10
0
    def test_check_restaurant_openings_ko_3(self):
        openings = Utils.create_openings_json()
        py_datetime = datetime.datetime(year=2021,
                                        month=4,
                                        day=27,
                                        hour=17,
                                        minute=30)

        # filter opening by week_day
        opening = BookingService.filter_openings(openings,
                                                 py_datetime.weekday())
        assert len(opening) == 1

        # transform opening found in a OpeningHourModel
        openings = Utils.openings_json_to_model(opening)
        # test case: close dinner and py_datetime > close_lunch
        openings[0].close_dinner = None

        # check if the restaurant is open
        result = BookingService.check_restaurant_openings(
            openings[0], py_datetime)
        assert result[1] == 404
예제 #11
0
    def test_get_min_seats_table_ok(self):
        tables = Utils.create_tables_json()

        min_seat_table = BookingService.get_min_seats_table(tables)
        assert min_seat_table == 3
예제 #12
0
    def test_get_table_name_ko(self):
        tables = Utils.create_tables_json()

        result = BookingService.get_table_name(tables, 4)
        assert result == "NO_NAME"
예제 #13
0
    def test_get_table_name_noname_ok(self):
        tables = Utils.create_tables_noname_json()

        result = BookingService.get_table_name(tables, 3)
        assert result == "Table #3"
예제 #14
0
    def test_get_table_name_ok(self):
        tables = Utils.create_tables_json()

        result = BookingService.get_table_name(tables, 1)
        assert result == tables[0]["name"]
예제 #15
0
    def test_fitler_table_min_seats_ko(self):
        tables = Utils.create_tables_json()

        result = BookingService.filter_table_min_seat(tables, 6)
        assert len(result) != len(tables)
예제 #16
0
    def test_filter_openings_ko(self):
        openings = Utils.create_openings_json()

        result = BookingService.filter_openings(openings, week_day=2)
        assert len(result) == 0