mirror of
https://github.com/django/django.git
synced 2024-11-30 23:20:50 +01:00
23 lines
947 B
Python
23 lines
947 B
Python
|
from django.http import HttpRequest, HttpResponse, HttpResponseNotAllowed
|
||
|
from django.test import SimpleTestCase
|
||
|
from django.views.decorators.http import require_safe
|
||
|
|
||
|
|
||
|
class RequireSafeDecoratorTest(SimpleTestCase):
|
||
|
def test_require_safe_accepts_only_safe_methods(self):
|
||
|
def my_view(request):
|
||
|
return HttpResponse("OK")
|
||
|
|
||
|
my_safe_view = require_safe(my_view)
|
||
|
request = HttpRequest()
|
||
|
request.method = "GET"
|
||
|
self.assertIsInstance(my_safe_view(request), HttpResponse)
|
||
|
request.method = "HEAD"
|
||
|
self.assertIsInstance(my_safe_view(request), HttpResponse)
|
||
|
request.method = "POST"
|
||
|
self.assertIsInstance(my_safe_view(request), HttpResponseNotAllowed)
|
||
|
request.method = "PUT"
|
||
|
self.assertIsInstance(my_safe_view(request), HttpResponseNotAllowed)
|
||
|
request.method = "DELETE"
|
||
|
self.assertIsInstance(my_safe_view(request), HttpResponseNotAllowed)
|