summaryrefslogtreecommitdiff
path: root/tests/check_framework
diff options
context:
space:
mode:
authorAngus Holder <aholder97@gmail.com>2020-11-14 17:25:57 +0000
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-06-09 09:06:42 +0200
commit3e73c65ffcf263d5ccd107589452a4615281a0e8 (patch)
tree8dc22276119e1ef908452d4b1a6a37ad3932e54b /tests/check_framework
parent8f89454bbc873a117cc8614f2d1f1fbfd4e79ee4 (diff)
downloaddjango-3e73c65ffcf263d5ccd107589452a4615281a0e8.tar.gz
Fixed #32195 -- Added system check for invalid view in path() and improved error messages.
Diffstat (limited to 'tests/check_framework')
-rw-r--r--tests/check_framework/test_urls.py10
-rw-r--r--tests/check_framework/urls/cbv_as_view.py19
2 files changed, 29 insertions, 0 deletions
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()),
+]