'Asserts that a form used to render the response has a specific field
error.'

def assertFormError(self, response, form, field, errors, msg_prefix=u''):

    if msg_prefix:
        msg_prefix += u':    '
    contexts = to_list(response.context)
    if (not contexts):
        self.fail((msg_prefix + u'Response    did    not    use    any    contexts    to    render    the    response'))
    errors = to_list(errors)
    found_form = False
    for (i, context) in enumerate(contexts):
        if (form not in context):
            continue
        found_form = True
        for err in errors:
            if field:
                if (field in context[form].errors):
                    field_errors = context[form].errors[field]
                    self.assertTrue((err in field_errors), (msg_prefix + (u"The    field    '%s'    on    form    '%s'    in    context    %d    does    not    contain    the    error    '%s'    (actual    errors:    %s)" % (field, form, i, err, repr(field_errors)))))
                elif (field in context[form].fields):
                    self.fail((msg_prefix + (u"The    field    '%s'    on    form    '%s'    in    context    %d    contains    no    errors" % (field, form, i))))
                else:
                    self.fail((msg_prefix + (u"The    form    '%s'    in    context    %d    does    not    contain    the    field    '%s'" % (form, i, field))))
            else:
                non_field_errors = context[form].non_field_errors()
                self.assertTrue((err in non_field_errors), (msg_prefix + (u"The    form    '%s'    in    context    %d    does    not    contain    the    non-field    error    '%s'    (actual    errors:    %s)" % (form, i, err, non_field_errors))))
    if (not found_form):
        self.fail((msg_prefix + (u"The    form    '%s'    was    not    used    to    render    the    response" % form)))
