django-rest-framework/tests/test_nullable_fields.py

40 lines
1.3 KiB
Python
Raw Normal View History

2014-09-02 20:41:23 +04:00
# from django.core.urlresolvers import reverse
2014-09-02 20:41:23 +04:00
# from django.conf.urls import patterns, url
# from rest_framework import serializers, generics
# from rest_framework.test import APITestCase
# from tests.models import NullableForeignKeySource
2014-09-02 20:41:23 +04:00
# class NullableFKSourceSerializer(serializers.ModelSerializer):
# class Meta:
# model = NullableForeignKeySource
2014-09-02 20:41:23 +04:00
# class NullableFKSourceDetail(generics.RetrieveUpdateDestroyAPIView):
# queryset = NullableForeignKeySource.objects.all()
# serializer_class = NullableFKSourceSerializer
2014-09-02 20:41:23 +04:00
# urlpatterns = patterns(
# '',
# url(r'^objects/(?P<pk>\d+)/$', NullableFKSourceDetail.as_view(), name='object-detail'),
# )
2014-09-02 20:41:23 +04:00
# class NullableForeignKeyTests(APITestCase):
# """
# DRF should be able to handle nullable foreign keys when a test
# Client POST/PUT request is made with its own serialized object.
# """
# urls = 'tests.test_nullable_fields'
2014-09-02 20:41:23 +04:00
# def test_updating_object_with_null_fk(self):
# obj = NullableForeignKeySource(name='example', target=None)
# obj.save()
# serialized_data = NullableFKSourceSerializer(obj).data
2014-09-02 20:41:23 +04:00
# response = self.client.put(reverse('object-detail', args=[obj.pk]), serialized_data)
2014-09-02 20:41:23 +04:00
# self.assertEqual(response.data, serialized_data)