Finished GET Single
parent
88c070696d
commit
219b5ae604
|
@ -31,4 +31,30 @@ class GetAllPuppiesTest(TestCase):
|
|||
puppies = Puppy.objects.all()
|
||||
serializer = PuppySerializer(puppies, many=True)
|
||||
self.assertEqual(response.data, serializer.data)
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
class GetSinglePuppyTest(TestCase):
|
||||
""" Test module for GET single puppy API """
|
||||
|
||||
def setUp(self):
|
||||
self.casper = Puppy.objects.create(
|
||||
name='Casper', age=3, breed='Bull Dog', color='Black')
|
||||
self.muffin = Puppy.objects.create(
|
||||
name='Muffin', age=1, breed='Gradane', color='Brown')
|
||||
self.rambo = Puppy.objects.create(
|
||||
name='Rambo', age=2, breed='Labrador', color='Black')
|
||||
self.ricky = Puppy.objects.create(
|
||||
name='Ricky', age=6, breed='Labrador', color='Brown')
|
||||
|
||||
def test_get_valid_single_puppy(self):
|
||||
response = client.get(
|
||||
reverse('get_delete_update_puppy', kwargs={'pk': self.rambo.pk}))
|
||||
puppy = Puppy.objects.get(pk=self.rambo.pk)
|
||||
serializer = PuppySerializer(puppy)
|
||||
self.assertEqual(response.data, serializer.data)
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
def test_get_invalid_single_puppy(self):
|
||||
response = client.get(
|
||||
reverse('get_delete_update_puppy', kwargs={'pk': 30}))
|
||||
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
|
||||
|
|
|
@ -7,7 +7,7 @@ from rest_framework import status
|
|||
from .models import Puppy
|
||||
from .serializers import PuppySerializer
|
||||
|
||||
@api_view(['GET', 'DELETE', 'PUT'])
|
||||
@api_view(['GET', 'DELETE', 'UPDATE'])
|
||||
def get_delete_update_puppy(request, pk):
|
||||
try:
|
||||
puppy = Puppy.objects.get(pk=pk)
|
||||
|
@ -16,7 +16,9 @@ def get_delete_update_puppy(request, pk):
|
|||
|
||||
# get details of a single puppy
|
||||
if request.method == 'GET':
|
||||
return Response({})
|
||||
# we get the puppy using an ID. Run the tests to ensure they all pass.
|
||||
serializer = PuppySerializer(puppy)
|
||||
return Response(serializer.data)
|
||||
# delete a single puppy
|
||||
elif request.method == 'DELETE':
|
||||
return Response({})
|
||||
|
|
Loading…
Reference in New Issue