summaryrefslogtreecommitdiff
path: root/tests/many_to_many
diff options
context:
space:
mode:
authorYoong Kang Lim <yoongkang.lim@gmail.com>2016-06-05 22:15:00 +1000
committerTim Graham <timograham@gmail.com>2016-08-05 13:32:27 -0400
commitd30febb4e59b659e0d279c77f61f936c199a05b2 (patch)
treec490770944097532ee322a8d21437b40a49eee0a /tests/many_to_many
parentea65c7cb4819cf18ac66215bc7b4df4af3fbe5ad (diff)
Fixed #26706 -- Made RelatedManager modification methods clear prefetch_related() cache.
Diffstat (limited to 'tests/many_to_many')
-rw-r--r--tests/many_to_many/tests.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/many_to_many/tests.py b/tests/many_to_many/tests.py
index 86ffe816eb..2d35266f46 100644
--- a/tests/many_to_many/tests.py
+++ b/tests/many_to_many/tests.py
@@ -518,6 +518,40 @@ class ManyToManyTests(TestCase):
self.assertQuerysetEqual(self.a4.publications.all(), [])
self.assertQuerysetEqual(self.p2.article_set.all(), ['<Article: NASA finds intelligent life on Earth>'])
+ def test_clear_after_prefetch(self):
+ a4 = Article.objects.prefetch_related('publications').get(id=self.a4.id)
+ self.assertQuerysetEqual(a4.publications.all(), ['<Publication: Science News>'])
+ a4.publications.clear()
+ self.assertQuerysetEqual(a4.publications.all(), [])
+
+ def test_remove_after_prefetch(self):
+ a4 = Article.objects.prefetch_related('publications').get(id=self.a4.id)
+ self.assertQuerysetEqual(a4.publications.all(), ['<Publication: Science News>'])
+ a4.publications.remove(self.p2)
+ self.assertQuerysetEqual(a4.publications.all(), [])
+
+ def test_add_after_prefetch(self):
+ a4 = Article.objects.prefetch_related('publications').get(id=self.a4.id)
+ self.assertEqual(a4.publications.count(), 1)
+ a4.publications.add(self.p1)
+ self.assertEqual(a4.publications.count(), 2)
+
+ def test_set_after_prefetch(self):
+ a4 = Article.objects.prefetch_related('publications').get(id=self.a4.id)
+ self.assertEqual(a4.publications.count(), 1)
+ a4.publications.set([self.p2, self.p1])
+ self.assertEqual(a4.publications.count(), 2)
+ a4.publications.set([self.p1])
+ self.assertEqual(a4.publications.count(), 1)
+
+ def test_add_then_remove_after_prefetch(self):
+ a4 = Article.objects.prefetch_related('publications').get(id=self.a4.id)
+ self.assertEqual(a4.publications.count(), 1)
+ a4.publications.add(self.p1)
+ self.assertEqual(a4.publications.count(), 2)
+ a4.publications.remove(self.p1)
+ self.assertQuerysetEqual(a4.publications.all(), ['<Publication: Science News>'])
+
def test_inherited_models_selects(self):
"""
#24156 - Objects from child models where the parent's m2m field uses