Exemplo n.º 1
0
def test_get_recipe_avg_rating_score(api_client):
    new_recipe = RecipeFactory()
    api_client.force_authenticate(new_recipe.author)
    new_recipe = Recipe.objects.all().get(id__exact=new_recipe.id)
    data = {'recipe': new_recipe.id, 'stars': 5}
    api_client.post(rating_create_url, data)
    api_client.logout()

    new_user = UserFactory()
    api_client.force_authenticate(new_user)
    data = {'recipe': new_recipe.id, 'stars': 1}
    api_client.post(rating_create_url, data)

    recipe_avg_stars = Rating.get_recipe_stars_score(recipe=new_recipe)

    assert recipe_avg_stars == 3.0
Exemplo n.º 2
0
        def test_rating_recipe_calculate_recipe_stars(self, api_client):
            recipe = RecipeFactory()
            first_user = UserFactory()
            api_client.force_authenticate(first_user)

            data = {
                'recipe': recipe.id,
                'stars': 4
            }
            api_client.post(rating_rate_url, data)
            api_client.logout()

            second_user = UserFactory()
            api_client.force_authenticate(second_user)
            data = {
                'recipe': recipe.id,
                'stars': 2
            }
            api_client.post(rating_rate_url, data)
            recipe = Recipe.objects.all().get(id=recipe.id)

            assert recipe.stars == '3.0'
            assert recipe.stars == str(Rating.get_recipe_stars_score(recipe=recipe))