mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-23 15:54:16 +03:00
Demonstrate problem post/put'ing serialized data that contains 'None'
This commit is contained in:
parent
6e92e415aa
commit
505f1173d0
8
rest_framework/tests/serializers.py
Normal file
8
rest_framework/tests/serializers.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
from rest_framework import serializers
|
||||
|
||||
from rest_framework.tests.models import NullableForeignKeySource
|
||||
|
||||
|
||||
class NullableFKSourceSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = NullableForeignKeySource
|
30
rest_framework/tests/test_nullable_fields.py
Normal file
30
rest_framework/tests/test_nullable_fields.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
from django.core.urlresolvers import reverse
|
||||
|
||||
from rest_framework.compat import patterns, url
|
||||
from rest_framework.test import APITestCase
|
||||
from rest_framework.tests.models import NullableForeignKeySource
|
||||
from rest_framework.tests.serializers import NullableFKSourceSerializer
|
||||
from rest_framework.tests.views import NullableFKSourceDetail
|
||||
|
||||
|
||||
urlpatterns = patterns(
|
||||
'',
|
||||
url(r'^objects/(?P<pk>\d+)/$', NullableFKSourceDetail.as_view(), name='object-detail'),
|
||||
)
|
||||
|
||||
|
||||
class NullableForeignKeyTests(APITestCase):
|
||||
"""
|
||||
DRF should be able to handle nullable fields when a TestClient
|
||||
POST/PUT request is made with its own serialized object.
|
||||
"""
|
||||
urls = 'rest_framework.tests.test_nullable_fields'
|
||||
|
||||
def test_updating_object_with_null_field_value(self):
|
||||
obj = NullableForeignKeySource(name='example', target=None)
|
||||
obj.save()
|
||||
serialized_data = NullableFKSourceSerializer(obj).data
|
||||
|
||||
response = self.client.put(reverse('object-detail', args=[obj.pk]), serialized_data)
|
||||
|
||||
self.assertEqual(response.data, serialized_data)
|
8
rest_framework/tests/views.py
Normal file
8
rest_framework/tests/views.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
from rest_framework import generics
|
||||
from rest_framework.tests.models import NullableForeignKeySource
|
||||
from rest_framework.tests.serializers import NullableFKSourceSerializer
|
||||
|
||||
|
||||
class NullableFKSourceDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
model = NullableForeignKeySource
|
||||
model_serializer_class = NullableFKSourceSerializer
|
Loading…
Reference in New Issue
Block a user