summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPaul Donohue <git@PaulSD.com>2018-04-08 13:35:24 -0400
committerTim Graham <timograham@gmail.com>2018-04-12 13:28:29 -0400
commit979253fce9c0bb6ee484a5a786d477a47545d972 (patch)
treeb9229bf46da039bacee673dd9755c584e2be6c5c /tests
parent8f76939f54924b01b41d4242e71ca98eb35964f2 (diff)
[1.11.x] Fixed #29296 -- Fixed crashes in admindocs when a view is a callable object.
Backport of 33a0b7ac815588ed92dca215e153390af8bdbdda from master
Diffstat (limited to 'tests')
-rw-r--r--tests/admin_docs/test_middleware.py5
-rw-r--r--tests/admin_docs/test_views.py6
-rw-r--r--tests/admin_docs/urls.py2
-rw-r--r--tests/admin_docs/views.py5
4 files changed, 18 insertions, 0 deletions
diff --git a/tests/admin_docs/test_middleware.py b/tests/admin_docs/test_middleware.py
index 426c78d58f..e5dbd9dfb3 100644
--- a/tests/admin_docs/test_middleware.py
+++ b/tests/admin_docs/test_middleware.py
@@ -42,3 +42,8 @@ class XViewMiddlewareTest(TestDataMixin, AdminDocsTestCase):
user.save()
response = self.client.head('/xview/class/')
self.assertNotIn('X-View', response)
+
+ def test_callable_object_view(self):
+ self.client.force_login(self.superuser)
+ response = self.client.head('/xview/callable_object/')
+ self.assertEqual(response['X-View'], 'admin_docs.views.XViewCallableObject')
diff --git a/tests/admin_docs/test_views.py b/tests/admin_docs/test_views.py
index bd483007c7..cf4f9359c7 100644
--- a/tests/admin_docs/test_views.py
+++ b/tests/admin_docs/test_views.py
@@ -54,6 +54,12 @@ class AdminDocViewTests(TestDataMixin, AdminDocsTestCase):
)
self.assertContains(response, 'Views by namespace test')
self.assertContains(response, 'Name: <code>test:func</code>.')
+ self.assertContains(
+ response,
+ '<h3><a href="/admindocs/views/admin_docs.views.XViewCallableObject/">'
+ '/xview/callable_object_without_xview/</a></h3>',
+ html=True,
+ )
@unittest.skipIf(six.PY2, "Python 2 doesn't support __qualname__.")
def test_view_index_with_method(self):
diff --git a/tests/admin_docs/urls.py b/tests/admin_docs/urls.py
index 0bcdee4b4b..67c72b249c 100644
--- a/tests/admin_docs/urls.py
+++ b/tests/admin_docs/urls.py
@@ -13,4 +13,6 @@ urlpatterns = [
url(r'^', include(ns_patterns, namespace='test')),
url(r'^xview/func/$', views.xview_dec(views.xview)),
url(r'^xview/class/$', views.xview_dec(views.XViewClass.as_view())),
+ url(r'^xview/callable_object/$', views.xview_dec(views.XViewCallableObject())),
+ url(r'^xview/callable_object_without_xview/$', views.XViewCallableObject()),
]
diff --git a/tests/admin_docs/views.py b/tests/admin_docs/views.py
index 31d253f7e2..21fe382bba 100644
--- a/tests/admin_docs/views.py
+++ b/tests/admin_docs/views.py
@@ -13,3 +13,8 @@ def xview(request):
class XViewClass(View):
def get(self, request):
return HttpResponse()
+
+
+class XViewCallableObject(View):
+ def __call__(self, request):
+ return HttpResponse()