コード例 #1
0
def calculate_rating_for_all_celery():
    """
    This method is called inside a periodic task initialized below.
    The work of this task if get all restaurants inside the database and
    calculate the rating for each restaurants.
    """
    RestaurantService.calculate_rating_for_all_restaurant()
コード例 #2
0
def calculate_rating_about_restaurant(restaurants_id: int):
    """
    This celery task is called inside the monolith app after a new review
    this give the possibility to maintain the the rating update and run a big task
    only to balance one time of day the rating.
    e.g: the task that we can run one  time per day is calculate_rating_for_all_celery
    :param restaurants_id: the restaurants id were the new review was created
    :return: the rating, only to have some feedback
    """
    RestaurantService.get_avg_rating_restaurant(restaurants_id)
コード例 #3
0
 def test_get_restaurant_rating_restaurant_not_exists(self):
     """
     test about the services restaurant to test the result of getting rating
     for a restaurant that doesn't exist
     :return:
     """
     exception_raised = True
     try:
         RestaurantService.get_avg_rating_restaurant(20)
         assert exception_raised is False
     except:
         assert exception_raised is True
コード例 #4
0
    def test_delete_restaurant_all_info_ok(self):
        """
        test about the services restaurant to test the result of deleting a restaurant
        and all its information (reivews, opening hours, ...)
        :return:
        """
        new_restaurant = Utils.create_restaurant()
        new_table = Utils.create_table(new_restaurant.id)
        new_menu = Utils.create_menu(new_restaurant.id, "Italian food")
        new_menu_photo = Utils.create_menu_photo(new_menu.id,
                                                 "http://testphotomenu.com")
        new_opening1 = Utils.create_openings(new_restaurant.id, 2)
        new_opening2 = Utils.create_openings(new_restaurant.id, 3)
        new_review = Utils.create_review(new_restaurant.id, 3)
        new_photo = Utils.create_photo(new_restaurant.id,
                                       "http://testphoto.com")
        new_dish = Utils.create_dish(new_restaurant.id, "Pizza")

        response = RestaurantService.delete_restaurant(new_restaurant.id)
        assert response is True

        assert Utils.get_restaurant(new_restaurant.id) is None
        assert Utils.get_table(new_table.id) is None
        assert Utils.get_menu(new_menu.id) is None
        assert Utils.get_menu(new_menu_photo.id) is None
        assert len(Utils.get_opening_by_restaurant(new_restaurant.id)) == 0
        assert Utils.get_review(new_review.id) is None
        assert Utils.get_photo(new_photo.id) is None
        assert Utils.get_dish(new_dish.id) is None
コード例 #5
0
 def test_all_restaurant(self):
     """
     test about the services restaurant to test the result of all restaurants
     :return:
     """
     all_restaurants = RestaurantService.get_all_restaurants()
     assert len(all_restaurants) == 2
コード例 #6
0
 def test_get_photo_with_url_not_exists(self):
     """
     test about the services restaurant to test the result of get photo of a
     restaurant uring a not existing URL
     :return:
     """
     photos = RestaurantService.get_photo_with_url("http://phototest1.com")
     assert len(photos) == 0
コード例 #7
0
 def test_get_restaurant_not_exists(self):
     """
     test about the services restaurant to test the result of get a restaurant
     in the case restaurant doesn't exist
     :return:
     """
     restaurant = RestaurantService.get_restaurant(10)
     assert restaurant is None
コード例 #8
0
 def test_delete_restaurant_all_info_not_found(self):
     """
     test about the services restaurant to test the result of deleting a restaurant
     and all its information for a restaurant that doesn't exist
     :return:
     """
     response = RestaurantService.delete_restaurant(100)
     assert response is True
     assert Utils.get_restaurant(100) is None
コード例 #9
0
 def test_get_menu_photos_with_url_not_exist(self):
     """
     test about the services restaurant to test the result of get a photo
     of a menu searching using a not existing URL
     :return:
     """
     photo = RestaurantService.get_menu_photo_with_url(
         "http://phototest1.com")
     assert photo is None
コード例 #10
0
 def test_get_restaurant_keyword_one_result(self):
     """
     test about the services restaurant to test the result of get restaurant
     using a keyword
     :return:
     """
     new_restaurant = Utils.create_restaurant()
     restaurants = RestaurantService.get_restaurants_by_keyword_name("wood")
     assert len(restaurants) == 1
     Utils.delete_restaurant(new_restaurant.id)
