From 71ada3a8e689a883b5ffdeb1744ea16f176ab730 Mon Sep 17 00:00:00 2001 From: Loic Bistuer Date: Fri, 30 Jan 2015 01:15:27 +0700 Subject: Fixed #6707 -- Added RelatedManager.set() and made descriptors' __set__ use it. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks Anssi Kääriäinen, Carl Meyer, Collin Anderson, and Tim Graham for the reviews. --- tests/generic_relations/tests.py | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'tests/generic_relations') diff --git a/tests/generic_relations/tests.py b/tests/generic_relations/tests.py index c6230b057e..bc2cfaa579 100644 --- a/tests/generic_relations/tests.py +++ b/tests/generic_relations/tests.py @@ -246,6 +246,58 @@ class GenericRelationsTests(TestCase): self.comp_func ) + def test_set(self): + bacon = Vegetable.objects.create(name="Bacon", is_yucky=False) + fatty = bacon.tags.create(tag="fatty") + salty = bacon.tags.create(tag="salty") + + bacon.tags.set([fatty, salty]) + self.assertQuerysetEqual(bacon.tags.all(), [ + "", + "", + ]) + + bacon.tags.set([fatty]) + self.assertQuerysetEqual(bacon.tags.all(), [ + "", + ]) + + bacon.tags.set([]) + self.assertQuerysetEqual(bacon.tags.all(), []) + + bacon.tags.set([fatty, salty], clear=True) + self.assertQuerysetEqual(bacon.tags.all(), [ + "", + "", + ]) + + bacon.tags.set([fatty], clear=True) + self.assertQuerysetEqual(bacon.tags.all(), [ + "", + ]) + + bacon.tags.set([], clear=True) + self.assertQuerysetEqual(bacon.tags.all(), []) + + def test_assign(self): + bacon = Vegetable.objects.create(name="Bacon", is_yucky=False) + fatty = bacon.tags.create(tag="fatty") + salty = bacon.tags.create(tag="salty") + + bacon.tags = [fatty, salty] + self.assertQuerysetEqual(bacon.tags.all(), [ + "", + "", + ]) + + bacon.tags = [fatty] + self.assertQuerysetEqual(bacon.tags.all(), [ + "", + ]) + + bacon.tags = [] + self.assertQuerysetEqual(bacon.tags.all(), []) + def test_assign_with_queryset(self): # Ensure that querysets used in reverse GFK assignments are pre-evaluated # so their value isn't affected by the clearing operation in -- cgit v1.3