Added the actual assertFormError changes, accidentally omitted from [5181].

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5182 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee 2007-05-10 13:48:18 +00:00
parent 70902908c7
commit 244a5d0006
1 changed files with 13 additions and 10 deletions

View File

@ -105,18 +105,21 @@ class TestCase(unittest.TestCase):
for i,context in enumerate(contexts): for i,context in enumerate(contexts):
if form in context: if form in context:
found_form = True found_form = True
try: for err in errors:
for err in errors: if field:
if field: if field in context[form].errors:
self.assertTrue(err in context[form].errors[field], self.assertTrue(err in context[form].errors[field],
"The field '%s' on form '%s' in context %d does not contain the error '%s' (actual errors: %s)" % "The field '%s' on form '%s' in context %d does not contain the error '%s' (actual errors: %s)" %
(field, form, i, err, list(context[form].errors[field]))) (field, form, i, err, list(context[form].errors[field])))
elif field in context[form].fields:
self.fail("The field '%s' on form '%s' in context %d contains no errors" %
(field, form, i))
else: else:
self.assertTrue(err in context[form].non_field_errors(), self.fail("The form '%s' in context %d does not contain the field '%s'" % (form, i, field))
"The form '%s' in context %d does not contain the non-field error '%s' (actual errors: %s)" % else:
(form, i, err, list(context[form].non_field_errors()))) self.assertTrue(err in context[form].non_field_errors(),
except KeyError: "The form '%s' in context %d does not contain the non-field error '%s' (actual errors: %s)" %
self.fail("The form '%s' in context %d does not contain the field '%s'" % (form, i, field)) (form, i, err, list(context[form].non_field_errors())))
if not found_form: if not found_form:
self.fail("The form '%s' was not used to render the response" % form) self.fail("The form '%s' was not used to render the response" % form)