Refs #32045 -- Added tests for GenericRelatedObjectManager.clear()/remove().

This commit is contained in:
Craig Smith 2020-11-06 10:40:00 +01:00 committed by Mariusz Felisiak
parent 3f7b327562
commit 6fa3d02f7f
1 changed files with 24 additions and 0 deletions

View File

@ -320,6 +320,30 @@ class GenericRelationsTests(TestCase):
self.assertEqual(1, bacon.tags.count())
self.assertEqual(1, qs.count())
def test_clear(self):
self.assertSequenceEqual(
TaggedItem.objects.order_by('tag'),
[self.fatty, self.hairy, self.salty, self.yellow],
)
self.bacon.tags.clear()
self.assertSequenceEqual(self.bacon.tags.all(), [])
self.assertSequenceEqual(
TaggedItem.objects.order_by('tag'),
[self.hairy, self.yellow],
)
def test_remove(self):
self.assertSequenceEqual(
TaggedItem.objects.order_by('tag'),
[self.fatty, self.hairy, self.salty, self.yellow],
)
self.bacon.tags.remove(self.fatty)
self.assertSequenceEqual(self.bacon.tags.all(), [self.salty])
self.assertSequenceEqual(
TaggedItem.objects.order_by('tag'),
[self.hairy, self.salty, self.yellow],
)
def test_generic_relation_related_name_default(self):
# GenericRelation isn't usable from the reverse side by default.
msg = (