Debian Codegraph @

tests/decorators/test_common.py

raw
1 from asgiref.sync import iscoroutinefunction
2
3 from django.http import HttpRequest, HttpResponse
4 from django.test import SimpleTestCase
5 from django.views.decorators.common import no_append_slash
6
7
8 class NoAppendSlashTests(SimpleTestCase):
9 def test_wrapped_sync_function_is_not_coroutine_function(self):
10 def sync_view(request):
11 return HttpResponse()
12
13 wrapped_view = no_append_slash(sync_view)
14 self.assertIs(iscoroutinefunction(wrapped_view), False)
15
16 def test_wrapped_async_function_is_coroutine_function(self):
17 async def async_view(request):
18 return HttpResponse()
19
20 wrapped_view = no_append_slash(async_view)
21 self.assertIs(iscoroutinefunction(wrapped_view), True)
22
23 def test_no_append_slash_decorator(self):
24 @no_append_slash
25 def sync_view(request):
26 return HttpResponse()
27
28 self.assertIs(sync_view.should_append_slash, False)
29 self.assertIsInstance(sync_view(HttpRequest()), HttpResponse)
30
31 async def test_no_append_slash_decorator_async_view(self):
32 @no_append_slash
33 async def async_view(request):
34 return HttpResponse()
35
36 self.assertIs(async_view.should_append_slash, False)
37 self.assertIsInstance(await async_view(HttpRequest()), HttpResponse)