select nameiscool option valueunknownunknownoption option valuetrue selectedyesoption option valuefalsenooption select def testrenderfalseself self checkhtml self widget iscool false html select nameiscool option valueunknown selectedunknownoption option valuetrueyesoption option valuefalsenooption select def testrendervalueunknownself self checkhtml self widget iscool unknown html select nameiscool option valueunknownunknownoption option valuetrue selectedyesoption option valuefalsenooption select def testrendervaluefalseself self checkhtml self widget iscool false html select nameiscool option valueunknown selectedunknownoption option valuetrueyesoption option valuefalsenooption select def testrendervalue2self self checkhtml self widget iscool 2 html select nameiscool option valueunknownunknownoption option valuetrueyesoption option valuefalse selectednooption select def testl10nself widget nullbooleanselect with translation overridedeat self checkhtml widget idbool true html def testfieldsetself class testformform templatename formstestsusefieldset html field nullbooleanfieldwidgetself widget form testform self assertisself widget usefieldset false self asserthtmlequal divlabel foridfieldfield label select namefield ididfield option valueunknown selectedunknownoption option valuetrueyesoption option valuefalsenooptionselectdiv form render select name is_cool option value unknown unknown option option value true selected yes option option value false no option select select name is_cool option value unknown unknown option option value true yes option option value false selected no option select select name is_cool option value unknown selected unknown option option value true yes option option value false no option select select name is_cool option value unknown selected unknown option option value true yes option option value false no option select select name is_cool option value unknown unknown option option value true selected yes option option value false no option select select name is_cool option value unknown unknown option option value true yes option option value false selected no option select select name is_cool option value unknown selected unknown option option value true yes option option value false no option select select name is_cool option value unknown unknown option option value true selected yes option option value false no option select select name is_cool option value unknown unknown option option value true yes option option value false selected no option select the nullbooleanselect widget s options are lazily localized 17190 select name id_bool option value unknown unbekannt option option value true selected ja option option value false nein option select
from django.forms import Form, NullBooleanField, NullBooleanSelect
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=(
                
            ),
        )

    def test_render_false(self):
        self.check_html(
            self.widget,
            "is_cool",
            False,
            html=(
                
            ),
        )

    def test_render_none(self):
        self.check_html(
            self.widget,
            "is_cool",
            None,
            html=(
                
            ),
        )

    def test_render_value_unknown(self):
        self.check_html(
            self.widget,
            "is_cool",
            "unknown",
            html=(
                
            ),
        )

    def test_render_value_true(self):
        self.check_html(
            self.widget,
            "is_cool",
            "true",
            html=(
                
            ),
        )

    def test_render_value_false(self):
        self.check_html(
            self.widget,
            "is_cool",
            "false",
            html=(
                
            ),
        )

    def test_render_value_1(self):
        self.check_html(
            self.widget,
            "is_cool",
            "1",
            html=(
                
            ),
        )

    def test_render_value_2(self):
        self.check_html(
            self.widget,
            "is_cool",
            "2",
            html=(
                
            ),
        )

    def test_render_value_3(self):
        self.check_html(
            self.widget,
            "is_cool",
            "3",
            html=(
                
            ),
        )

    def test_l10n(self):
        
        widget = NullBooleanSelect()

        with translation.override("de-at"):
            self.check_html(
                widget,
                "id_bool",
                True,
                html=(
                    
                ),
            )

    def test_fieldset(self):
        class TestForm(Form):
            template_name = "forms_tests/use_fieldset.html"
            field = NullBooleanField(widget=self.widget)

        form = TestForm()
        self.assertIs(self.widget.use_fieldset, False)
        self.assertHTMLEqual(
            '<div><label for="id_field">Field:</label>'
            '<select name="field" id="id_field">'
            '<option value="unknown" selected>Unknown</option>'
            '<option value="true">Yes</option>'
            '<option value="false">No</option></select></div>',
            form.render(),
        )