import datetime
from django.forms import ChoiceField, Form, MultiWidget, RadioSelect
from django.test import override_settings
from .base import WidgetTest
class RadioSelectTest(WidgetTest):
widget = RadioSelect
def test_render(self):
choices = (("", "------"),) + self.beatles
self.check_html(
self.widget(choices=choices),
"beatle",
"J",
html="""
in the multiple_input.html widget template include the class
attribute.
"""
html = """
"""
self.check_html(
self.widget(choices=self.beatles),
"beatle",
"J",
attrs={"class": "bar"},
html=html,
)
@override_settings(USE_THOUSAND_SEPARATOR=True)
def test_doesnt_localize_input_value(self):
choices = [
(1, "One"),
(1000, "One thousand"),
(1000000, "One million"),
]
html = """
"""
self.check_html(self.widget(choices=choices), "number", None, html=html)
choices = [
(datetime.time(0, 0), "midnight"),
(datetime.time(12, 0), "noon"),
]
html = """
"""
self.check_html(self.widget(choices=choices), "time", None, html=html)
def test_render_as_subwidget(self):
"""A RadioSelect as a subwidget of MultiWidget."""
choices = (("", "------"),) + self.beatles
self.check_html(
MultiWidget([self.widget(choices=choices)]),
"beatle",
["J"],
html="""
""",
)
def test_fieldset(self):
class TestForm(Form):
template_name = "forms_tests/use_fieldset.html"
field = ChoiceField(
widget=self.widget, choices=self.beatles, required=False
)
form = TestForm()
self.assertIs(self.widget.use_fieldset, True)
self.assertHTMLEqual(
'
",
form.render(),
)