1
0
mirror of https://github.com/django/django.git synced 2024-12-25 10:35:48 +00:00
django/tests/forms_tests/widget_tests/test_splithiddendatetimewidget.py
Preston Timmons 4c30fa905d Rewrote form widget tests as proper unittests.
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.
2015-08-31 23:03:55 -05:00

43 lines
1.6 KiB
Python

from datetime import datetime
from django.forms import SplitHiddenDateTimeWidget
from django.test import override_settings
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=(
'<input type="hidden" name="date_0" /><input type="hidden" name="date_1" />'
))
def test_render_value(self):
d = datetime(2007, 9, 17, 12, 51, 34, 482548)
self.check_html(self.widget, 'date', d, html=(
'<input type="hidden" name="date_0" value="2007-09-17" />'
'<input type="hidden" name="date_1" value="12:51:34" />'
))
self.check_html(self.widget, 'date', datetime(2007, 9, 17, 12, 51, 34), html=(
'<input type="hidden" name="date_0" value="2007-09-17" />'
'<input type="hidden" name="date_1" value="12:51:34" />'
))
self.check_html(self.widget, 'date', datetime(2007, 9, 17, 12, 51), html=(
'<input type="hidden" name="date_0" value="2007-09-17" />'
'<input type="hidden" name="date_1" value="12:51:00" />'
))
@override_settings(USE_L10N=True)
@translation.override('de-at')
def test_l10n(self):
d = datetime(2007, 9, 17, 12, 51)
self.check_html(self.widget, 'date', d, html=(
"""
<input type="hidden" name="date_0" value="17.09.2007" />
<input type="hidden" name="date_1" value="12:51:00" />
"""
))