diff options
| author | Andreas Pelme | 2014-03-02 12:40:30 +0100 | 
|---|---|---|
| committer | Andreas Pelme | 2014-03-02 12:40:30 +0100 | 
| commit | 971578ca345c3d3bae7fd93b87c41d43483b6f05 (patch) | |
| tree | 72a6d3d0ced5750a8ba01bedc3a6f8a936e05e2f /tests/test_nullable_fields.py | |
| parent | 62786a7ad64918022f11f1b95ce84adb8d798830 (diff) | |
| download | django-rest-framework-971578ca345c3d3bae7fd93b87c41d43483b6f05.tar.bz2 | |
Support for running the test suite with py.test
 * Get rid of runtests.py
 * Moved test code  from rest_framework/tests and rest_framework/runtests to tests
 * Invoke py.test from setup.py
 * Invoke py.test from Travis
 * Invoke py.test from tox
 * Changed setUpClass to be just plain setUp in test_permissions.py
 * Updated contribution guideline to show how to invoke py.test
Diffstat (limited to 'tests/test_nullable_fields.py')
| -rw-r--r-- | tests/test_nullable_fields.py | 30 | 
1 files changed, 30 insertions, 0 deletions
| diff --git a/tests/test_nullable_fields.py b/tests/test_nullable_fields.py new file mode 100644 index 00000000..33a9685f --- /dev/null +++ b/tests/test_nullable_fields.py @@ -0,0 +1,30 @@ +from django.core.urlresolvers import reverse + +from rest_framework.compat import patterns, url +from rest_framework.test import APITestCase +from tests.models import NullableForeignKeySource +from tests.serializers import NullableFKSourceSerializer +from 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 foreign keys when a test +    Client POST/PUT request is made with its own serialized object. +    """ +    urls = 'tests.test_nullable_fields' + +    def test_updating_object_with_null_fk(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) | 
