-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
35 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
from rest_framework import status | ||
from rest_framework.authtoken.serializers import serializers | ||
from rest_framework.test import APIClient | ||
from core.models import Recipe | ||
from core.models import Recipe, User | ||
from recipe.serializers import RecipeSerializer | ||
|
||
RECIPE_URL = reverse("recipe:recipe-list") | ||
|
@@ -22,7 +22,6 @@ def create_recipe(user, **params): | |
"time_minutes": 23, | ||
"price": Decimal("4.64"), | ||
"description": "This is a sample recipe description", | ||
"link": "https://example.com", | ||
} | ||
|
||
defaults.update(params) | ||
|
@@ -52,12 +51,13 @@ class PrivateRecipeAPITests(TestCase): | |
""" | ||
|
||
def setUp(self): | ||
self.client = APIClient() | ||
self.user = get_user_model().objects.create_user( | ||
"[email protected]", | ||
"test!password" | ||
self.user = User.objects.create_user( | ||
email="[email protected]", | ||
password="testpassword", | ||
name="TestUserIam", | ||
) | ||
self.client.force_authenticate() | ||
self.client = APIClient() | ||
self.client.force_authenticate(user=self.user) | ||
|
||
def test_retrieve_recipes(self): | ||
"""Tests retrieving recipes""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"""Urls mapping for recipe app""" | ||
|
||
from django.urls import path, include | ||
from rest_framework.routers import DefaultRouter | ||
from recipe import views | ||
|
||
router = DefaultRouter() | ||
router.register("recipes", views.RecipeViewSet) | ||
|
||
app_name = "recipe" | ||
|
||
urlpatterns = [ | ||
path("", include(router.urls)), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,23 @@ | ||
""" | ||
Views for recipe API endpoint | ||
Views for recipe API endpoints | ||
""" | ||
|
||
from rest_framework import viewsets | ||
from rest_framework.authentication import TokenAuthentication | ||
from rest_framework.permissions import IsAuthenticated | ||
|
||
from core.models import Recipe | ||
from serializers import RecipeSerializer | ||
from recipe.serializers import RecipeSerializer | ||
|
||
class RecipeViewSet(viewsets.ModelViewSet): | ||
"""Views to manage Recipe API endpoints""" | ||
|
||
serializer_class = RecipeSerializer | ||
queryset = Recipe.objects.all() | ||
authentication_classes = [TokenAuthentication] | ||
permission_classes = [IsAuthenticated] | ||
|
||
def get_queryset(self): | ||
"""Retrieve recipe for authenticated user""" | ||
|
||
return self.queryset.filter(user=self.request.user).order_by("-id") |