aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/tests
diff options
context:
space:
mode:
authorPaul Oswald2014-07-28 16:59:55 +0900
committerPaul Oswald2014-07-28 16:59:55 +0900
commit921e4ed2ee11edffd19d2ca40f10d47d2c148ea1 (patch)
treed6a331ba11ddf1d4faad0dbb655219ea8fca781a /rest_framework/tests
parentc7a988eb38b96926156f01c2b6f2603a4ef41ecf (diff)
downloaddjango-rest-framework-921e4ed2ee11edffd19d2ca40f10d47d2c148ea1.tar.bz2
Evaluate content before passing to regex.sub
Issue #1708
Diffstat (limited to 'rest_framework/tests')
-rw-r--r--rest_framework/tests/test_description.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/rest_framework/tests/test_description.py b/rest_framework/tests/test_description.py
index 4c03c1de..52fa55fb 100644
--- a/rest_framework/tests/test_description.py
+++ b/rest_framework/tests/test_description.py
@@ -2,6 +2,7 @@
from __future__ import unicode_literals
from django.test import TestCase
+from django.utils.encoding import python_2_unicode_compatible
from rest_framework.compat import apply_markdown, smart_text
from rest_framework.views import APIView
from rest_framework.tests.description import ViewWithNonASCIICharactersInDocstring
@@ -98,6 +99,27 @@ class TestViewNamesAndDescriptions(TestCase):
pass
self.assertEqual(MockView().get_view_description(), '')
+ def test_view_description_can_be_promise(self):
+ """
+ Ensure a view may have a docstring that is actually a lazily evaluated
+ class that can be converted to a string.
+
+ See: https://github.com/tomchristie/django-rest-framework/issues/1708
+ """
+ # use a mock object instead of gettext_lazy to ensure that we can't end
+ # up with a test case string in our l10n catalog
+ @python_2_unicode_compatible
+ class MockLazyStr(object):
+ def __init__(self, string):
+ self.s = string
+ def __str__(self):
+ return self.s
+
+ class MockView(APIView):
+ __doc__ = MockLazyStr("a gettext string")
+
+ self.assertEqual(MockView().get_view_description(), 'a gettext string')
+
def test_markdown(self):
"""
Ensure markdown to HTML works as expected.