Skip to content

Commit

Permalink
adding test for field limiter
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanNoelk committed Apr 6, 2018
1 parent 183426c commit b589ab1
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions v1/recipe/tests/test_field_limiter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python
# encoding: utf-8

from django.test import TestCase
from rest_framework.test import APIRequestFactory
from v1.recipe import views


class RecipeSerializerTests(TestCase):
fixtures = [
'test/users.json',
'course_data.json',
'cuisine_data.json',
'ing_data.json',
'recipe_data.json'
]

def setUp(self):
self.factory = APIRequestFactory()

def test_view_limiter(self):
"""Test to make sure we have the right fields"""
view = views.RecipeViewSet.as_view({'get': 'list'})
request = self.factory.get('/api/v1/recipe/recipes/tasty-chili?fields=id')
response = view(request)

self.assertTrue(response.data.get('id', True))
self.assertFalse(response.data.get('title', False))

view = views.RecipeViewSet.as_view({'get': 'list'})
request = self.factory.get('/api/v1/recipe/recipes/tasty-chili?fields=id,title,photo')
response = view(request)

self.assertTrue(response.data.get('id', True))
self.assertTrue(response.data.get('title', True))
self.assertTrue(response.data.get('photo', True))
self.assertFalse(response.data.get('directions', False))
self.assertFalse(response.data.get('author', False))

0 comments on commit b589ab1

Please sign in to comment.