Exemple #1
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
        """
        form = RestaurantForm()
        form.name.data = "rest_mock_{}".format(randrange(10000))
        form.phone.data = "096321343{}".format(randrange(10000))
        form.lat.data = 12
        form.lon.data = 12
        form.n_tables.data = 50
        form.covid_measures.data = "Random comment {}".format(randrange(10000))
        form.cuisine.data = ["Italian food"]
        form.open_days.data = ["0"]
        form.open_lunch.data = datetime.time(datetime(2020, 7, 1, 12, 00))
        form.close_lunch.data = datetime.time(datetime(2020, 7, 1, 12, 00))
        form.open_dinner.data = datetime.time(datetime(2020, 7, 1, 18, 00))
        form.close_dinner.data = datetime.time(datetime(2020, 6, 1, 22, 00))

        user = create_user_on_db(randrange(6000, 9000), role_id=2)
        assert user is not None
        assert user.role_id == 2

        restaurant = RestaurantServices.create_new_restaurant(
            form, user.id, 6, user.email)
        assert restaurant is not None
        rest_by_name = RestaurantServices.get_restaurants_by_keyword(
            name=restaurant.name)
        assert len(rest_by_name) is 1

        del_user_on_db(user.id)
        RestaurantServices.delete_restaurant(restaurant.id)
Exemple #2
0
    def test_create_restaurant(self):
        """
        test create user
        :return:
        """
        form = RestaurantForm()
        form.name.data = "rest_mock_{}".format(randrange(10000))
        form.phone.data = "096321343{}".format(randrange(10000))
        form.lat.data = 12
        form.lon.data = 12
        form.n_tables.data = 50
        form.covid_measures.data = "Random comment {}".format(randrange(10000))
        form.cuisine.data = ["Italian food"]
        form.open_days.data = ["0"]
        form.open_lunch.data = datetime.time(datetime(2020, 7, 1, 12, 00))
        form.close_lunch.data = datetime.time(datetime(2020, 7, 1, 12, 00))
        form.open_dinner.data = datetime.time(datetime(2020, 7, 1, 18, 00))
        form.close_dinner.data = datetime.time(datetime(2020, 6, 1, 22, 00))

        user = create_user_on_db(randrange(1, 60000), role_id=2)
        assert user is not None
        assert user.role_id == 2

        restaurant = RestaurantServices.create_new_restaurant(
            form, user.id, 6, user.email)
        assert restaurant is not None

        ## This call should be delete also the restaurants
        del_user_on_db(user.id)
        RestaurantServices.delete_restaurant(restaurant.id)
Exemple #3
0
    def test_restaurant_name(self):
        """
        check the function that return the restaurant name
        """
        form = RestaurantForm()
        form.name.data = "rest_mock_{}".format(randrange(10000))
        form.phone.data = "096321343{}".format(randrange(10000))
        form.lat.data = 12
        form.lon.data = 12
        form.n_tables.data = 50
        form.covid_measures.data = "Random comment {}".format(randrange(10000))
        form.cuisine.data = ["Italian food"]
        form.open_days.data = ["0"]
        form.open_lunch.data = datetime.time(datetime(2020, 7, 1, 12, 00))
        form.close_lunch.data = datetime.time(datetime(2020, 7, 1, 12, 00))
        form.open_dinner.data = datetime.time(datetime(2020, 7, 1, 18, 00))
        form.close_dinner.data = datetime.time(datetime(2020, 6, 1, 22, 00))

        user = create_user_on_db(randrange(10, 50000), role_id=2)
        assert user is not None
        assert user.role_id == 2

        restaurant = RestaurantServices.create_new_restaurant(
            form, user, 6, user.email)
        assert restaurant is not None

        name = RestaurantServices.get_restaurant_name(restaurant.id)
        assert restaurant.name == name

        ## This call should be delete also the restaurants
        # At this point also the review should be killed with the restaurants
        del_user_on_db(user.id)
        RestaurantServices.delete_restaurant(restaurant.id)
Exemple #4
0
    def test_three_reviews(self):
        """
        check the three reviews fetcher
        """
        form = RestaurantForm()
        form.name.data = "rest_mock_{}".format(randrange(10000))
        form.phone.data = "096321343{}".format(randrange(10000))
        form.lat.data = 12
        form.lon.data = 12
        form.n_tables.data = 50
        form.covid_measures.data = "Random comment {}".format(randrange(10000))
        form.cuisine.data = ["Italian food"]
        form.open_days.data = ["0"]
        form.open_lunch.data = datetime.time(datetime(2020, 7, 1, 12, 00))
        form.close_lunch.data = datetime.time(datetime(2020, 7, 1, 12, 00))
        form.open_dinner.data = datetime.time(datetime(2020, 7, 1, 18, 00))
        form.close_dinner.data = datetime.time(datetime(2020, 6, 1, 22, 00))

        user = create_user_on_db(randrange(10, 50000), role_id=2)
        assert user is not None
        assert user.role_id == 2

        restaurant = RestaurantServices.create_new_restaurant(
            form, user.id, 6, user.email)
        assert restaurant is not None

        reviewer = create_user_on_db(randrange(10, 50000), role_id=3)

        review1 = RestaurantServices.review_restaurant(restaurant.id,
                                                       reviewer.email, 5,
                                                       "test1")
        assert review1 is not None
        review2 = RestaurantServices.review_restaurant(restaurant.id,
                                                       reviewer.email, 4,
                                                       "test2")
        assert review2 is not None
        review3 = RestaurantServices.review_restaurant(restaurant.id,
                                                       reviewer.email, 3,
                                                       "test3")
        assert review3 is not None

        three_reviews = RestaurantServices.get_three_reviews(restaurant.id)
        assert three_reviews is not None
        assert len(three_reviews) == 3

        ## This call should be delete also the restaurants
        # At this point also the review should be killed with the restaurants
        del_user_on_db(user.id)
        del_user_on_db(reviewer.id)
        RestaurantServices.delete_restaurant(restaurant.id)
Exemple #5
0
def my_data():
    """
    This API call give the possibility to the user modify the restaurants
    """
    message = None
    if request.method == "POST":
        # update restaurant
        restaurant_modified = RestaurantServices.update_restaurant(
            session["RESTAURANT_ID"],
            request.form.get("name"),
            request.form.get("lat"),
            request.form.get("lon"),
            request.form.get("covid_measures"),
        )
        # if no resturant match the update query (session problem probably)
        if restaurant_modified:
            message = "Some errors occurs during modification. PLease try again later"
        else:
            message = "Restaurant data has been modified."

    # get the restaurants info and fill the form
    # this part is both for POST and GET requests
    restaurant = RestaurantServices.get_rest_by_id(session["RESTAURANT_ID"])
    if restaurant is not None:
        form = RestaurantForm(obj=restaurant)
        form2 = RestaurantTableForm()
        # get all tables
        tables = RestaurantServices.get_restaurant_tables(
            session["RESTAURANT_ID"])
        return render_template(
            "restaurant_data.html",
            form=form,
            only=["name", "lat", "lon", "covid_measures"],
            tables=tables,
            form2=form2,
            message=message,
        )
    else:
        return redirect("/restaurant/create")
Exemple #6
0
def create_restaurants_on_db(
    name: str = "mock_rest{}".format(randrange(1000, 50000)),
    user_id: int = None,
    user_email: str = None,
    tables: int = 50,
):
    form = RestaurantForm()
    form.name.data = name
    form.phone.data = "1234{}".format(randrange(1000, 50000))
    form.lat.data = 183
    form.lon.data = 134
    form.n_tables.data = tables
    form.covid_measures.data = "We can survive{}".format(randrange(
        1000, 50000))
    form.cuisine.data = ["Italian food"]
    form.open_days.data = ["0", "1", "2", "3", "4", "5", "6"]
    form.open_lunch.data = time(hour=12, minute=00)
    form.close_lunch.data = time(hour=15, minute=00)
    form.open_dinner.data = time(hour=19, minute=00)
    form.close_dinner.data = time(hour=22, minute=00)
    return RestaurantServices.create_new_restaurant(form,
                                                    user_id=user_id,
                                                    user_email=user_email,
                                                    max_sit=6)
Exemple #7
0
def create_restaurant():
    """
    This flask method give the possibility with a POST request to create a new
    restaurant inside the system
    """
    form = RestaurantForm()
    if request.method == "POST":
        # TODO check why it's not working this if statement below
        # if form.validate_on_submit():
        current_app.logger.debug("Check if user {} si present".format(
            current_user.email))
        user = UserService.user_is_present(current_user.email)
        if user is None:
            return render_template(
                "create_restaurant.html",
                _test="anonymus_user_test",
                form=form,
                message="User not logged",
            )

        # create the restaurant
        newrestaurant = RestaurantServices.create_new_restaurant(
            form, current_user.id, _max_seats)
        if newrestaurant is None:
            return render_template(
                "create_restaurant.html",
                _test="create_rest_failed",
                form=form,
                message="Error on create services",
            )
        session["RESTAURANT_ID"] = newrestaurant.id
        session["RESTAURANT_NAME"] = newrestaurant.name
        return redirect("/")
    return render_template("create_restaurant.html",
                           _test="create_rest_test",
                           form=form)