def setUp(self): for idx in range(1, 4): target = ManyToManyTarget(name='target-%d' % idx) target.save() source = ManyToManySource(name='source-%d' % idx) source.save() for target in ManyToManyTarget.objects.all(): source.targets.add(target)
def test_many_to_many_unsaved(self): source = ManyToManySource(name='source-unsaved') serializer = ManyToManySourceSerializer(source) expected = {'id': None, 'name': 'source-unsaved', 'targets': []} # no query if source hasn't been created yet with self.assertNumQueries(0): self.assertEqual(serializer.data, expected)