Ejemplo n.º 1
0
    def test_booking_in_past(self):
        """
        check if i can book in the past
        """
        """
        restaurant closed
        """
        user = create_user_on_db(randrange(100000))
        assert user is not None
        rest_owner = create_user_on_db(ran=randrange(100000, 200000),
                                       role_id=3)
        assert rest_owner is not None
        restaurant = create_restaurants_on_db(user_id=rest_owner.id,
                                              user_email=rest_owner.email,
                                              tables=1)

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

        assert book is None

        # 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)
Ejemplo n.º 2
0
    def test_delete_booking(self):
        """
        test for deletion
        """

        user = create_user_on_db(randrange(100000))
        assert user is not None
        rest_owner = create_user_on_db(ran=randrange(100000, 200000),
                                       role_id=3)
        assert rest_owner is not None
        restaurant = create_restaurants_on_db(user_id=rest_owner.id,
                                              user_email=rest_owner.email)

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

        assert "restaurant_name" in book
        assert book["restaurant_name"] == restaurant.name

        # delete the reservation
        BookingServices.delete_book(book["id"], user.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)
Ejemplo n.º 3
0
    def test_get_restaurant_people_none(self):
        """
        The method test the function inside the RestaurantServices to search all the people
        inside the restaurants, the function return an array that looks like
        [people_to_lunch, people_to_dinner, people_checkin]

        Test flow
        - new restaurants
        - get all people
        - del restaurant
        """
        owner_one = create_user_on_db(randrange(10, 50000), role_id=2)
        assert owner_one is not None

        restaurant_one = create_restaurants_on_db(name="First",
                                                  user_id=owner_one.id,
                                                  user_email=owner_one.email)
        assert restaurant_one is not None

        all_people = RestaurantServices.get_restaurant_people(
            restaurant_one.id)
        assert all_people is not None
        assert len(all_people) == 3
        assert all_people[0] == 0
        assert all_people[1] == 0
        assert all_people[2] == 0
        del_restaurant_on_db(restaurant_one.id)
        del_user_on_db(owner_one.id)
Ejemplo n.º 4
0
    def test_checkin_reservation(self):
        """
        test mark checked in a reservation by operator
        """
        owner = create_user_on_db(randrange(1, 500000), role_id=2)
        assert owner is not None

        rest = create_restaurants_on_db(user_id=owner.id,
                                        user_email=owner.email)
        assert rest is not None

        user = create_user_on_db(randrange(1, 500000))
        assert user is not None

        date_time = datetime(2022, 10, 28, 21, 30)

        reservation = create_random_booking(1, rest.id, user, date_time,
                                            "*****@*****.**")

        assert reservation is not None

        response = RestaurantServices.checkin_reservations(reservation["id"])
        assert response is not None

        del_booking(reservation["id"], user.id)
        del_user_on_db(user.id)
        del_user_on_db(owner.id)
        del_restaurant_on_db(rest.id)
Ejemplo n.º 5
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))
        assert user is not None
        rest_owner = create_user_on_db(ran=randrange(100000, 200000),
                                       role_id=3)
        assert rest_owner is not None
        restaurant = create_restaurants_on_db(user_id=rest_owner.id,
                                              user_email=rest_owner.email)
        assert restaurant is not None

        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 "restaurant_name" in book
        assert book["restaurant_name"] == restaurant.name
        assert "restaurant_name" in book2
        assert book2["restaurant_name"] == restaurant.name

        # delete friends
        del_booking_services(book["id"], user.id)
        del_booking_services(book2["id"], user.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)
Ejemplo n.º 6
0
    def test_update_booking(self):
        """
        this test insert two reservation that should be ok
        """
        user = create_user_on_db(randrange(100000))
        assert user is not None
        rest_owner = create_user_on_db(ran=randrange(100000, 200000),
                                       role_id=3)
        assert rest_owner is not None
        restaurant = create_restaurants_on_db(user_id=rest_owner.id,
                                              user_email=rest_owner.email)

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

        assert "restaurant_name" in book
        assert book["restaurant_name"] == restaurant.name

        book = BookingServices.update_book(
            book["id"],
            restaurant.id,
            user.id,
            datetime.datetime(year=2120, month=11, day=25, hour=14),
            2,
            "*****@*****.**",
        )
        assert "restaurant_name" in book
        assert book["restaurant_name"] == restaurant.name

        # delete friends
        del_friends_of_reservation(book["id"])

        # delete reservations
        del_booking_services(book["id"], user.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)
Ejemplo n.º 7
0
    def test_new_booking_overlaps(self):
        """
        overlapped reservations
        """

        user = create_user_on_db(randrange(100000))
        assert user is not None
        rest_owner = create_user_on_db(ran=randrange(100000, 200000),
                                       role_id=3)
        assert rest_owner is not None
        restaurant = create_restaurants_on_db(user_id=rest_owner.id,
                                              user_email=rest_owner.email,
                                              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 "restaurant_name" in book
        assert book["restaurant_name"] == restaurant.name
        assert book2 is None

        # delete friends
        del_friends_of_reservation(book["id"])

        # delete reservations
        del_booking_services(book["id"], user.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)
Ejemplo n.º 8
0
    def test_reservation_local_ok_by_email(self):
        """
        This test cases, tru to test the logic inside the services to avoid
        stupid result

        http://localhost:5000/my_reservations?fromDate=2013-10-07&toDate=2014-10-07&[email protected]
        :return:
        """
        owner = create_user_on_db(randrange(1, 500000), role_id=2)
        assert owner is not None

        rest = create_restaurants_on_db(user_id=owner.id,
                                        user_email=owner.email)
        assert rest is not None

        user = create_user_on_db(randrange(1, 500000), )
        assert user is not None

        date_time = datetime(2022, 10, 28, 21, 30)

        reservation = create_random_booking(1, rest.id, user, date_time,
                                            "*****@*****.**")
        assert reservation is not None

        from_date = datetime(2022, 9, 28)
        to_date = datetime(2022, 11, 28)

        print(BookingServices.get_all_booking())

        search_reservation = BookingServices.get_reservation_by_constraint(
            user.id, from_date, to_date, rest.id)
        print(search_reservation)
        assert len(search_reservation) != 0

        del_booking(reservation["id"], user.id)
        del_user_on_db(user.id)
        del_user_on_db(owner.id)
        del_restaurant_on_db(rest.id)