import datetime from django.forms import 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="""
""") def test_nested_choices(self): nested_choices = ( ('unknown', 'Unknown'), ('Audio', (('vinyl', 'Vinyl'), ('cd', 'CD'))), ('Video', (('vhs', 'VHS'), ('dvd', 'DVD'))), ) html = """
""" self.check_html( self.widget(choices=nested_choices), 'nestchoice', 'dvd', attrs={'id': 'media'}, html=html, ) def test_constructor_attrs(self): """ Attributes provided at instantiation are passed to the constituent inputs. """ widget = RadioSelect(attrs={'id': 'foo'}, choices=self.beatles) html = """
""" self.check_html(widget, 'beatle', 'J', html=html) def test_render_attrs(self): """ Attributes provided at render-time are passed to the constituent inputs. """ html = """
""" self.check_html(self.widget(choices=self.beatles), 'beatle', 'J', attrs={'id': 'bar'}, html=html) def test_class_attrs(self): """ The
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="""
""")