Route: GET ALL
parent
2eec63daf6
commit
88c070696d
|
@ -7,4 +7,28 @@ from ..models import Puppy
|
|||
from ..serializers import PuppySerializer
|
||||
|
||||
# initialize the APIClient app
|
||||
client = Client()
|
||||
client = Client()
|
||||
|
||||
class GetAllPuppiesTest(TestCase):
|
||||
"""
|
||||
Test module for GET all puppies API
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
Puppy.objects.create(
|
||||
name='Casper', age=3, breed='Bull Dog', color='Black')
|
||||
Puppy.objects.create(
|
||||
name='Muffin', age=1, breed='Gradane', color='Brown')
|
||||
Puppy.objects.create(
|
||||
name='Rambo', age=2, breed='Labrador', color='Black')
|
||||
Puppy.objects.create(
|
||||
name='Ricky', age=6, breed='Labrador', color='Brown')
|
||||
|
||||
def test_get_all_puppies(self):
|
||||
# get API response
|
||||
response = client.get(reverse('get_post_puppies'))
|
||||
# get data from db
|
||||
puppies = Puppy.objects.all()
|
||||
serializer = PuppySerializer(puppies, many=True)
|
||||
self.assertEqual(response.data, serializer.data)
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
@ -28,6 +28,11 @@ def get_delete_update_puppy(request, pk):
|
|||
def get_post_puppies(request):
|
||||
# get all puppies
|
||||
if request.method == 'GET':
|
||||
puppies = Puppy.objects.all()
|
||||
serializer = PuppySerializer(puppies, many=True) # generate a nested list of 'edit' items
|
||||
return Response(serializer.data)
|
||||
# insert a new record for a puppy
|
||||
elif request.method == 'POST':
|
||||
return Response({})
|
||||
# insert a new record for a puppy
|
||||
elif request.method == 'POST':
|
||||
|
|
Loading…
Reference in New Issue