mirror of
https://github.com/django/django.git
synced 2024-11-18 15:34:16 +00:00
4c30fa905d
This is preparation for landing the template-based widget rendering patch and goes a long way to making these tests more useful for future development. The old doctest heritage is strong here.
52 lines
1.9 KiB
Python
52 lines
1.9 KiB
Python
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=(
|
|
'<input type="text" name="date_0" /><input type="text" name="date_1" />'
|
|
))
|
|
|
|
def test_render_none(self):
|
|
self.check_html(self.widget, 'date', None, html=(
|
|
'<input type="text" name="date_0" /><input type="text" name="date_1" />'
|
|
))
|
|
|
|
def test_render_datetime(self):
|
|
self.check_html(self.widget, 'date', datetime(2006, 1, 10, 7, 30), html=(
|
|
'<input type="text" name="date_0" value="2006-01-10" />'
|
|
'<input type="text" name="date_1" value="07:30:00" />'
|
|
))
|
|
|
|
def test_render_date_and_time(self):
|
|
self.check_html(self.widget, 'date', [date(2006, 1, 10), time(7, 30)], html=(
|
|
'<input type="text" name="date_0" value="2006-01-10" />'
|
|
'<input type="text" name="date_1" value="07:30:00" />'
|
|
))
|
|
|
|
def test_constructor_attrs(self):
|
|
widget = SplitDateTimeWidget(attrs={'class': 'pretty'})
|
|
self.check_html(widget, 'date', datetime(2006, 1, 10, 7, 30), html=(
|
|
'<input type="text" class="pretty" value="2006-01-10" name="date_0" />'
|
|
'<input type="text" class="pretty" value="07:30:00" name="date_1" />'
|
|
))
|
|
|
|
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=(
|
|
'<input type="text" name="date_0" value="10/01/2006" />'
|
|
'<input type="text" name="date_1" value="07:30" />'
|
|
))
|