summaryrefslogtreecommitdiff
path: root/tests/forms_tests
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2013-03-08 18:16:38 +0100
committerClaude Paroz <claude@2xlibre.net>2013-03-08 18:19:24 +0100
commitcbfb8ed53b31ec9701f5fb8e519a8644fd4c8095 (patch)
tree15c59a9a317fe3acb7956ff4c0e680fc959ef00a /tests/forms_tests
parent6983a1a540a6e6c3bd941fa15ddd8cb49f9ec74e (diff)
Fixed a regression in forms changed_data
Thanks Loic Bistuer for spotting the regression and the initial patch. Refs #16612.
Diffstat (limited to 'tests/forms_tests')
-rw-r--r--tests/forms_tests/tests/forms.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/forms_tests/tests/forms.py b/tests/forms_tests/tests/forms.py
index 9cf217b86b..ff4630b7d6 100644
--- a/tests/forms_tests/tests/forms.py
+++ b/tests/forms_tests/tests/forms.py
@@ -1201,6 +1201,32 @@ class FormsTestCase(TestCase):
<option value="w">whiz</option>
</select></li>""")
+ def test_changed_data(self):
+ class Person(Form):
+ first_name = CharField(initial='Hans')
+ last_name = CharField(initial='Greatel')
+ birthday = DateField(initial=datetime.date(1974, 8, 16))
+
+ p = Person(data={'first_name': 'Hans', 'last_name': 'Scrmbl',
+ 'birthday': '1974-08-16'})
+ self.assertTrue(p.is_valid())
+ self.assertNotIn('first_name', p.changed_data)
+ self.assertIn('last_name', p.changed_data)
+ self.assertNotIn('birthday', p.changed_data)
+
+ # Test that field raising ValidationError is always in changed_data
+ class PedanticField(forms.Field):
+ def to_python(self, value):
+ raise ValidationError('Whatever')
+
+ class Person2(Person):
+ pedantic = PedanticField(initial='whatever', show_hidden_initial=True)
+
+ p = Person2(data={'first_name': 'Hans', 'last_name': 'Scrmbl',
+ 'birthday': '1974-08-16', 'initial-pedantic': 'whatever'})
+ self.assertFalse(p.is_valid())
+ self.assertIn('pedantic', p.changed_data)
+
def test_boundfield_values(self):
# It's possible to get to the value which would be used for rendering
# the widget for a field by using the BoundField's value method.