コード例 #11
0
 def test_get_menus_no_results(self):
     """
     test about the services restaurant to test the result of get menus of
     a restaurant that doesn't have menus
     :return:
     """
     new_restaurant = Utils.create_restaurant()
     menus = RestaurantService.get_menus(new_restaurant.id)
     assert len(menus) == 0
     Utils.delete_restaurant(new_restaurant.id)
コード例 #12
0
 def test_get_restaurant_keyword_more_results(self):
     """
     test about the services restaurant to test the result of get restaurant
     using a keyword, obteining more results
     :return:
     """
     new_restaurant = Utils.create_restaurant()
     restaurants = RestaurantService.get_restaurants_by_keyword_name("rest")
     assert len(restaurants) == 2
     Utils.delete_restaurant(new_restaurant.id)
コード例 #13
0
 def test_get_restaurant_ok(self):
     """
     test about the services restaurant to test the result of get a restaurant
     :return:
     """
     new_restaurant = Utils.create_restaurant()
     restaurant = RestaurantService.get_restaurant(new_restaurant.id)
     assert restaurant is not None
     assert restaurant.name == "Test restaurant"
     assert restaurant.owner_email == "*****@*****.**"
     Utils.delete_restaurant(new_restaurant.id)
コード例 #14
0
 def test_get_restaurant_keyword_complete_name(self):
     """
     test about the services restaurant to test the result of get restaurant
     using as keyword the name of the restaurant
     :return:
     """
     new_restaurant = Utils.create_restaurant()
     restaurants = RestaurantService.get_restaurants_by_keyword_name(
         "Pepperwood")
     assert len(restaurants) == 1
     Utils.delete_restaurant(new_restaurant.id)
コード例 #15
0
    def test_get_tables_ok(self):
        """
        test about the services restaurant to test the result of get tables of a
        restaurant
        :return:
        """
        new_restaurant = Utils.create_restaurant()
        new_table1 = Utils.create_table(new_restaurant.id)
        new_table2 = Utils.create_table(new_restaurant.id)

        tables = RestaurantService.get_tables(new_restaurant.id)
        assert len(tables) == 2

        query_table = RestaurantService.get_table(new_table1.id)

        assert query_table.id == new_table1.id

        Utils.delete_table(new_table1.id)
        Utils.delete_table(new_table2.id)
        Utils.delete_restaurant(new_restaurant.id)
コード例 #16
0
 def test_get_restaurant_by_email_not_exists(self):
     """
     test about the services restaurant to test the result of get restaurant
     that doesn't exist using owner email
     :return:
     """
     new_restaurant = Utils.create_restaurant()
     restaurant = RestaurantService.get_restaurants_by_owner_email(
         "*****@*****.**")
     assert restaurant is None
     Utils.delete_restaurant(new_restaurant.id)
コード例 #17
0
 def test_get_restaurant_by_email_exist(self):
     """
     test about the services restaurant to test the result of get restaurant
     using owner email
     :return:
     """
     new_restaurant = Utils.create_restaurant()
     restaurant = RestaurantService.get_restaurants_by_owner_email(
         "*****@*****.**")
     assert restaurant == new_restaurant
     Utils.delete_restaurant(new_restaurant.id)
コード例 #18
0
    def test_get_openings_not_exists(self):
        """
        test about the services restaurant to test the result of get opening
        hours of a restaurant without opening hours
        :return:
        """
        new_restaurant = Utils.create_restaurant()

        openings = RestaurantService.get_openings(new_restaurant.id)
        assert len(openings) == 0

        Utils.delete_restaurant(new_restaurant.id)
コード例 #19
0
    def test_get_tables_not_exists(self):
        """
        test about the services restaurant to test the result of get tables of a
        restaurant with no tables
        :return:
        """
        new_restaurant = Utils.create_restaurant()

        tables = RestaurantService.get_tables(new_restaurant.id)
        assert len(tables) == 0

        Utils.delete_restaurant(new_restaurant.id)
コード例 #20
0
    def test_get_photos_not_exists(self):
        """
        test about the services restaurant to test the result of get photos of a
        restaurant with no photos
        :return:
        """
        new_restaurant = Utils.create_restaurant()

        photos = RestaurantService.get_photos(new_restaurant.id)
        assert len(photos) == 0

        Utils.delete_restaurant(new_restaurant.id)
コード例 #21
0
    def test_get_restaurant_rating_ok_empty(self):
        """
        test about the services restaurant to test the result of getting rating
        for a restaurant with no reviews
        :return:
        """
        new_restaurant = Utils.create_restaurant()

        rating = RestaurantService.get_avg_rating_restaurant(new_restaurant.id)
        assert rating == 0

        Utils.delete_restaurant(new_restaurant.id)
