mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-23 10:03:57 +03:00
Add test for m2m create
This commit is contained in:
parent
c1be29418b
commit
f72be7b8fa
|
@ -130,6 +130,25 @@ class PKManyToManyTests(TestCase):
|
||||||
]
|
]
|
||||||
self.assertEquals(serializer.data, expected)
|
self.assertEquals(serializer.data, expected)
|
||||||
|
|
||||||
|
def test_many_to_many_create(self):
|
||||||
|
data = {'id': 4, 'name': u'source-4', 'targets': [1, 3]}
|
||||||
|
serializer = ManyToManySourceSerializer(data=data)
|
||||||
|
self.assertTrue(serializer.is_valid())
|
||||||
|
obj = serializer.save()
|
||||||
|
self.assertEquals(serializer.data, data)
|
||||||
|
self.assertEqual(obj.name, u'source-4')
|
||||||
|
|
||||||
|
# Ensure source 4 is added, and everything else is as expected
|
||||||
|
queryset = ManyToManySource.objects.all()
|
||||||
|
serializer = ManyToManySourceSerializer(queryset)
|
||||||
|
expected = [
|
||||||
|
{'id': 1, 'name': u'source-1', 'targets': [1]},
|
||||||
|
{'id': 2, 'name': u'source-2', 'targets': [1, 2]},
|
||||||
|
{'id': 3, 'name': u'source-3', 'targets': [1, 2, 3]},
|
||||||
|
{'id': 4, 'name': u'source-4', 'targets': [1, 3]},
|
||||||
|
]
|
||||||
|
self.assertEquals(serializer.data, expected)
|
||||||
|
|
||||||
def test_reverse_many_to_many_create(self):
|
def test_reverse_many_to_many_create(self):
|
||||||
data = {'id': 4, 'name': u'target-4', 'sources': [1, 3]}
|
data = {'id': 4, 'name': u'target-4', 'sources': [1, 3]}
|
||||||
serializer = ManyToManyTargetSerializer(data=data)
|
serializer = ManyToManyTargetSerializer(data=data)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user