Commit d44a8f24 by José Padilla

Merge remote-tracking branch 'poswald/view-description-as-promise' into view-description-as-promise

parents f4e02446 3e93c96e
...@@ -5,6 +5,8 @@ from __future__ import unicode_literals ...@@ -5,6 +5,8 @@ from __future__ import unicode_literals
from django.utils.html import escape from django.utils.html import escape
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.utils.encoding import force_text
from rest_framework.compat import apply_markdown from rest_framework.compat import apply_markdown
import re import re
...@@ -28,6 +30,7 @@ def dedent(content): ...@@ -28,6 +30,7 @@ def dedent(content):
as it fails to dedent multiline docstrings that include as it fails to dedent multiline docstrings that include
unindented text on the initial line. unindented text on the initial line.
""" """
content = force_text(content)
whitespace_counts = [len(line) - len(line.lstrip(' ')) whitespace_counts = [len(line) - len(line.lstrip(' '))
for line in content.splitlines()[1:] if line.lstrip()] for line in content.splitlines()[1:] if line.lstrip()]
......
...@@ -98,6 +98,28 @@ class TestViewNamesAndDescriptions(TestCase): ...@@ -98,6 +98,28 @@ class TestViewNamesAndDescriptions(TestCase):
pass pass
self.assertEqual(MockView().get_view_description(), '') 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
class MockLazyStr(object):
def __init__(self, string):
self.s = string
def __str__(self):
return self.s
def __unicode__(self):
return self.s
class MockView(APIView):
__doc__ = MockLazyStr(u"a gettext string")
self.assertEqual(MockView().get_view_description(), u'a gettext string')
def test_markdown(self): def test_markdown(self):
""" """
Ensure markdown to HTML works as expected. Ensure markdown to HTML works as expected.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment