示例#1
0
    def test_new_booking(self):
        """
        TEST FOR ADDING A RESERVATION
        test flow
        - Create a new customer
        - Create a new restaurant owner
        - create a new restaurant
        - check on Reservation (what we aspect)
        - erase friends from reservation
        - erase opening hours
        - erase restaurants (included the tables)
        - erase user
        """

        user = create_user_on_db(randrange(100000))
        rest_owner = create_user_on_db(ran=2)
        restaurant = create_restaurants_on_db(user_id=rest_owner.id)

        book = BookingServices.book(
            restaurant.id,
            user,
            datetime.datetime(year=2120, month=11, day=25, hour=13),
            4,
            "[email protected];[email protected];[email protected]",
        )

        book2 = BookingServices.book(
            restaurant.id,
            user,
            datetime.datetime(year=2120, month=11, day=25, hour=13),
            6,
            "[email protected];[email protected];[email protected];[email protected];[email protected]",
        )

        assert book[0] is not None
        assert book2[0] is not None

        # delete friends
        del_friends_of_reservation(book[0].id)
        del_friends_of_reservation(book2[0].id)

        # delete reservations
        del_booking_services(book[0].id)
        del_booking_services(book2[0].id)

        # delete restaurants (so also tables)
        del_restaurant_on_db(restaurant.id)

        # delete users
        del_user_on_db(user.id)
        del_user_on_db(rest_owner.id)

        # AT THE END THERE MUST TO BE ONLY ONE RESERVATION
        q = db.session.query(func.count(Reservation.id)).scalar()
        assert q == 1
示例#2
0
    def test_new_booking_overlaps(self):
        """
        overlapped reservations
        """

        user = create_user_on_db()
        rest_owner = create_user_on_db(ran=2)
        restaurant = create_restaurants_on_db(user_id=rest_owner.id, tables=1)

        book = BookingServices.book(
            restaurant.id,
            user,
            datetime.datetime(year=2120, month=11, day=25, hour=13),
            4,
            "[email protected];[email protected];[email protected]",
        )

        book2 = BookingServices.book(
            restaurant.id,
            user,
            datetime.datetime(year=2120, month=11, day=25, hour=13, minute=29),
            6,
            "[email protected];[email protected];[email protected];[email protected];[email protected]",
        )

        assert book[0] is not None
        assert book2[0] is None

        # delete friends
        del_friends_of_reservation(book[0].id)

        # delete reservations
        del_booking_services(book[0].id)

        # delete restaurants (so also tables)
        del_restaurant_on_db(restaurant.id)

        # delete users
        del_user_on_db(user.id)
        del_user_on_db(rest_owner.id)

        # AT THE END THERE MUST TO BE ONLY ONE RESERVATION
        q = db.session.query(func.count(Reservation.id)).scalar()
        assert q == 1
示例#3
0
    def test_update_booking(self):
        """
        this test insert two reservation that should be ok
        """
        user = create_user_on_db()
        rest_owner = create_user_on_db(ran=2)
        restaurant = create_restaurants_on_db(user_id=rest_owner.id)

        book = BookingServices.book(
            restaurant.id,
            user,
            datetime.datetime(year=2120, month=11, day=25, hour=13),
            4,
            "[email protected];[email protected];[email protected]",
        )

        assert book[0] is not None

        book = BookingServices.update_book(
            book[0].id,
            user,
            datetime.datetime(year=2120, month=11, day=25, hour=14),
            2,
            "*****@*****.**",
        )
        assert book[0] is not None

        # delete friends
        del_friends_of_reservation(book[0].id)

        # delete reservations
        del_booking_services(book[0].id)

        # delete restaurants (so also tables)
        del_restaurant_on_db(restaurant.id)

        # delete users
        del_user_on_db(user.id)
        del_user_on_db(rest_owner.id)

        # AT THE END THERE MUST TO BE ONLY ONE RESERVATION
        q = db.session.query(func.count(Reservation.id)).scalar()
        assert q == 1