from django.forms import CheckboxSelectMultiple from .base import WidgetTest class CheckboxSelectMultipleTest(WidgetTest): widget = CheckboxSelectMultiple() def test_render_value(self): self.check_html(self.widget, 'beatles', ['J'], choices=self.beatles, html=( """""" )) def test_render_value_multiple(self): self.check_html(self.widget, 'beatles', ['J', 'P'], choices=self.beatles, html=( """""" )) def test_render_none(self): """ If the value is None, none of the options are selected. """ self.check_html(self.widget, 'beatles', None, choices=self.beatles, 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, 'nestchoice', ('vinyl', 'dvd'), choices=nested_choices, attrs={'id': 'media'}, html=html, ) def test_separate_ids(self): """ Each input gets a separate ID. """ choices = [('a', 'A'), ('b', 'B'), ('c', 'C')] html = """ """ self.check_html(self.widget, 'letters', ['a', 'c'], choices=choices, attrs={'id': 'abc'}, html=html) def test_separate_ids_constructor(self): """ Each input gets a separate ID when the ID is passed to the constructor. """ widget = CheckboxSelectMultiple(attrs={'id': 'abc'}) choices = [('a', 'A'), ('b', 'B'), ('c', 'C')] html = """ """ self.check_html(widget, 'letters', ['a', 'c'], choices=choices, html=html)