示例#1
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(12345543234)
        assert owner is not None

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

        user = create_user_on_db(123455432332)
        assert user is not None

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

        books = create_random_booking(1, rest.id, user, date_time, "*****@*****.**")
        assert len(books) == 1

        from_date = "2020-09-28"
        to_date = "2020-11-28"

        reservations = RestaurantServices.get_reservation_rest(
            rest.owner_id, rest.id, from_date, to_date, user.email)
        assert len(reservations) == 1

        del_user_on_db(user.id)
        del_restaurant_on_db(rest.id)
示例#2
0
    def test_booking_in_past(self):
        """
        check if i can book in the past
        """
        """
        restaurant closed
        """
        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=1999, month=11, day=25, hour=10),
            4,
            "[email protected];[email protected];[email protected]",
        )

        assert book[0] 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)

        # 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_delete_booking(self):
        """
        test for deletion
        """

        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=12),
            6,
            "[email protected];[email protected];[email protected];[email protected];[email protected]",
        )

        assert book[0] is not None

        # delete the reservation
        BookingServices.delete_book(book[0].id, user.id)
        # check how many reservations
        q = db.session.query(func.count(Reservation.id)).scalar()
        assert q == 1

        # 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)
示例#4
0
    def test_rating_review_restaurants(self):
        """
        This method test the function called by celery to calculate the rating of all restaurants

        Test flow:
        - Create 2 owner
        - Create 2 restaurants and binding owner
        - Create a customer
        - Make a review for the restaurants
        - calculate the rating for all restaurants
        - check on db the new rating
        - erase all data create inside the test
        """
        owner_one = create_user_on_db(123444223)
        assert owner_one is not None
        owner_two = create_user_on_db(123444226)
        assert owner_two is not None

        restaurant_one = create_restaurants_on_db(name="First",
                                                  user_id=owner_one.id)
        assert restaurant_one is not None
        restaurant_two = create_restaurants_on_db(name="Second",
                                                  user_id=owner_two.id)
        assert restaurant_two is not None

        start_one = 3.0
        start_two = 5.0
        review = create_review_for_restaurants(starts=start_one,
                                               rest_id=restaurant_one.id)
        assert review is not None
        review = create_review_for_restaurants(starts=start_two,
                                               rest_id=restaurant_one.id)
        assert review is not None

        start_tree = 2.0
        review = create_review_for_restaurants(starts=start_tree,
                                               rest_id=restaurant_two.id)
        assert review is not None

        rating_rest_one = (start_one + start_two) / 2
        rating_rest_two = start_tree

        RestaurantServices.calculate_rating_for_all()

        rest = get_rest_with_name(restaurant_one.name)
        assert rest.rating == rating_rest_one
        rest = get_rest_with_name(restaurant_two.name)
        assert rest.rating == rating_rest_two

        del_all_review_for_rest(restaurant_one.id)
        del_all_review_for_rest(restaurant_two.id)
        del_restaurant_on_db(restaurant_one.id)
        del_restaurant_on_db(restaurant_two.id)
        del_user_on_db(owner_one.id)
        del_user_on_db(owner_two.id)
示例#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))
        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
示例#6
0
    def test_search_contacts_user_with_booking(self):
        """
        Searching for list of contacts of a covid-19 positive
        customer with bookings
        """

        owner = create_user_on_db(787436)
        assert owner is not None
        restaurant = create_restaurants_on_db("Pepperwood", user_id=owner.id)
        assert restaurant is not None

        customer1 = create_user_on_db(787437)
        assert customer1 is not None

        date_booking_1 = (get_today_midnight() -
                          timedelta(days=datetime.today().weekday()) +
                          timedelta(hours=13))
        books1 = create_random_booking(1, restaurant.id, customer1,
                                       date_booking_1, "*****@*****.**")

        assert len(books1) == 1

        # a new user that books in the same restaurant of the previous one
        customer2 = create_user_on_db(787438)
        assert customer2 is not None

        date_booking_2 = (get_today_midnight() -
                          timedelta(days=datetime.today().weekday()) +
                          timedelta(hours=13))
        books2 = create_random_booking(1, restaurant.id, customer2,
                                       date_booking_2, "*****@*****.**")
        assert len(books2) == 1

        # an user become covid19 positive
        positive = positive_with_user_id(customer1.id)
        assert positive is None
        message = HealthyServices.mark_positive(user_phone=customer1.phone)
        assert len(message) == 0

        q_already_positive = (db.session.query(Positive).filter_by(
            user_id=customer1.id, marked=True).first())
        assert q_already_positive is not None

        contacts = HealthyServices.search_contacts(customer1.id)
        assert len(contacts) == 1

        message = HealthyServices.unmark_positive("", customer1.phone)
        assert len(message) == 0

        del_user_on_db(customer1.id)
        del_user_on_db(customer2.id)
        del_restaurant_on_db(restaurant.id)
示例#7
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(100000))
        assert owner_one is not None

        restaurant_one = create_restaurants_on_db(name="First",
                                                  user_id=owner_one.id)
        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)
示例#8
0
    def test_search_restaurant_by_key_ok_partial_name(self):
        """
        This test unit test the service to perform the search by keyword of the restaurants
        on persistence
        """
        user = create_user_on_db()
        rest = create_restaurants_on_db("Gino Sorbillo", user.id)
        assert rest is not None
        rest_by_name = RestaurantServices.get_restaurants_by_keyword(
            name=rest.name)
        assert len(rest_by_name) is 1

        rest_by_name = RestaurantServices.get_restaurants_by_keyword(
            name="Gino")
        assert len(rest_by_name) is 1

        rest_by_name = RestaurantServices.get_restaurants_by_keyword(
            name="gino")
        assert len(rest_by_name) is 1

        rest_by_name = RestaurantServices.get_restaurants_by_keyword(
            name="Sorbillo")
        assert len(rest_by_name) is 1

        rest_by_name = RestaurantServices.get_restaurants_by_keyword(
            name="sorbillo")
        assert len(rest_by_name) is 1

        del_user_on_db(user.id)
        for rest in rest_by_name:
            del_restaurant_on_db(rest.id)
