diff options
| author | Tom Christie | 2012-12-29 13:32:49 +0000 |
|---|---|---|
| committer | Tom Christie | 2012-12-29 13:33:03 +0000 |
| commit | bf69205cd33fc1601e5ae3c0c48ffcff1a62470b (patch) | |
| tree | 23a0c19fc59d95de2eca690d314566bb1c529181 /rest_framework/tests/relations_pk.py | |
| parent | 809f5de330deb4b71aaaa93bcdb8ba34b0b2e24d (diff) | |
| download | django-rest-framework-bf69205cd33fc1601e5ae3c0c48ffcff1a62470b.tar.bz2 | |
Tests for retrieving nullable relations
Diffstat (limited to 'rest_framework/tests/relations_pk.py')
| -rw-r--r-- | rest_framework/tests/relations_pk.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/rest_framework/tests/relations_pk.py b/rest_framework/tests/relations_pk.py index e3360939..7a1fe07c 100644 --- a/rest_framework/tests/relations_pk.py +++ b/rest_framework/tests/relations_pk.py @@ -229,9 +229,21 @@ class PKNullableForeignKeyTests(TestCase): target = ForeignKeyTarget(name='target-1') target.save() for idx in range(1, 4): + if idx == 3: + target = None source = NullableForeignKeySource(name='source-%d' % idx, target=target) source.save() + def test_foreign_key_retrieve_with_null(self): + queryset = NullableForeignKeySource.objects.all() + serializer = NullableForeignKeySourceSerializer(queryset) + expected = [ + {'id': 1, 'name': u'source-1', 'target': 1}, + {'id': 2, 'name': u'source-2', 'target': 1}, + {'id': 3, 'name': u'source-3', 'target': None}, + ] + self.assertEquals(serializer.data, expected) + def test_foreign_key_create_with_valid_null(self): data = {'id': 4, 'name': u'source-4', 'target': None} serializer = NullableForeignKeySourceSerializer(data=data) @@ -246,7 +258,7 @@ class PKNullableForeignKeyTests(TestCase): expected = [ {'id': 1, 'name': u'source-1', 'target': 1}, {'id': 2, 'name': u'source-2', 'target': 1}, - {'id': 3, 'name': u'source-3', 'target': 1}, + {'id': 3, 'name': u'source-3', 'target': None}, {'id': 4, 'name': u'source-4', 'target': None} ] self.assertEquals(serializer.data, expected) @@ -270,7 +282,7 @@ class PKNullableForeignKeyTests(TestCase): expected = [ {'id': 1, 'name': u'source-1', 'target': 1}, {'id': 2, 'name': u'source-2', 'target': 1}, - {'id': 3, 'name': u'source-3', 'target': 1}, + {'id': 3, 'name': u'source-3', 'target': None}, {'id': 4, 'name': u'source-4', 'target': None} ] self.assertEquals(serializer.data, expected) @@ -289,7 +301,7 @@ class PKNullableForeignKeyTests(TestCase): expected = [ {'id': 1, 'name': u'source-1', 'target': None}, {'id': 2, 'name': u'source-2', 'target': 1}, - {'id': 3, 'name': u'source-3', 'target': 1} + {'id': 3, 'name': u'source-3', 'target': None} ] self.assertEquals(serializer.data, expected) @@ -312,7 +324,7 @@ class PKNullableForeignKeyTests(TestCase): expected = [ {'id': 1, 'name': u'source-1', 'target': None}, {'id': 2, 'name': u'source-2', 'target': 1}, - {'id': 3, 'name': u'source-3', 'target': 1} + {'id': 3, 'name': u'source-3', 'target': None} ] self.assertEquals(serializer.data, expected) |
