diff options
| author | Alasdair Nicol <alasdair@thenicols.net> | 2019-04-04 00:17:25 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-04-25 11:38:35 +0200 |
| commit | 3c3df7db8e5ce7882d6a8379fc2d0f82330114f1 (patch) | |
| tree | fa3a3533bd412af7980ee2dc3586ba8fc1914def /tests | |
| parent | f24cf51661af21cfe2d90d7cba6557c56778ef20 (diff) | |
[2.2.x] Fixed #30318 -- Added check for importability of arguments of custom error handler views.
Thanks to Jon on Stack Overflow for reporting the issue.
Backport of a5accc0368c6575b55976c06af36ed399c85c781 from master
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/check_framework/test_urls.py | 23 | ||||
| -rw-r--r-- | tests/check_framework/urls/bad_error_handlers_invalid_path.py | 6 |
2 files changed, 29 insertions, 0 deletions
diff --git a/tests/check_framework/test_urls.py b/tests/check_framework/test_urls.py index 67de26c690..217b5e7bad 100644 --- a/tests/check_framework/test_urls.py +++ b/tests/check_framework/test_urls.py @@ -181,6 +181,29 @@ class CheckCustomErrorHandlersTests(SimpleTestCase): id='urls.E007', )) + @override_settings(ROOT_URLCONF='check_framework.urls.bad_error_handlers_invalid_path') + def test_bad_handlers_invalid_path(self): + result = check_url_config(None) + paths = [ + 'django.views.bad_handler', + 'django.invalid_module.bad_handler', + 'invalid_module.bad_handler', + 'django', + ] + hints = [ + "Could not import '{}'. View does not exist in module django.views.", + "Could not import '{}'. Parent module django.invalid_module does not exist.", + "No module named 'invalid_module'", + "Could not import '{}'. The path must be fully qualified.", + ] + for code, path, hint, error in zip([400, 403, 404, 500], paths, hints, result): + with self.subTest('handler{}'.format(code)): + self.assertEqual(error, Error( + "The custom handler{} view '{}' could not be imported.".format(code, path), + hint=hint.format(path), + id='urls.E008', + )) + @override_settings(ROOT_URLCONF='check_framework.urls.good_error_handlers') def test_good_handlers(self): result = check_url_config(None) diff --git a/tests/check_framework/urls/bad_error_handlers_invalid_path.py b/tests/check_framework/urls/bad_error_handlers_invalid_path.py new file mode 100644 index 0000000000..77e0c639e0 --- /dev/null +++ b/tests/check_framework/urls/bad_error_handlers_invalid_path.py @@ -0,0 +1,6 @@ +urlpatterns = [] + +handler400 = 'django.views.bad_handler' +handler403 = 'django.invalid_module.bad_handler' +handler404 = 'invalid_module.bad_handler' +handler500 = 'django' |
