summaryrefslogtreecommitdiff
path: root/tests/forms_tests
diff options
context:
space:
mode:
authorJeroen Dekkers <jeroen@dekkers.ch>2012-08-03 18:17:41 +0200
committerJeroen Dekkers <jeroen@dekkers.ch>2013-05-22 01:05:22 +0200
commitd0788c277035727b7b070abd0f02d075acffc84f (patch)
tree1b8ed7ba7f00d7de84cdafbf72bac316f86b20b7 /tests/forms_tests
parent5d164569916b44e476a3fa2a292c6fe9c6735177 (diff)
Fixed #18709 -- Check if initial_value is a callable
In _get_changed_data, check if initial_value is a callable and call it if it is.
Diffstat (limited to 'tests/forms_tests')
-rw-r--r--tests/forms_tests/tests/test_formsets.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/tests/forms_tests/tests/test_formsets.py b/tests/forms_tests/tests/test_formsets.py
index 767a900673..1e9e7db30c 100644
--- a/tests/forms_tests/tests/test_formsets.py
+++ b/tests/forms_tests/tests/test_formsets.py
@@ -1,8 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
+import datetime
+
from django.forms import (CharField, DateField, FileField, Form, IntegerField,
- ValidationError, formsets)
+ SplitDateTimeField, ValidationError, formsets)
from django.forms.formsets import BaseFormSet, formset_factory
from django.forms.util import ErrorList
from django.test import TestCase
@@ -45,6 +47,13 @@ FavoriteDrinksFormSet = formset_factory(FavoriteDrinkForm,
formset=BaseFavoriteDrinksFormSet, extra=3)
+# Used in ``test_formset_splitdatetimefield``.
+class SplitDateTimeForm(Form):
+ when = SplitDateTimeField(initial=datetime.datetime.now)
+
+SplitDateTimeFormSet = formset_factory(SplitDateTimeForm)
+
+
class FormsFormsetTestCase(TestCase):
def test_basic_formset(self):
# A FormSet constructor takes the same arguments as Form. Let's create a FormSet
@@ -882,6 +891,19 @@ class FormsFormsetTestCase(TestCase):
self.assertEqual(len(formset.forms), 0)
self.assertTrue(formset)
+ def test_formset_splitdatetimefield(self):
+ """
+ Formset should also work with SplitDateTimeField(initial=datetime.datetime.now).
+ Regression test for #18709.
+ """
+ data = {
+ 'form-TOTAL_FORMS': '1',
+ 'form-INITIAL_FORMS': '0',
+ 'form-0-when_0': '1904-06-16',
+ 'form-0-when_1': '15:51:33',
+ }
+ formset = SplitDateTimeFormSet(data)
+ self.assertTrue(formset.is_valid())
def test_formset_error_class(self):
# Regression tests for #16479 -- formsets form use ErrorList instead of supplied error_class