示例#9
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
示例#10
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
示例#11
0
 def test_mark_positive_user_precondition(self):
     """
     It tests that a new user is not positive
     """
     # an operator
     user = create_user_on_db()
     assert user is not None
     assert user.role_id is 3
     positive = positive_with_user_id(user.id, marked=True)
     assert positive is None
     delete_positive_with_user_id(user.id)
     del_user_on_db(user.id)
示例#12
0
 def test_mark_positive_user_by_phone(self):
     """
     It tests that health authority can mark a customer as covid-19
     positive using only the customer's phone number
     """
     user = create_user_on_db()
     assert user is not None
     positive = positive_with_user_id(user.id)
     assert positive is None
     message = HealthyServices.mark_positive("", user.phone)
     assert len(message) is 0
     delete_positive_with_user_id(user.id)
     del_user_on_db(user.id)
示例#13
0
 def test_mark_positive_user_by_email(self):
     """
     It tests that health authority can mark a customer as covid-19
     positive using only the customer's email
     """
     user = create_user_on_db()
     assert user is not None
     assert user.role_id is 3
     assert user is not None
     positive = positive_with_user_id(user.id)
     assert positive is None
     message = HealthyServices.mark_positive(user.email, "")
     assert len(message) is 0
     delete_positive_with_user_id(user.id)
     del_user_on_db(user.id)
示例#14
0
 def test_mark_positive_ok(self):
     """
     It tests that a user is correctly marked as covid-19 positive by
     health authority
     """
     # an operator
     user = create_user_on_db()
     assert user is not None
     assert user.role_id is 3
     positive = positive_with_user_id(user.id)
     assert positive is None
     message = HealthyServices.mark_positive(user.email, user.phone)
     assert len(message) is 0
     delete_positive_with_user_id(user.id)
     del_user_on_db(user.id)
示例#15
0
    def test_unmark_user_not_positive(self):
        """
        It tests that health authority cannot mark a customer as healed
        if the customer is not covid-19 positive
        """
        user = create_user_on_db()
        assert user is not None
        assert user.role_id is 3

        message = HealthyServices.unmark_positive(user.email, user.phone)
        assert message == "User with email {} is not Covid-19 positive".format(
            user.email)

        delete_positive_with_user_id(user.id)
        del_user_on_db(user.id)
示例#16
0
 def test_mark_positive_already_covid(self):
     """
     It tests that a customer can't be marked as covid-19 positive if
     he is already covid-19 positive
     """
     user = create_user_on_db()
     assert user is not None
     assert user.role_id is 3
     positive = positive_with_user_id(user.id)
     assert positive is None
     message = HealthyServices.mark_positive(user.email, user.phone)
     assert len(message) is 0
     message = HealthyServices.mark_positive(user.email, user.phone)
     assert message == "User with email {} already Covid-19 positive".format(
         user.email)
     delete_positive_with_user_id(user.id)
     del_user_on_db(user.id)
示例#17
0
    def test_unmark_positive_ok(self):
        """
        It tests that health authority can mark a customer as healed
        using customer's email and phone number
        """
        user = create_user_on_db()
        assert user is not None
        assert user.role_id is 3
        positive = positive_with_user_id(user.id)
        assert positive is None
        message = HealthyServices.mark_positive(user.email, user.phone)
        assert len(message) is 0

        message = HealthyServices.unmark_positive(user.email, user.phone)
        assert len(message) is 0

        delete_was_positive_with_user_id(user.id)
        del_user_on_db(user.id)
示例#18
0
    def test_search_contacts_user_with_no_booking(self):
        """
        Searching for list of contacts of a covid-19 positive
        customer with no bookings
        """
        user = create_user_on_db()
        assert user is not None
        assert user.role_id is 3
        positive = positive_with_user_id(user.id)
        assert positive is None
        message = HealthyServices.mark_positive("", user.phone)
        assert len(message) is 0

        contacts = HealthyServices.search_contacts(user.id)
        assert len(contacts) is 0

        message = HealthyServices.unmark_positive("", user.phone)
        assert len(message) is 0

        delete_was_positive_with_user_id(user.id)
        del_user_on_db(user.id)
示例#19
0
    def test_rating_single_restaurant(self):
        """
        This method test the method to calculate a rating inside a new restautants

        Test flow:
        - Create owner
        - Create restaurant1 and binding owner
        - Create a customer
        - Make a review for the restaurant
        - check the result of the function
        - check on bd the new rating
        - erase all data create inside the test
        """
        owner_one = create_user_on_db(randrange(100000))
        assert owner_one is not None

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

        start_one = 3.0
        start_two = 4.5
        review = create_review_for_restaurants(starts=start_one,
                                               rest_id=restaurant_one.id)
        assert review is not None
        review = create_review_for_restaurants(starts=start_two,
                                               rest_id=restaurant_one.id)
        assert review is not None

        rating_rest_one = (start_one + start_two) / 2.0

        rating = RestaurantServices.get_rating_restaurant(restaurant_one.id)
        assert rating == rating_rest_one

        rest = get_rest_with_name(restaurant_one.name)
        assert rest.rating == rating_rest_one

        del_all_review_for_rest(restaurant_one.id)
        del_restaurant_on_db(restaurant_one.id)
        del_user_on_db(owner_one.id)