summaryrefslogtreecommitdiff
path: root/tests/generic_relations
diff options
context:
space:
mode:
authorJon Janzen <jon@jonjanzen.com>2022-11-03 19:57:33 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-11-09 10:32:40 +0100
commit321ecb40f4da842926e1bc07e11df4aabe53ca4b (patch)
tree3a306ec0bc38c90eb95d8adceaecc3017e1b3d06 /tests/generic_relations
parent41e8931c2cc68d8b2de4219be930e2c305b4eba1 (diff)
downloaddjango-321ecb40f4da842926e1bc07e11df4aabe53ca4b.tar.gz
Fixed #34135 -- Added async-compatible interface to related managers.
Diffstat (limited to 'tests/generic_relations')
-rw-r--r--tests/generic_relations/tests.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/generic_relations/tests.py b/tests/generic_relations/tests.py
index e6bee11cdf..18e3578f60 100644
--- a/tests/generic_relations/tests.py
+++ b/tests/generic_relations/tests.py
@@ -324,6 +324,13 @@ class GenericRelationsTests(TestCase):
with self.assertRaisesMessage(TypeError, msg):
self.bacon.tags.add(self.lion)
+ async def test_aadd(self):
+ bacon = await Vegetable.objects.acreate(name="Bacon", is_yucky=False)
+ t1 = await TaggedItem.objects.acreate(content_object=self.quartz, tag="shiny")
+ t2 = await TaggedItem.objects.acreate(content_object=self.quartz, tag="fatty")
+ await bacon.tags.aadd(t1, t2, bulk=False)
+ self.assertEqual(await bacon.tags.acount(), 2)
+
def test_set(self):
bacon = Vegetable.objects.create(name="Bacon", is_yucky=False)
fatty = bacon.tags.create(tag="fatty")
@@ -347,6 +354,16 @@ class GenericRelationsTests(TestCase):
bacon.tags.set([], clear=True)
self.assertSequenceEqual(bacon.tags.all(), [])
+ async def test_aset(self):
+ bacon = await Vegetable.objects.acreate(name="Bacon", is_yucky=False)
+ fatty = await bacon.tags.acreate(tag="fatty")
+ await bacon.tags.aset([fatty])
+ self.assertEqual(await bacon.tags.acount(), 1)
+ await bacon.tags.aset([])
+ self.assertEqual(await bacon.tags.acount(), 0)
+ await bacon.tags.aset([fatty], bulk=False, clear=True)
+ self.assertEqual(await bacon.tags.acount(), 1)
+
def test_assign(self):
bacon = Vegetable.objects.create(name="Bacon", is_yucky=False)
fatty = bacon.tags.create(tag="fatty")
@@ -388,6 +405,10 @@ class GenericRelationsTests(TestCase):
[self.hairy, self.yellow],
)
+ async def test_aclear(self):
+ await self.bacon.tags.aclear()
+ self.assertEqual(await self.bacon.tags.acount(), 0)
+
def test_remove(self):
self.assertSequenceEqual(
TaggedItem.objects.order_by("tag"),
@@ -400,6 +421,12 @@ class GenericRelationsTests(TestCase):
[self.hairy, self.salty, self.yellow],
)
+ async def test_aremove(self):
+ await self.bacon.tags.aremove(self.fatty)
+ self.assertEqual(await self.bacon.tags.acount(), 1)
+ await self.bacon.tags.aremove(self.salty)
+ self.assertEqual(await self.bacon.tags.acount(), 0)
+
def test_generic_relation_related_name_default(self):
# GenericRelation isn't usable from the reverse side by default.
msg = (