summaryrefslogtreecommitdiff
path: root/tests/async
diff options
context:
space:
mode:
authorDevilsAutumn <bhuvnesh875@gmail.com>2022-10-30 22:21:54 +0530
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-11-02 09:14:17 +0100
commitd5bcdf858d962d02de925603c17986980f03729a (patch)
tree367182dbc54c46faa2196b7f047eceeda62ec650 /tests/async
parent6103059592c6c1bd171977d26b76ee475175043c (diff)
downloaddjango-d5bcdf858d962d02de925603c17986980f03729a.tar.gz
Fixed #34112 -- Added async-compatible interface to Model methods.
Thanks Adam Johnson for the review.
Diffstat (limited to 'tests/async')
-rw-r--r--tests/async/test_async_model_methods.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/async/test_async_model_methods.py b/tests/async/test_async_model_methods.py
new file mode 100644
index 0000000000..94e0370e35
--- /dev/null
+++ b/tests/async/test_async_model_methods.py
@@ -0,0 +1,25 @@
+from django.test import TestCase
+
+from .models import SimpleModel
+
+
+class AsyncModelOperationTest(TestCase):
+ @classmethod
+ def setUpTestData(cls):
+ cls.s1 = SimpleModel.objects.create(field=0)
+
+ async def test_asave(self):
+ self.s1.field = 10
+ await self.s1.asave()
+ refetched = await SimpleModel.objects.aget()
+ self.assertEqual(refetched.field, 10)
+
+ async def test_adelete(self):
+ await self.s1.adelete()
+ count = await SimpleModel.objects.acount()
+ self.assertEqual(count, 0)
+
+ async def test_arefresh_from_db(self):
+ await SimpleModel.objects.filter(pk=self.s1.pk).aupdate(field=20)
+ await self.s1.arefresh_from_db()
+ self.assertEqual(self.s1.field, 20)