Exemplo n.º 1
0
import pytest
from django.urls import resolve, reverse

from accounts.models import UserAccount
from factories import RecipeFactory, UserFactory
from recipes.models import Recipe

# add test to get info from recipe detail page
# ------------------------------------------------ Tests
pytestmark = pytest.mark.django_db
recipe_list_url = Recipe.get_list_url()
create_recipe_url = Recipe.get_create_url()
search_recipe_url = Recipe.get_search_url()

followed_users_recipes_url = Recipe.get_followed_users_recipes_url()
top_rated_recipes_url = Recipe.get_top_rated_recipes_url()


class TestRecipeListView:
    class TestAuthenticatedUsers:
        def test_recipe_list_page_render(self, api_client):
            new_user = UserAccount()
            api_client.force_authenticate(new_user)

            recipe_list_page_render = api_client.get(recipe_list_url)

            assert recipe_list_page_render.status_code == 200

    class TestGuestUsers:
        def test_recipe_list_page_render(self, api_client):
            recipe_list_page_render = api_client.get(recipe_list_url)
Exemplo n.º 2
0
def test_get_top_rated_recipes_url():
    assert Recipe.get_top_rated_recipes_url() == reverse('recipes:top')