mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #31077 -- Made debug decorators raise TypeError if they're not called.
Django will raise an error if you forget to call the decorator.
This commit is contained in:
committed by
Mariusz Felisiak
parent
02eff7ef60
commit
d8e2333528
@@ -26,6 +26,9 @@ from django.views.debug import (
|
||||
Path as DebugPath, cleanse_setting, default_urlconf,
|
||||
technical_404_response, technical_500_response,
|
||||
)
|
||||
from django.views.decorators.debug import (
|
||||
sensitive_post_parameters, sensitive_variables,
|
||||
)
|
||||
|
||||
from ..views import (
|
||||
custom_exception_reporter_filter_view, index_page,
|
||||
@@ -1272,3 +1275,26 @@ class HelperFunctionTests(SimpleTestCase):
|
||||
initial = {'login': 'cooper', 'password': 'secret'}
|
||||
expected = {'login': 'cooper', 'password': CLEANSED_SUBSTITUTE}
|
||||
self.assertEqual(cleanse_setting('SETTING_NAME', initial), expected)
|
||||
|
||||
|
||||
class DecoratorsTests(SimpleTestCase):
|
||||
def test_sensitive_variables_not_called(self):
|
||||
msg = (
|
||||
'sensitive_variables() must be called to use it as a decorator, '
|
||||
'e.g., use @sensitive_variables(), not @sensitive_variables.'
|
||||
)
|
||||
with self.assertRaisesMessage(TypeError, msg):
|
||||
@sensitive_variables
|
||||
def test_func(password):
|
||||
pass
|
||||
|
||||
def test_sensitive_post_parameters_not_called(self):
|
||||
msg = (
|
||||
'sensitive_post_parameters() must be called to use it as a '
|
||||
'decorator, e.g., use @sensitive_post_parameters(), not '
|
||||
'@sensitive_post_parameters.'
|
||||
)
|
||||
with self.assertRaisesMessage(TypeError, msg):
|
||||
@sensitive_post_parameters
|
||||
def test_func(request):
|
||||
return index_page(request)
|
||||
|
||||
Reference in New Issue
Block a user