mirror of
https://github.com/django/django.git
synced 2025-08-24 20:44:24 +00:00
Fixed #34112 -- Added async-compatible interface to Model methods.
Thanks Adam Johnson for the review.
This commit is contained in:
parent
6103059592
commit
d5bcdf858d
6 changed files with 86 additions and 0 deletions
25
tests/async/test_async_model_methods.py
Normal file
25
tests/async/test_async_model_methods.py
Normal file
|
@ -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)
|
Loading…
Add table
Add a link
Reference in a new issue