Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
fd3f538e
Commit
fd3f538e
authored
Apr 04, 2013
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix up view name/description tests
parent
f68721ad
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
40 deletions
+23
-40
rest_framework/tests/description.py
+23
-40
No files found.
rest_framework/tests/description.py
View file @
fd3f538e
...
@@ -4,6 +4,7 @@ from __future__ import unicode_literals
...
@@ -4,6 +4,7 @@ from __future__ import unicode_literals
from
django.test
import
TestCase
from
django.test
import
TestCase
from
rest_framework.views
import
APIView
from
rest_framework.views
import
APIView
from
rest_framework.compat
import
apply_markdown
from
rest_framework.compat
import
apply_markdown
from
rest_framework.utils.formatting
import
get_view_name
,
get_view_description
# We check that docstrings get nicely un-indented.
# We check that docstrings get nicely un-indented.
DESCRIPTION
=
"""an example docstring
DESCRIPTION
=
"""an example docstring
...
@@ -49,22 +50,16 @@ MARKED_DOWN_gte_21 = """<h2 id="an-example-docstring">an example docstring</h2>
...
@@ -49,22 +50,16 @@ MARKED_DOWN_gte_21 = """<h2 id="an-example-docstring">an example docstring</h2>
class
TestViewNamesAndDescriptions
(
TestCase
):
class
TestViewNamesAndDescriptions
(
TestCase
):
def
test_resource_name_uses_classname_by_default
(
self
):
def
test_view_name_uses_class_name
(
self
):
"""Ensure Resource names are based on the classname by default."""
"""
Ensure view names are based on the class name.
"""
class
MockView
(
APIView
):
class
MockView
(
APIView
):
pass
pass
self
.
assertEqual
(
MockView
()
.
get_name
(
),
'Mock'
)
self
.
assertEqual
(
get_view_name
(
MockView
),
'Mock'
)
def
test_resource_name_can_be_set_explicitly
(
self
):
def
test_view_description_uses_docstring
(
self
):
"""Ensure Resource names can be set using the 'get_name' method."""
"""Ensure view descriptions are based on the docstring."""
example
=
'Some Other Name'
class
MockView
(
APIView
):
def
get_name
(
self
):
return
example
self
.
assertEqual
(
MockView
()
.
get_name
(),
example
)
def
test_resource_description_uses_docstring_by_default
(
self
):
"""Ensure Resource names are based on the docstring by default."""
class
MockView
(
APIView
):
class
MockView
(
APIView
):
"""an example docstring
"""an example docstring
====================
====================
...
@@ -81,44 +76,32 @@ class TestViewNamesAndDescriptions(TestCase):
...
@@ -81,44 +76,32 @@ class TestViewNamesAndDescriptions(TestCase):
# hash style header #"""
# hash style header #"""
self
.
assertEqual
(
MockView
()
.
get_description
(),
DESCRIPTION
)
self
.
assertEqual
(
get_view_description
(
MockView
),
DESCRIPTION
)
def
test_resource_description_can_be_set_explicitly
(
self
):
"""Ensure Resource descriptions can be set using the 'get_description' method."""
example
=
'Some other description'
class
MockView
(
APIView
):
"""docstring"""
def
get_description
(
self
):
return
example
self
.
assertEqual
(
MockView
()
.
get_description
(),
example
)
def
test_resource_description_supports_unicode
(
self
):
def
test_view_description_supports_unicode
(
self
):
"""
Unicode in docstrings should be respected.
"""
class
MockView
(
APIView
):
class
MockView
(
APIView
):
"""Проверка"""
"""Проверка"""
pass
pass
self
.
assertEqual
(
MockView
()
.
get_description
(),
"Проверка"
)
self
.
assertEqual
(
get_view_description
(
MockView
),
"Проверка"
)
def
test_resource_description_does_not_require_docstring
(
self
):
"""Ensure that empty docstrings do not affect the Resource's description if it has been set using the 'get_description' method."""
example
=
'Some other description'
class
MockView
(
APIView
):
def
get_description
(
self
):
return
example
self
.
assertEqual
(
MockView
()
.
get_description
(),
example
)
def
test_resource_description_can_be_empty
(
self
):
def
test_view_description_can_be_empty
(
self
):
"""Ensure that if a resource has no doctring or 'description' class attribute, then it's description is the empty string."""
"""
Ensure that if a view has no docstring,
then it's description is the empty string.
"""
class
MockView
(
APIView
):
class
MockView
(
APIView
):
pass
pass
self
.
assertEqual
(
MockView
()
.
get_description
(
),
''
)
self
.
assertEqual
(
get_view_description
(
MockView
),
''
)
def
test_markdown
(
self
):
def
test_markdown
(
self
):
"""Ensure markdown to HTML works as expected"""
"""
Ensure markdown to HTML works as expected.
"""
if
apply_markdown
:
if
apply_markdown
:
gte_21_match
=
apply_markdown
(
DESCRIPTION
)
==
MARKED_DOWN_gte_21
gte_21_match
=
apply_markdown
(
DESCRIPTION
)
==
MARKED_DOWN_gte_21
lt_21_match
=
apply_markdown
(
DESCRIPTION
)
==
MARKED_DOWN_lt_21
lt_21_match
=
apply_markdown
(
DESCRIPTION
)
==
MARKED_DOWN_lt_21
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment