summaryrefslogtreecommitdiff
path: root/tests/generic_relations
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/generic_relations
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/generic_relations')
-rw-r--r--tests/generic_relations/tests.py52
1 files changed, 52 insertions, 0 deletions
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(), [
+ "<TaggedItem: fatty>",
+ "<TaggedItem: salty>",
+ ])
+
+ bacon.tags.set([fatty])
+ self.assertQuerysetEqual(bacon.tags.all(), [
+ "<TaggedItem: fatty>",
+ ])
+
+ bacon.tags.set([])
+ self.assertQuerysetEqual(bacon.tags.all(), [])
+
+ bacon.tags.set([fatty, salty], clear=True)
+ self.assertQuerysetEqual(bacon.tags.all(), [
+ "<TaggedItem: fatty>",
+ "<TaggedItem: salty>",
+ ])
+
+ bacon.tags.set([fatty], clear=True)
+ self.assertQuerysetEqual(bacon.tags.all(), [
+ "<TaggedItem: fatty>",
+ ])
+
+ 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(), [
+ "<TaggedItem: fatty>",
+ "<TaggedItem: salty>",
+ ])
+
+ bacon.tags = [fatty]
+ self.assertQuerysetEqual(bacon.tags.all(), [
+ "<TaggedItem: fatty>",
+ ])
+
+ 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