mirror of
https://github.com/django/django.git
synced 2025-03-06 07:22:32 +00:00
Moved http decorator tests into decorators/test_http.py.
This commit is contained in:
parent
fcc5091b4a
commit
865a6650d0
22
tests/decorators/test_http.py
Normal file
22
tests/decorators/test_http.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
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)
|
@ -7,7 +7,7 @@ from django.contrib.auth.decorators import (
|
|||||||
permission_required,
|
permission_required,
|
||||||
user_passes_test,
|
user_passes_test,
|
||||||
)
|
)
|
||||||
from django.http import HttpRequest, HttpResponse, HttpResponseNotAllowed
|
from django.http import HttpResponse
|
||||||
from django.test import SimpleTestCase
|
from django.test import SimpleTestCase
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.utils.functional import keep_lazy, keep_lazy_text, lazy
|
from django.utils.functional import keep_lazy, keep_lazy_text, lazy
|
||||||
@ -117,29 +117,6 @@ class DecoratorsTest(TestCase):
|
|||||||
|
|
||||||
self.assertEqual(response, ["test2", "test1"])
|
self.assertEqual(response, ["test2", "test1"])
|
||||||
|
|
||||||
def test_require_safe_accepts_only_safe_methods(self):
|
|
||||||
"""
|
|
||||||
Test for the require_safe decorator.
|
|
||||||
A view returns either a response or an exception.
|
|
||||||
Refs #15637.
|
|
||||||
"""
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
# For testing method_decorator, a decorator that assumes a single argument.
|
# For testing method_decorator, a decorator that assumes a single argument.
|
||||||
# We will get type arguments if there is a mismatch in the number of arguments.
|
# We will get type arguments if there is a mismatch in the number of arguments.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user