mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-27 12:04:02 +03:00
Add test for creating a reverse fk relation
This commit is contained in:
parent
24e14b7d53
commit
f92c5b28ad
|
@ -49,6 +49,22 @@ class ReverseForeignKeyTests(TestCase):
|
||||||
serializer = ForeignKeyTargetSerializer(queryset)
|
serializer = ForeignKeyTargetSerializer(queryset)
|
||||||
self.assertEquals(serializer.data, self.data)
|
self.assertEquals(serializer.data, self.data)
|
||||||
|
|
||||||
|
def test_reverse_foreign_key_create(self):
|
||||||
|
data = deepcopy(self.new_target_data)
|
||||||
|
data['sources'].append({'name': u'source-4', 'target': 2})
|
||||||
|
instance = ForeignKeyTarget.objects.get(pk=2)
|
||||||
|
serializer = ForeignKeyTargetSerializer(instance, data=data)
|
||||||
|
self.assertTrue(serializer.is_valid())
|
||||||
|
self.assertEquals(serializer.data, data)
|
||||||
|
serializer.save()
|
||||||
|
|
||||||
|
# Ensure target 2 has new source and everything else is as expected
|
||||||
|
queryset = ForeignKeyTarget.objects.all()
|
||||||
|
serializer = ForeignKeyTargetSerializer(queryset)
|
||||||
|
expected = deepcopy(self.data)
|
||||||
|
expected[1]['sources'].append({'id': 4, 'name': 'source-4', 'target': 2})
|
||||||
|
self.assertEquals(serializer.data, expected)
|
||||||
|
|
||||||
def test_reverse_foreign_key_update(self):
|
def test_reverse_foreign_key_update(self):
|
||||||
data = deepcopy(self.target_data)
|
data = deepcopy(self.target_data)
|
||||||
data['sources'][0]['name'] = 'source-1-changed'
|
data['sources'][0]['name'] = 'source-1-changed'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user