Add tests for some template tags (#4815)

This commit is contained in:
Artem Muterko 2017-01-18 22:41:32 +02:00 committed by Tom Christie
parent a8534baa41
commit 46210205a4

View File

@ -5,7 +5,8 @@ from django.test import TestCase
from rest_framework.relations import Hyperlink
from rest_framework.templatetags.rest_framework import (
add_nested_class, add_query_param, format_value, urlize_quoted_links
add_nested_class, add_query_param, as_string, break_long_headers,
format_value, get_pagination_html, urlize_quoted_links
)
from rest_framework.test import APIRequestFactory
@ -214,6 +215,27 @@ class TemplateTagTests(TestCase):
for case in negative_cases:
self.assertEqual(add_nested_class(case), '')
def test_as_string_with_none(self):
result = as_string(None)
assert result == ''
def test_get_pagination_html(self):
class MockPager(object):
def __init__(self):
self.called = False
def to_html(self):
self.called = True
pager = MockPager()
get_pagination_html(pager)
assert pager.called is True
def test_break_long_lines(self):
header = 'long test header,' * 20
expected_header = '<br> ' + ', <br>'.join(header.split(','))
assert break_long_headers(header) == expected_header
class Issue1386Tests(TestCase):
"""