from datetime import date, datetime, time
from django.forms import SplitDateTimeWidget
from .base import WidgetTest
class SplitDateTimeWidgetTest(WidgetTest):
widget = SplitDateTimeWidget()
def test_render_empty(self):
self.check_html(
self.widget,
"date",
"",
html=(''),
)
def test_render_none(self):
self.check_html(
self.widget,
"date",
None,
html=(''),
)
def test_render_datetime(self):
self.check_html(
self.widget,
"date",
datetime(2006, 1, 10, 7, 30),
html=(
''
''
),
)
def test_render_date_and_time(self):
self.check_html(
self.widget,
"date",
[date(2006, 1, 10), time(7, 30)],
html=(
''
''
),
)
def test_constructor_attrs(self):
widget = SplitDateTimeWidget(attrs={"class": "pretty"})
self.check_html(
widget,
"date",
datetime(2006, 1, 10, 7, 30),
html=(
''
''
),
)
def test_constructor_different_attrs(self):
html = (
''
''
)
widget = SplitDateTimeWidget(
date_attrs={"class": "foo"}, time_attrs={"class": "bar"}
)
self.check_html(widget, "date", datetime(2006, 1, 10, 7, 30), html=html)
widget = SplitDateTimeWidget(
date_attrs={"class": "foo"}, attrs={"class": "bar"}
)
self.check_html(widget, "date", datetime(2006, 1, 10, 7, 30), html=html)
widget = SplitDateTimeWidget(
time_attrs={"class": "bar"}, attrs={"class": "foo"}
)
self.check_html(widget, "date", datetime(2006, 1, 10, 7, 30), html=html)
def test_formatting(self):
"""
Use 'date_format' and 'time_format' to change the way a value is
displayed.
"""
widget = SplitDateTimeWidget(
date_format="%d/%m/%Y",
time_format="%H:%M",
)
self.check_html(
widget,
"date",
datetime(2006, 1, 10, 7, 30),
html=(
''
''
),
)