From 3e73c65ffcf263d5ccd107589452a4615281a0e8 Mon Sep 17 00:00:00 2001 From: Angus Holder Date: Sat, 14 Nov 2020 17:25:57 +0000 Subject: Fixed #32195 -- Added system check for invalid view in path() and improved error messages. --- tests/check_framework/test_urls.py | 10 ++++++++++ tests/check_framework/urls/cbv_as_view.py | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tests/check_framework/urls/cbv_as_view.py (limited to 'tests/check_framework') diff --git a/tests/check_framework/test_urls.py b/tests/check_framework/test_urls.py index 2ef3d5b07f..663c7a299c 100644 --- a/tests/check_framework/test_urls.py +++ b/tests/check_framework/test_urls.py @@ -134,6 +134,16 @@ class CheckUrlConfigTests(SimpleTestCase): result = check_url_namespaces_unique(None) self.assertEqual(result, []) + @override_settings(ROOT_URLCONF='check_framework.urls.cbv_as_view') + def test_check_view_not_class(self): + self.assertEqual(check_url_config(None), [ + Error( + "Your URL pattern 'missing_as_view' has an invalid view, pass " + "EmptyCBV.as_view() instead of EmptyCBV.", + id='urls.E009', + ), + ]) + class UpdatedToPathTests(SimpleTestCase): diff --git a/tests/check_framework/urls/cbv_as_view.py b/tests/check_framework/urls/cbv_as_view.py new file mode 100644 index 0000000000..932a2bfcc9 --- /dev/null +++ b/tests/check_framework/urls/cbv_as_view.py @@ -0,0 +1,19 @@ +from django.http import HttpResponse +from django.urls import path +from django.views import View + + +class EmptyCBV(View): + pass + + +class EmptyCallableView: + def __call__(self, request, *args, **kwargs): + return HttpResponse() + + +urlpatterns = [ + path('missing_as_view', EmptyCBV), + path('has_as_view', EmptyCBV.as_view()), + path('callable_class', EmptyCallableView()), +] -- cgit v1.3