Skip to content

Instantly share code, notes, and snippets.

@loic
Created June 30, 2014 08:24
Show Gist options
  • Save loic/3ca561e77949e63556e3 to your computer and use it in GitHub Desktop.
Save loic/3ca561e77949e63556e3 to your computer and use it in GitHub Desktop.
diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py
index 985ff8e..f87b684 100644
--- a/tests/forms_tests/tests/test_forms.py
+++ b/tests/forms_tests/tests/test_forms.py
@@ -740,6 +740,25 @@ class FormsTestCase(TestCase):
with six.assertRaisesRegex(self, ValueError, "has no field named"):
f.add_error('missing_field', 'Some error.')
+ def test_regression_17(self):
+ class CodeForm(Form):
+ code = CharField(max_length=10)
+
+ def clean(self):
+ try:
+ raise ValidationError({
+ 'code': [ValidationError('Code error')]
+ })
+ except ValidationError as e:
+ for field, error_list in e.update_error_dict({}).items():
+ self._errors.setdefault(field, self.error_class()).extend(error_list)
+ del self.cleaned_data[field]
+
+ form = CodeForm({'code': 'hello'})
+ form.is_valid()
+ self.assertEqual(form.cleaned_data, {})
+ self.assertEqual(dict(form.errors), {'code': ['Code error']})
+
def test_has_error(self):
class UserRegistration(Form):
username = CharField(max_length=10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment