0
0
mirror of https://github.com/django/django.git synced 2024-12-01 07:31:48 +01:00
django/tests/forms_tests/widget_tests/base.py
Dmitry 12cefee5d8 Refs #15667 -- Prevented newlines in attrs.html widget rendering.
Removed the trailing newline from widget attrs.html template.
The solution may be revisited by fixing refs #9198 but not
for Django 1.11.

Thanks Dmitry Ivanchenko for the report and Preston Timmons for advice.
2017-01-06 19:11:32 -05:00

29 lines
1.1 KiB
Python

from django.forms.renderers import DjangoTemplates, Jinja2
from django.test import SimpleTestCase
try:
import jinja2
except ImportError:
jinja2 = None
class WidgetTest(SimpleTestCase):
beatles = (('J', 'John'), ('P', 'Paul'), ('G', 'George'), ('R', 'Ringo'))
@classmethod
def setUpClass(cls):
cls.django_renderer = DjangoTemplates()
cls.jinja2_renderer = Jinja2() if jinja2 else None
cls.renderers = [cls.django_renderer] + ([cls.jinja2_renderer] if cls.jinja2_renderer else [])
super(WidgetTest, cls).setUpClass()
def check_html(self, widget, name, value, html='', attrs=None, strict=False, **kwargs):
assertEqual = self.assertEqual if strict else self.assertHTMLEqual
if self.jinja2_renderer:
output = widget.render(name, value, attrs=attrs, renderer=self.jinja2_renderer, **kwargs)
# Django escapes quotes with '"' while Jinja2 uses '"'.
assertEqual(output.replace('"', '"'), html)
output = widget.render(name, value, attrs=attrs, renderer=self.django_renderer, **kwargs)
assertEqual(output, html)