1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Fixed #29642 -- Added check for arguments of custom error handler views.

This commit is contained in:
Adam Johnson
2018-09-07 08:33:19 +01:00
committed by Tim Graham
parent d483a5f0dc
commit 245c36d7b6
5 changed files with 73 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
from django.conf import settings
from django.core.checks.messages import Warning
from django.core.checks.messages import Error, Warning
from django.core.checks.urls import (
E006, check_url_config, check_url_namespaces_unique, check_url_settings,
get_warning_for_invalid_pattern,
@@ -165,6 +165,28 @@ class UpdatedToPathTests(SimpleTestCase):
self.assertIn(expected_msg, warning.msg)
class CheckCustomErrorHandlersTests(SimpleTestCase):
@override_settings(ROOT_URLCONF='check_framework.urls.bad_error_handlers')
def test_bad_handlers(self):
result = check_url_config(None)
self.assertEqual(len(result), 4)
for code, num_params, error in zip([400, 403, 404, 500], [2, 2, 2, 1], result):
with self.subTest('handler{}'.format(code)):
self.assertEqual(error, Error(
"The custom handler{} view "
"'check_framework.urls.bad_error_handlers.bad_handler' "
"does not take the correct number of arguments (request{})."
.format(code, ', exception' if num_params == 2 else ''),
id='urls.E007',
))
@override_settings(ROOT_URLCONF='check_framework.urls.good_error_handlers')
def test_good_handlers(self):
result = check_url_config(None)
self.assertEqual(result, [])
class CheckURLSettingsTests(SimpleTestCase):
@override_settings(STATIC_URL='a/', MEDIA_URL='b/')