コード例 #22
0
    def test_get_reviews_random_not_exists(self):
        """
        test about the services restaurant to test the result of get a number
        of random reviews of a restaurant with no reviews
        :return:
        """
        new_restaurant = Utils.create_restaurant()

        reviews = RestaurantService.get_reviews_random(new_restaurant.id, 5)
        assert len(reviews) == 0

        Utils.delete_restaurant(new_restaurant.id)
コード例 #23
0
    def test_create_restaurant_ok(self):
        """
        test about the services restaurant to test the result of creating a restaurant
        :return:
        """
        body = Utils.json_create_restaurant()

        restaurants = RestaurantService.create_restaurant(body, _max_seats)
        assert restaurants is not None
        assert body["restaurant"]["name"] == restaurants.name
        assert restaurants.id > 0

        Utils.delete_creation_restaurant(body)
コード例 #24
0
    def test_get_reviews_random_0(self):
        """
        test about the services restaurant to test the result of get a number
        of random reviews of a restaurant testing a limit case (number=0)
        :return:
        """
        new_restaurant = Utils.create_restaurant()
        new_review = Utils.create_review(new_restaurant.id, _stars)

        reviews = RestaurantService.get_reviews_random(new_restaurant.id, 0)
        assert len(reviews) == 0

        Utils.delete_review(new_review.id)
        Utils.delete_restaurant(new_restaurant.id)
コード例 #25
0
    def test_get_menu_ok(self):
        """
        test about the services restaurant to test the result of get a menu
        :return:
        """
        new_restaurant = Utils.create_restaurant()
        new_menu = Utils.create_menu(new_restaurant.id, "Italian food")

        menu = RestaurantService.get_menu(new_menu.id)
        assert menu is not None
        assert menu.cusine == "Italian food"

        Utils.delete_menu(new_menu.id)
        Utils.delete_restaurant(new_restaurant.id)
コード例 #26
0
    def test_get_menu_photos_not_exist(self):
        """
        test about the services restaurant to test the result of get photos of a
        menu without photos
        :return:
        """
        new_restaurant = Utils.create_restaurant()
        new_menu = Utils.create_menu(new_restaurant.id, "Italian food")

        photos = RestaurantService.get_menu_photos(new_menu.id)
        assert len(photos) == 0

        Utils.delete_menu(new_menu.id)
        Utils.delete_restaurant(new_restaurant.id)
コード例 #27
0
    def test_get_reviews_ok(self):
        """
        test about the services restaurant to test the result of get reviews of a
        restaurant
        :return:
        """
        new_restaurant = Utils.create_restaurant()
        new_review = Utils.create_review(new_restaurant.id, _stars)

        reviews = RestaurantService.get_reviews(new_restaurant.id)
        assert len(reviews) == 1

        Utils.delete_review(new_review.id)
        Utils.delete_restaurant(new_restaurant.id)
コード例 #28
0
    def test_create_dish_ok(self):
        """
        test about the services restaurant to test the result of creating a dish
        :return:
        """
        new_restaurant = Utils.create_restaurant()
        body = Utils.json_dish()

        response = RestaurantService.create_dish(body["name"], body["price"],
                                                 new_restaurant.id)
        assert response is not None

        Utils.delete_dish_restaurant(new_restaurant.id)
        Utils.delete_restaurant(new_restaurant.id)
コード例 #29
0
    def test_get_reviews_random_bigger_num_ok(self):
        """
        test about the services restaurant to test the result of get a number
        of random reviews bigger of the number of reviews of the restaurant
        :return:
        """
        new_restaurant = Utils.create_restaurant()
        new_review = Utils.create_review(new_restaurant.id, _stars)

        reviews = RestaurantService.get_reviews_random(new_restaurant.id, 3)
        assert len(reviews) == 1

        Utils.delete_review(new_review.id)
        Utils.delete_restaurant(new_restaurant.id)
コード例 #30
0
    def test_create_restaurant_photo_ok(self):
        """
        test about the services restaurant to test the result of creating a
        restaurant photo
        :return:
        """
        new_restaurant = Utils.create_restaurant()
        body = Utils.json_photo()

        response = RestaurantService.create_restaurant_photo(
            body["url"], body["caption"], new_restaurant.id)
        assert response is not None

        Utils.delete_restaurant_photo(new_restaurant.id)
        Utils.delete_restaurant(new_restaurant.id)