From b589ab129ff2167c8c27da8947fa7c3e3188f440 Mon Sep 17 00:00:00 2001 From: "ryan.noelk" Date: Fri, 6 Apr 2018 09:51:14 +0200 Subject: [PATCH] adding test for field limiter --- v1/recipe/tests/test_field_limiter.py | 38 +++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 v1/recipe/tests/test_field_limiter.py diff --git a/v1/recipe/tests/test_field_limiter.py b/v1/recipe/tests/test_field_limiter.py new file mode 100644 index 0000000..4be5644 --- /dev/null +++ b/v1/recipe/tests/test_field_limiter.py @@ -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))