Skip to content

Commit

Permalink
Test that select widget works correctly with optgroup choices
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-maertens committed Apr 2, 2016
1 parent ec823bb commit c1cd905
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def runtests(args=None):

cov.stop()
cov.save()
if os.getenv('HTML_REPORT'):
cov.html_report()

sys.exit(failures)

Expand Down
4 changes: 4 additions & 0 deletions tests/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class DjangoWidgetsForm(forms.Form):
text = forms.CharField(widget=forms.Textarea)
checkbox = forms.BooleanField()
select = forms.ChoiceField(choices=((1, 'a'), (11, 'b'), (22, 'c')))
optgroup_select = forms.ChoiceField(choices=(
('label1', [(1, 'a'), (11, 'b')]),
('label2', [(22, 'c')])
))
null_boolean_select = forms.NullBooleanField()
select_multiple = forms.MultipleChoiceField(choices=((1, 'a'), (11, 'b'), (22, 'c')))
radio_select = forms.ChoiceField(choices=((1, 'a'), (11, 'b'), (22, 'c')),
Expand Down
12 changes: 12 additions & 0 deletions tests/test_widgets_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ def test_widgets_unbound(self):
<option value="11">b</option>
<option value="22">c</option>
</select>''',
'optgroup_select': '''
<select id="id_optgroup_select" name="optgroup_select">
<optgroup label="label1">
<option value="1">a</option>
<option value="11">b</option>
</optgroup>
<optgroup label="label2">
<option value="22">c</option>
</optgroup>
</select>''',
'null_boolean_select': '''
<select id="id_null_boolean_select" name="null_boolean_select">
<option value="1" selected="selected">Unknown</option>
Expand Down Expand Up @@ -118,6 +128,8 @@ def test_widgets_unbound(self):

# all kind of selects
self.assertInHTML(expected_output['select'], output, msg_prefix='Select rendered incorrectly: ')
self.assertInHTML(
expected_output['optgroup_select'], output, msg_prefix='Select with optgroups rendered incorrectly: ')
self.assertInHTML(
expected_output['null_boolean_select'], output, msg_prefix='NullBooleanSelect rendered incorrectly: ')
self.assertInHTML(
Expand Down

0 comments on commit c1cd905

Please sign in to comment.