diff options
| author | Tai Lee <tai.lee@3030.com.au> | 2013-06-18 10:10:21 +1000 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2013-10-04 13:27:08 -0400 |
| commit | bcd4c3f27d5bcf701337ac7c74c042d90792bdc3 (patch) | |
| tree | 1ae6457311bd778ae84a0c38aee73acc56879bcd /tests | |
| parent | 3895d8899d7a01f2bdb1c206e45d8578a9739c91 (diff) | |
Fixed #6681 -- Don't break docutils when rendering reStructuredText.
Don't set a global default interpreted role function for reStructuredText.
Instead, use the `default-role` directive to change the default only within
the `parse_rst()` function.
Thanks Malcolm Tredinnick for the report.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/admin_docs/tests.py | 44 | ||||
| -rw-r--r-- | tests/admin_docs/urls.py | 3 |
2 files changed, 46 insertions, 1 deletions
diff --git a/tests/admin_docs/tests.py b/tests/admin_docs/tests.py index aeb527c7b9..3ae3a42843 100644 --- a/tests/admin_docs/tests.py +++ b/tests/admin_docs/tests.py @@ -1,3 +1,11 @@ +import unittest + +try: + import docutils +except ImportError: + docutils = None + +from django.contrib.admindocs import utils from django.contrib.auth.models import User from django.test import TestCase from django.test.utils import override_settings @@ -43,3 +51,39 @@ class XViewMiddlewareTest(TestCase): user.save() response = self.client.head('/xview/class/') self.assertFalse('X-View' in response) + + +@unittest.skipUnless(docutils, "no docutils installed.") +class DefaultRoleTest(TestCase): + urls = 'admin_docs.urls' + + def test_parse_rst(self): + """ + Tests that ``django.contrib.admindocs.utils.parse_rst`` uses + ``cmsreference`` as the default role. + """ + markup = ('<p><a class="reference external" href="/admindocs/%s">' + 'title</a></p>\n') + self.assertEqual(utils.parse_rst('`title`', 'model'), + markup % 'models/title/') + self.assertEqual(utils.parse_rst('`title`', 'view'), + markup % 'views/title/') + self.assertEqual(utils.parse_rst('`title`', 'template'), + markup % 'templates/title/') + self.assertEqual(utils.parse_rst('`title`', 'filter'), + markup % 'filters/#title') + self.assertEqual(utils.parse_rst('`title`', 'tag'), + markup % 'tags/#title') + + def test_publish_parts(self): + """ + Tests that Django hasn't broken the default role for interpreted text + when ``publish_parts`` is used directly, by setting it to + ``cmsreference``. See #6681. + """ + self.assertNotEqual(docutils.parsers.rst.roles.DEFAULT_INTERPRETED_ROLE, + 'cmsreference') + source = 'reST, `interpreted text`, default role.' + markup = '<p>reST, <cite>interpreted text</cite>, default role.</p>\n' + parts = docutils.core.publish_parts(source=source, writer_name="html4css1") + self.assertEqual(parts['fragment'], markup) diff --git a/tests/admin_docs/urls.py b/tests/admin_docs/urls.py index 914b4836e0..08eaf03632 100644 --- a/tests/admin_docs/urls.py +++ b/tests/admin_docs/urls.py @@ -1,8 +1,9 @@ -from django.conf.urls import patterns +from django.conf.urls import include, patterns from . import views urlpatterns = patterns('', + (r'^admindocs/', include('django.contrib.admindocs.urls')), (r'^xview/func/$', views.xview_dec(views.xview)), (r'^xview/class/$', views.xview_dec(views.XViewClass.as_view())), ) |
