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)
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
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)
def test_get_restaurant_rating_ok_0(self): """ test about the services restaurant to test the result of getting rating for a restaurant whose rating is 0 :return: """ new_restaurant = Utils.create_restaurant() new_review1 = Utils.create_review(new_restaurant.id, 0) new_review2 = Utils.create_review(new_restaurant.id, 0) rating = RestaurantService.get_avg_rating_restaurant(new_restaurant.id) assert rating == 0 Utils.delete_review(new_review1.id) Utils.delete_review(new_review2.id) Utils.delete_restaurant(new_restaurant.id)
def test_get_restaurant_rating_ok_not_0(self): """ test about the services restaurant to test the result of getting rating for a restaurant whose rating is different from 0 :return: """ new_restaurant = Utils.create_restaurant() new_review1 = Utils.create_review(new_restaurant.id, 3) new_review2 = Utils.create_review(new_restaurant.id, 5) new_review3 = Utils.create_review(new_restaurant.id, 2.5) rating = RestaurantService.get_avg_rating_restaurant(new_restaurant.id) assert rating == 3.5 Utils.delete_review(new_review1.id) Utils.delete_review(new_review2.id) Utils.delete_review(new_review3.id) Utils.delete_restaurant(new_restaurant.id)