mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Refs #33476 -- Reformatted code with Black.
This commit is contained in:
committed by
Mariusz Felisiak
parent
f68fa8b45d
commit
9c19aff7c7
@@ -12,7 +12,10 @@ from django.utils.asyncio import async_unsafe
|
||||
from .models import SimpleModel
|
||||
|
||||
|
||||
@skipIf(sys.platform == 'win32' and (3, 8, 0) < sys.version_info < (3, 8, 1), 'https://bugs.python.org/issue38563')
|
||||
@skipIf(
|
||||
sys.platform == "win32" and (3, 8, 0) < sys.version_info < (3, 8, 1),
|
||||
"https://bugs.python.org/issue38563",
|
||||
)
|
||||
class CacheTest(SimpleTestCase):
|
||||
def test_caches_local(self):
|
||||
@async_to_sync
|
||||
@@ -24,20 +27,28 @@ class CacheTest(SimpleTestCase):
|
||||
self.assertIs(cache_1, cache_2)
|
||||
|
||||
|
||||
@skipIf(sys.platform == 'win32' and (3, 8, 0) < sys.version_info < (3, 8, 1), 'https://bugs.python.org/issue38563')
|
||||
@skipIf(
|
||||
sys.platform == "win32" and (3, 8, 0) < sys.version_info < (3, 8, 1),
|
||||
"https://bugs.python.org/issue38563",
|
||||
)
|
||||
class DatabaseConnectionTest(SimpleTestCase):
|
||||
"""A database connection cannot be used in an async context."""
|
||||
|
||||
async def test_get_async_connection(self):
|
||||
with self.assertRaises(SynchronousOnlyOperation):
|
||||
list(SimpleModel.objects.all())
|
||||
|
||||
|
||||
@skipIf(sys.platform == 'win32' and (3, 8, 0) < sys.version_info < (3, 8, 1), 'https://bugs.python.org/issue38563')
|
||||
@skipIf(
|
||||
sys.platform == "win32" and (3, 8, 0) < sys.version_info < (3, 8, 1),
|
||||
"https://bugs.python.org/issue38563",
|
||||
)
|
||||
class AsyncUnsafeTest(SimpleTestCase):
|
||||
"""
|
||||
async_unsafe decorator should work correctly and returns the correct
|
||||
message.
|
||||
"""
|
||||
|
||||
@async_unsafe
|
||||
def dangerous_method(self):
|
||||
return True
|
||||
@@ -46,13 +57,13 @@ class AsyncUnsafeTest(SimpleTestCase):
|
||||
# async_unsafe decorator catches bad access and returns the right
|
||||
# message.
|
||||
msg = (
|
||||
'You cannot call this from an async context - use a thread or '
|
||||
'sync_to_async.'
|
||||
"You cannot call this from an async context - use a thread or "
|
||||
"sync_to_async."
|
||||
)
|
||||
with self.assertRaisesMessage(SynchronousOnlyOperation, msg):
|
||||
self.dangerous_method()
|
||||
|
||||
@mock.patch.dict(os.environ, {'DJANGO_ALLOW_ASYNC_UNSAFE': 'true'})
|
||||
@mock.patch.dict(os.environ, {"DJANGO_ALLOW_ASYNC_UNSAFE": "true"})
|
||||
@async_to_sync # mock.patch() is not async-aware.
|
||||
async def test_async_unsafe_suppressed(self):
|
||||
# Decorator doesn't trigger check when the environment variable to
|
||||
@@ -60,4 +71,4 @@ class AsyncUnsafeTest(SimpleTestCase):
|
||||
try:
|
||||
self.dangerous_method()
|
||||
except SynchronousOnlyOperation:
|
||||
self.fail('SynchronousOnlyOperation should not be raised.')
|
||||
self.fail("SynchronousOnlyOperation should not be raised.")
|
||||
|
||||
Reference in New Issue
Block a user