"""
self.check_html(
self.widget(choices=nested_choices),
"nestchoice",
"dvd",
attrs={"id": "media"},
html=html,
)
def test_render_none(self):
"""
If value is None, none of the options are selected.
"""
choices = BLANK_CHOICE_DASH + self.beatles
html = """
"""
self.check_html(self.widget(choices=choices), "beatle", None, html=html)
def test_render_label_value(self):
"""
If the value corresponds to a label (but not to an option value), none
of the options are selected.
"""
html = """
"""
self.check_html(self.widget(choices=self.beatles), "beatle", "Ringo", html=html)
def test_render_selected(self):
"""
Only one option can be selected.
"""
choices = [("0", "0"), ("1", "1"), ("2", "2"), ("3", "3"), ("0", "extra")]
html = """
"""
self.check_html(self.widget(choices=choices), "choices", "0", html=html)
def test_constructor_attrs(self):
"""
Attributes provided at instantiation are passed to the constituent
inputs.
"""
widget = self.widget(attrs={"id": "foo"}, choices=self.beatles)
html = """
"""
self.check_html(widget, "beatle", "J", html=html)
def test_compare_to_str(self):
"""
The value is compared to its str()
"""
html = """
"""
self.check_html(widget, "num", 3, html=html)
def test_choices_constructor_generator(self):
"""
If choices is passed to the constructor and is a generator, it can be
iterated over multiple times without getting consumed.
"""
def get_choices():
for i in range(4):
yield (i, i)
html = """
"""
self.check_html(self.widget(choices=choices), "escape", None, html=html)
def test_choices_unicode(self):
html = """
"""
self.check_html(
self.widget(choices=[("ŠĐĆŽćžšđ", "ŠĐabcĆŽćžšđ"), ("ćžšđ", "abcćžšđ")]),
"email",
"ŠĐĆŽćžšđ",
html=html,
)
def test_choices_optgroup(self):
"""
Choices can be nested one level in order to create HTML optgroups
"""
html = """
"""
self.check_html(self.nested_widget, "nestchoice", None, html=html)
def test_choices_select_outer(self):
html = """
"""
self.check_html(self.nested_widget, "nestchoice", "outer1", html=html)
def test_choices_select_inner(self):
html = """
"""
self.check_html(self.nested_widget, "nestchoice", "inner2", html=html)
def test_render_attrs(self):
"""
Attributes provided at render-time are passed to the constituent
inputs.
"""
html = """