File tree Expand file tree Collapse file tree 4 files changed +34
-49
lines changed Expand file tree Collapse file tree 4 files changed +34
-49
lines changed Original file line number Diff line number Diff line change 3
3
from __future__ import unicode_literals
4
4
from django .test import TestCase
5
5
from rest_framework .views import APIView
6
- from rest_framework .compat import apply_markdown
6
+ from rest_framework .compat import apply_markdown , smart_text
7
7
from rest_framework .utils .formatting import get_view_name , get_view_description
8
+ from rest_framework .tests .views import (
9
+ ViewWithNonASCIICharactersInDocstring , UTF8_TEST_DOCSTRING )
8
10
9
11
# We check that docstrings get nicely un-indented.
10
12
DESCRIPTION = """an example docstring
@@ -83,11 +85,10 @@ def test_view_description_supports_unicode(self):
83
85
Unicode in docstrings should be respected.
84
86
"""
85
87
86
- class MockView (APIView ):
87
- """Проверка"""
88
- pass
89
-
90
- self .assertEqual (get_view_description (MockView ), "Проверка" )
88
+ self .assertEqual (
89
+ get_view_description (ViewWithNonASCIICharactersInDocstring ),
90
+ smart_text (UTF8_TEST_DOCSTRING )
91
+ )
91
92
92
93
def test_view_description_can_be_empty (self ):
93
94
"""
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from rest_framework .views import APIView
4
+
5
+
6
+ # test strings snatched from http://www.columbia.edu/~fdc/utf8/,
7
+ # http://winrus.com/utf8-jap.htm and memory
8
+ UTF8_TEST_DOCSTRING = (
9
+ 'zażółć gęślą jaźń'
10
+ 'Sîne klâwen durh die wolken sint geslagen'
11
+ 'Τη γλώσσα μου έδωσαν ελληνική'
12
+ 'யாமறிந்த மொழிகளிலே தமிழ்மொழி'
13
+ 'На берегу пустынных волн'
14
+ 'てすと'
15
+ 'アイウエオカキクケコサシスセソタチツテ'
16
+ )
17
+
18
+
19
+ # Apparently there is an issue where docstrings of imported view classes
20
+ # do not retain their encoding information even if a module has a proper
21
+ # encoding declaration at the top of its source file. Therefore for tests
22
+ # to catch unicode related errors, a mock view has to be declared in a separate
23
+ # module.
24
+ class ViewWithNonASCIICharactersInDocstring (APIView ):
25
+ __doc__ = UTF8_TEST_DOCSTRING
Original file line number Diff line number Diff line change 5
5
6
6
from django .utils .html import escape
7
7
from django .utils .safestring import mark_safe
8
- from rest_framework .compat import apply_markdown
8
+ from rest_framework .compat import apply_markdown , smart_text
9
9
import re
10
10
11
11
@@ -24,11 +24,6 @@ def _remove_leading_indent(content):
24
24
Remove leading indent from a block of text.
25
25
Used when generating descriptions from docstrings.
26
26
"""
27
- try :
28
- content = content .decode ('utf-8' )
29
- except (AttributeError , UnicodeEncodeError ):
30
- pass # the string should keep the default 'ascii' encoding in
31
- # Python 2.x or stay a unicode string in Python 3.x
32
27
whitespace_counts = [len (line ) - len (line .lstrip (' ' ))
33
28
for line in content .splitlines ()[1 :] if line .lstrip ()]
34
29
@@ -68,7 +63,7 @@ def get_view_description(cls, html=False):
68
63
Return a description for an `APIView` class or `@api_view` function.
69
64
"""
70
65
description = cls .__doc__ or ''
71
- description = _remove_leading_indent (description )
66
+ description = _remove_leading_indent (smart_text ( description ) )
72
67
if html :
73
68
return markup_description (description )
74
69
return description
You can’t perform that action at this time.
0 commit comments