summaryrefslogtreecommitdiff
path: root/tests/decorators
diff options
context:
space:
mode:
authorBen Lomax <lomax.on.the.run@gmail.com>2023-07-08 21:00:42 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-07-10 07:55:02 +0200
commit953f81e078fb7299b6d40d4e599e5f559e03952b (patch)
tree66cafa352d883e72240a188b1f27ea22d4d79d03 /tests/decorators
parent6d427288e410e9cad39b1aa1b4d4893fbd391282 (diff)
Refs #31949 -- Made @csrf_exempt decorator to work with async functions.
Diffstat (limited to 'tests/decorators')
-rw-r--r--tests/decorators/test_csrf.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/decorators/test_csrf.py b/tests/decorators/test_csrf.py
new file mode 100644
index 0000000000..275b12ee9d
--- /dev/null
+++ b/tests/decorators/test_csrf.py
@@ -0,0 +1,37 @@
+from asgiref.sync import iscoroutinefunction
+
+from django.http import HttpRequest, HttpResponse
+from django.test import SimpleTestCase
+from django.views.decorators.csrf import csrf_exempt
+
+
+class CsrfExemptTests(SimpleTestCase):
+ def test_wrapped_sync_function_is_not_coroutine_function(self):
+ def sync_view(request):
+ return HttpResponse()
+
+ wrapped_view = csrf_exempt(sync_view)
+ self.assertIs(iscoroutinefunction(wrapped_view), False)
+
+ def test_wrapped_async_function_is_coroutine_function(self):
+ async def async_view(request):
+ return HttpResponse()
+
+ wrapped_view = csrf_exempt(async_view)
+ self.assertIs(iscoroutinefunction(wrapped_view), True)
+
+ def test_csrf_exempt_decorator(self):
+ @csrf_exempt
+ def sync_view(request):
+ return HttpResponse()
+
+ self.assertIs(sync_view.csrf_exempt, True)
+ self.assertIsInstance(sync_view(HttpRequest()), HttpResponse)
+
+ async def test_csrf_exempt_decorator_async_view(self):
+ @csrf_exempt
+ async def async_view(request):
+ return HttpResponse()
+
+ self.assertIs(async_view.csrf_exempt, True)
+ self.assertIsInstance(await async_view(HttpRequest()), HttpResponse)