summaryrefslogtreecommitdiff
path: root/tests/decorators
diff options
context:
space:
mode:
authorBen Lomax <lomax.on.the.run@gmail.com>2023-05-19 21:14:32 +0800
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-05-23 10:04:41 +0200
commit23abec9192c88f9372e5784ae69c9aa5be2b21be (patch)
tree7dcee84ff72a113563fb1eb4bbf47948e0ed305c /tests/decorators
parente5c844d6f2a4ac6ae674d741b5f1fa2a688cedf4 (diff)
Refs #31949 -- Made @no_append_slash decorator to work with async functions.
Diffstat (limited to 'tests/decorators')
-rw-r--r--tests/decorators/test_common.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/decorators/test_common.py b/tests/decorators/test_common.py
new file mode 100644
index 0000000000..a2661ef30a
--- /dev/null
+++ b/tests/decorators/test_common.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.common import no_append_slash
+
+
+class NoAppendSlashTests(SimpleTestCase):
+ def test_wrapped_sync_function_is_not_coroutine_function(self):
+ def sync_view(request):
+ return HttpResponse()
+
+ wrapped_view = no_append_slash(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 = no_append_slash(async_view)
+ self.assertIs(iscoroutinefunction(wrapped_view), True)
+
+ def test_no_append_slash_decorator(self):
+ @no_append_slash
+ def sync_view(request):
+ return HttpResponse()
+
+ self.assertIs(sync_view.should_append_slash, False)
+ self.assertIsInstance(sync_view(HttpRequest()), HttpResponse)
+
+ async def test_no_append_slash_decorator_async_view(self):
+ @no_append_slash
+ async def async_view(request):
+ return HttpResponse()
+
+ self.assertIs(async_view.should_append_slash, False)
+ self.assertIsInstance(await async_view(HttpRequest()), HttpResponse)