mirror of https://github.com/django/django.git
Added tests for SelectDateWidget.value_from_datadict().
This commit is contained in:
parent
1500573620
commit
3a4b11873a
|
@ -497,6 +497,25 @@ class SelectDateWidgetTest(WidgetTest):
|
|||
with self.subTest(value=value):
|
||||
self.assertEqual(self.widget.format_value(value), {'day': None, 'month': None, 'year': None})
|
||||
|
||||
def test_value_from_datadict(self):
|
||||
tests = [
|
||||
(('2000', '12', '1'), '2000-12-1'),
|
||||
(('0', '12', '1'), '0-12-1'),
|
||||
(('2000', '0', '1'), '2000-0-1'),
|
||||
(('2000', '12', '0'), '2000-12-0'),
|
||||
(('', '', '', ''), None),
|
||||
((None, '12', '1'), None),
|
||||
(('2000', None, '1'), None),
|
||||
(('2000', '12', None), None),
|
||||
]
|
||||
for values, expected in tests:
|
||||
with self.subTest(values=values):
|
||||
data = {}
|
||||
for field_name, value in zip(('year', 'month', 'day'), values):
|
||||
if value is not None:
|
||||
data['field_%s' % field_name] = value
|
||||
self.assertEqual(self.widget.value_from_datadict(data, {}, 'field'), expected)
|
||||
|
||||
def test_value_omitted_from_data(self):
|
||||
self.assertIs(self.widget.value_omitted_from_data({}, {}, 'field'), True)
|
||||
self.assertIs(self.widget.value_omitted_from_data({'field_month': '12'}, {}, 'field'), False)
|
||||
|
|
Loading…
Reference in New Issue