From bc1e2d8e8edde6cc7d2657c68242a13ee65a15b8 Mon Sep 17 00:00:00 2001 From: Helen Sherwood-Taylor Date: Fri, 12 Aug 2016 19:07:24 +0100 Subject: Fixed #27018 -- Fixed admindocs crash with a view in a class. Generated correct admindocs URLs on Python 3. URLs generate 404s on Python 2, as in older versions of Django. --- tests/admin_docs/tests.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests/admin_docs') diff --git a/tests/admin_docs/tests.py b/tests/admin_docs/tests.py index 82384a4bb8..f57a9c8117 100644 --- a/tests/admin_docs/tests.py +++ b/tests/admin_docs/tests.py @@ -9,6 +9,7 @@ from django.contrib.sites.models import Site from django.test import TestCase, modify_settings, override_settings from django.test.utils import captured_stderr from django.urls import reverse +from django.utils import six from .models import Company, Person @@ -82,6 +83,18 @@ class AdminDocViewTests(TestDataMixin, AdminDocsTestCase): self.assertContains(response, 'Views by namespace test') self.assertContains(response, 'Name: test:func.') + @unittest.skipIf(six.PY2, "Python 2 doesn't support __qualname__.") + def test_view_index_with_method(self): + """ + Views that are methods are listed correctly. + """ + response = self.client.get(reverse('django-admindocs-views-index')) + self.assertContains( + response, + '

/admin/

', + html=True + ) + def test_view_detail(self): url = reverse('django-admindocs-views-detail', args=['django.contrib.admindocs.views.BaseAdminDocsView']) response = self.client.get(url) @@ -103,6 +116,14 @@ class AdminDocViewTests(TestDataMixin, AdminDocsTestCase): self.assertEqual(response.status_code, 404) self.assertNotIn("urlpatterns_reverse.nonimported_module", sys.modules) + def test_view_detail_as_method(self): + """ + Views that are methods can be displayed. + """ + url = reverse('django-admindocs-views-detail', args=['django.contrib.admin.sites.AdminSite.index']) + response = self.client.get(url) + self.assertEqual(response.status_code, 200 if six.PY3 else 404) + def test_model_index(self): response = self.client.get(reverse('django-admindocs-models-index')) self.assertContains( -- cgit v1.3