from datetime import datetime from django.forms import Form, SplitDateTimeField, SplitHiddenDateTimeWidget from django.utils import translation from .base import WidgetTest class SplitHiddenDateTimeWidgetTest(WidgetTest): widget = SplitHiddenDateTimeWidget() def test_render_empty(self): self.check_html( self.widget, "date", "", html=( '' ), ) def test_render_value(self): d = datetime(2007, 9, 17, 12, 51, 34, 482548) self.check_html( self.widget, "date", d, html=( '' '' ), ) self.check_html( self.widget, "date", datetime(2007, 9, 17, 12, 51, 34), html=( '' '' ), ) self.check_html( self.widget, "date", datetime(2007, 9, 17, 12, 51), html=( '' '' ), ) @translation.override("de-at") def test_l10n(self): d = datetime(2007, 9, 17, 12, 51) self.check_html( self.widget, "date", d, html=( """ """ ), ) def test_constructor_different_attrs(self): html = ( '' '' ) widget = SplitHiddenDateTimeWidget( date_attrs={"class": "foo"}, time_attrs={"class": "bar"} ) self.check_html(widget, "date", datetime(2006, 1, 10, 7, 30), html=html) widget = SplitHiddenDateTimeWidget( date_attrs={"class": "foo"}, attrs={"class": "bar"} ) self.check_html(widget, "date", datetime(2006, 1, 10, 7, 30), html=html) widget = SplitHiddenDateTimeWidget( time_attrs={"class": "bar"}, attrs={"class": "foo"} ) self.check_html(widget, "date", datetime(2006, 1, 10, 7, 30), html=html) def test_fieldset(self): class TestForm(Form): template_name = "forms_tests/use_fieldset.html" field = SplitDateTimeField(widget=self.widget) form = TestForm() self.assertIs(self.widget.use_fieldset, True) self.assertHTMLEqual( '' '', form.render(), ) def test_fieldset_with_unhidden_field(self): class TestForm(Form): template_name = "forms_tests/use_fieldset.html" hidden_field = SplitDateTimeField(widget=self.widget) unhidden_field = SplitDateTimeField() form = TestForm() self.assertIs(self.widget.use_fieldset, True) self.assertHTMLEqual( "
', form.render(), )