summaryrefslogtreecommitdiff
path: root/tests/many_to_many
diff options
context:
space:
mode:
authorLoic Bistuer <loic.bistuer@gmail.com>2015-01-30 01:15:27 +0700
committerLoic Bistuer <loic.bistuer@gmail.com>2015-02-05 12:45:08 +0700
commit71ada3a8e689a883b5ffdeb1744ea16f176ab730 (patch)
tree7e4696ec75370e0747a26c4dea541626573895b2 /tests/many_to_many
parent49516f7158ed0ca39ea8116d25a32a80288d47b3 (diff)
downloaddjango-71ada3a8e689a883b5ffdeb1744ea16f176ab730.tar.gz
Fixed #6707 -- Added RelatedManager.set() and made descriptors' __set__ use it.
Thanks Anssi Kääriäinen, Carl Meyer, Collin Anderson, and Tim Graham for the reviews.
Diffstat (limited to 'tests/many_to_many')
-rw-r--r--tests/many_to_many/tests.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/many_to_many/tests.py b/tests/many_to_many/tests.py
index adb897840a..192bc5f0e8 100644
--- a/tests/many_to_many/tests.py
+++ b/tests/many_to_many/tests.py
@@ -332,6 +332,45 @@ class ManyToManyTests(TestCase):
])
self.assertQuerysetEqual(self.a3.publications.all(), [])
+ def test_set(self):
+ self.p2.article_set.set([self.a4, self.a3])
+ self.assertQuerysetEqual(self.p2.article_set.all(),
+ [
+ '<Article: NASA finds intelligent life on Earth>',
+ '<Article: Oxygen-free diet works wonders>',
+ ])
+ self.assertQuerysetEqual(self.a4.publications.all(),
+ ['<Publication: Science News>'])
+ self.a4.publications.set([self.p3.id])
+ self.assertQuerysetEqual(self.p2.article_set.all(),
+ ['<Article: NASA finds intelligent life on Earth>'])
+ self.assertQuerysetEqual(self.a4.publications.all(),
+ ['<Publication: Science Weekly>'])
+
+ self.p2.article_set.set([])
+ self.assertQuerysetEqual(self.p2.article_set.all(), [])
+ self.a4.publications.set([])
+ self.assertQuerysetEqual(self.a4.publications.all(), [])
+
+ self.p2.article_set.set([self.a4, self.a3], clear=True)
+ self.assertQuerysetEqual(self.p2.article_set.all(),
+ [
+ '<Article: NASA finds intelligent life on Earth>',
+ '<Article: Oxygen-free diet works wonders>',
+ ])
+ self.assertQuerysetEqual(self.a4.publications.all(),
+ ['<Publication: Science News>'])
+ self.a4.publications.set([self.p3.id], clear=True)
+ self.assertQuerysetEqual(self.p2.article_set.all(),
+ ['<Article: NASA finds intelligent life on Earth>'])
+ self.assertQuerysetEqual(self.a4.publications.all(),
+ ['<Publication: Science Weekly>'])
+
+ self.p2.article_set.set([], clear=True)
+ self.assertQuerysetEqual(self.p2.article_set.all(), [])
+ self.a4.publications.set([], clear=True)
+ self.assertQuerysetEqual(self.a4.publications.all(), [])
+
def test_assign(self):
# Relation sets can be assigned. Assignment clears any existing set members
self.p2.article_set = [self.a4, self.a3]