2015-08-31 02:13:42 +00:00
|
|
|
from datetime import time
|
|
|
|
|
|
|
|
from django.forms import TimeInput
|
|
|
|
from django.test import override_settings
|
|
|
|
from django.utils import translation
|
|
|
|
|
|
|
|
from .base import WidgetTest
|
|
|
|
|
|
|
|
|
|
|
|
class TimeInputTest(WidgetTest):
|
|
|
|
widget = TimeInput()
|
|
|
|
|
|
|
|
def test_render_none(self):
|
2018-01-21 07:09:10 +00:00
|
|
|
self.check_html(self.widget, 'time', None, html='<input type="text" name="time">')
|
2015-08-31 02:13:42 +00:00
|
|
|
|
|
|
|
def test_render_value(self):
|
|
|
|
"""
|
|
|
|
The microseconds are trimmed on display, by default.
|
|
|
|
"""
|
|
|
|
t = time(12, 51, 34, 482548)
|
|
|
|
self.assertEqual(str(t), '12:51:34.482548')
|
2018-01-21 07:09:10 +00:00
|
|
|
self.check_html(self.widget, 'time', t, html='<input type="text" name="time" value="12:51:34">')
|
2015-08-31 02:13:42 +00:00
|
|
|
self.check_html(self.widget, 'time', time(12, 51, 34), html=(
|
2018-01-21 07:09:10 +00:00
|
|
|
'<input type="text" name="time" value="12:51:34">'
|
2015-08-31 02:13:42 +00:00
|
|
|
))
|
|
|
|
self.check_html(self.widget, 'time', time(12, 51), html=(
|
2018-01-21 07:09:10 +00:00
|
|
|
'<input type="text" name="time" value="12:51:00">'
|
2015-08-31 02:13:42 +00:00
|
|
|
))
|
|
|
|
|
|
|
|
def test_string(self):
|
2017-01-20 21:04:05 +00:00
|
|
|
"""Initializing from a string value."""
|
2015-08-31 02:13:42 +00:00
|
|
|
self.check_html(self.widget, 'time', '13:12:11', html=(
|
2018-01-21 07:09:10 +00:00
|
|
|
'<input type="text" name="time" value="13:12:11">'
|
2015-08-31 02:13:42 +00:00
|
|
|
))
|
|
|
|
|
|
|
|
def test_format(self):
|
|
|
|
"""
|
|
|
|
Use 'format' to change the way a value is displayed.
|
|
|
|
"""
|
|
|
|
t = time(12, 51, 34, 482548)
|
|
|
|
widget = TimeInput(format='%H:%M', attrs={'type': 'time'})
|
2018-01-21 07:09:10 +00:00
|
|
|
self.check_html(widget, 'time', t, html='<input type="time" name="time" value="12:51">')
|
2015-08-31 02:13:42 +00:00
|
|
|
|
|
|
|
@override_settings(USE_L10N=True)
|
|
|
|
@translation.override('de-at')
|
|
|
|
def test_l10n(self):
|
|
|
|
t = time(12, 51, 34, 482548)
|
2018-01-21 07:09:10 +00:00
|
|
|
self.check_html(self.widget, 'time', t, html='<input type="text" name="time" value="12:51:34">')
|