summaryrefslogtreecommitdiff
path: root/tests/async
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2019-12-02 13:02:21 -0700
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-12-03 17:29:31 +0100
commitc90ab30fa1305481024b9c3c50b5a6ed6cd9a2f5 (patch)
treec1178f55153aec63190c0329882a00513569e2cc /tests/async
parent635a3f8e6e0303e8a87586ef6be4ab0cc01d7c0d (diff)
downloaddjango-c90ab30fa1305481024b9c3c50b5a6ed6cd9a2f5.tar.gz
Fixed #31056 -- Allowed disabling async-unsafe check with an environment variable.
Diffstat (limited to 'tests/async')
-rw-r--r--tests/async/tests.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/tests/async/tests.py b/tests/async/tests.py
index 450a38018d..f42e549075 100644
--- a/tests/async/tests.py
+++ b/tests/async/tests.py
@@ -1,5 +1,6 @@
+import os
import sys
-from unittest import skipIf
+from unittest import mock, skipIf
from asgiref.sync import async_to_sync
@@ -39,3 +40,13 @@ class AsyncUnsafeTest(SimpleTestCase):
)
with self.assertRaisesMessage(SynchronousOnlyOperation, msg):
self.dangerous_method()
+
+ @mock.patch.dict(os.environ, {'DJANGO_ALLOW_ASYNC_UNSAFE': 'true'})
+ @async_to_sync
+ async def test_async_unsafe_suppressed(self):
+ # Decorator doesn't trigger check when the environment variable to
+ # suppress it is set.
+ try:
+ self.dangerous_method()
+ except SynchronousOnlyOperation:
+ self.fail('SynchronousOnlyOperation should not be raised.')