Commit fd3f538e by Tom Christie

Fix up view name/description tests

parent f68721ad
...@@ -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
......
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