2015-08-31 04:13:42 +02:00
|
|
|
from django.forms import NullBooleanSelect
|
|
|
|
from django.test import override_settings
|
|
|
|
from django.utils import translation
|
|
|
|
|
|
|
|
from .base import WidgetTest
|
|
|
|
|
|
|
|
|
|
|
|
class NullBooleanSelectTest(WidgetTest):
|
|
|
|
widget = NullBooleanSelect()
|
|
|
|
|
|
|
|
def test_render_true(self):
|
|
|
|
self.check_html(self.widget, 'is_cool', True, html=(
|
|
|
|
"""<select name="is_cool">
|
|
|
|
<option value="1">Unknown</option>
|
2016-09-22 00:12:13 +02:00
|
|
|
<option value="2" selected>Yes</option>
|
2015-08-31 04:13:42 +02:00
|
|
|
<option value="3">No</option>
|
|
|
|
</select>"""
|
|
|
|
))
|
|
|
|
|
|
|
|
def test_render_false(self):
|
|
|
|
self.check_html(self.widget, 'is_cool', False, html=(
|
|
|
|
"""<select name="is_cool">
|
|
|
|
<option value="1">Unknown</option>
|
|
|
|
<option value="2">Yes</option>
|
2016-09-22 00:12:13 +02:00
|
|
|
<option value="3" selected>No</option>
|
2015-08-31 04:13:42 +02:00
|
|
|
</select>"""
|
|
|
|
))
|
|
|
|
|
|
|
|
def test_render_none(self):
|
|
|
|
self.check_html(self.widget, 'is_cool', None, html=(
|
|
|
|
"""<select name="is_cool">
|
2016-09-22 00:12:13 +02:00
|
|
|
<option value="1" selected>Unknown</option>
|
2015-08-31 04:13:42 +02:00
|
|
|
<option value="2">Yes</option>
|
|
|
|
<option value="3">No</option>
|
|
|
|
</select>"""
|
|
|
|
))
|
|
|
|
|
|
|
|
def test_render_value(self):
|
|
|
|
self.check_html(self.widget, 'is_cool', '2', html=(
|
|
|
|
"""<select name="is_cool">
|
|
|
|
<option value="1">Unknown</option>
|
2016-09-22 00:12:13 +02:00
|
|
|
<option value="2" selected>Yes</option>
|
2015-08-31 04:13:42 +02:00
|
|
|
<option value="3">No</option>
|
|
|
|
</select>"""
|
|
|
|
))
|
|
|
|
|
|
|
|
@override_settings(USE_L10N=True)
|
|
|
|
def test_l10n(self):
|
|
|
|
"""
|
2016-10-27 09:53:39 +02:00
|
|
|
The NullBooleanSelect widget's options are lazily localized (#17190).
|
2015-08-31 04:13:42 +02:00
|
|
|
"""
|
|
|
|
widget = NullBooleanSelect()
|
|
|
|
|
|
|
|
with translation.override('de-at'):
|
|
|
|
self.check_html(widget, 'id_bool', True, html=(
|
|
|
|
"""
|
|
|
|
<select name="id_bool">
|
|
|
|
<option value="1">Unbekannt</option>
|
2016-09-22 00:12:13 +02:00
|
|
|
<option value="2" selected>Ja</option>
|
2015-08-31 04:13:42 +02:00
|
|
|
<option value="3">Nein</option>
|
|
|
|
</select>
|
|
|
|
"""
|
|
|
|
))
|