From b6c90c0d684cd036a2ce874fd9ace7a8a2bfda2f Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Mon, 29 Oct 2012 17:20:06 +0000 Subject: [PATCH] Fix slug based put as create test --- rest_framework/tests/generics.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/rest_framework/tests/generics.py b/rest_framework/tests/generics.py index ef5edd58d..d45ea9760 100644 --- a/rest_framework/tests/generics.py +++ b/rest_framework/tests/generics.py @@ -22,11 +22,20 @@ class InstanceView(generics.RetrieveUpdateDestroyAPIView): model = BasicModel +class SlugSerializer(serializers.ModelSerializer): + slug = serializers.Field() # read only + + class Meta: + model = SlugBasedModel + exclude = ('id',) + + class SlugBasedInstanceView(InstanceView): """ A model with a slug-field. """ model = SlugBasedModel + serializer_class = SlugSerializer class TestRootView(TestCase): @@ -254,10 +263,10 @@ class TestInstanceView(TestCase): content = {'text': 'foobar'} request = factory.put('/test_slug', json.dumps(content), content_type='application/json') - response = self.slug_based_view(request, pk='test_slug').render() + response = self.slug_based_view(request, slug='test_slug').render() self.assertEquals(response.status_code, status.HTTP_200_OK) self.assertEquals(response.data, {'slug': 'test_slug', 'text': 'foobar'}) - new_obj = self.objects.get(slug='test_slug') + new_obj = SlugBasedModel.objects.get(slug='test_slug') self.assertEquals(new_obj.text, 'foobar')