mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-26 03:23:59 +03:00
Fix slug based put as create test
This commit is contained in:
parent
215edc5dfa
commit
b6c90c0d68
|
@ -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')
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user