'Check for form errors.
Asserts that the response does contain a form in its
context, and that form has errors, if count were given,
it must match the exact numbers of errors'

def assertFormErrors(self, response, count=0, message=None, context_name='form'):

    context = getattr(response, 'context', {})
    assert (context and (context_name in context)), 'The    response    did    not    contain    a    form.'
    errors = response.context[context_name]._errors
    if count:
        assert (len(errors) == count), ('%d    errors    were    found    on    the    form,    %d    expected' % (len(errors), count))
        if (message and (message not in six.text_type(errors))):
            self.fail(('Expected    message    not    found,    instead    found:    %s' % [('%s:    %s' % (key, [e for e in field_errors])) for (key, field_errors) in errors.items()]))
    else:
        assert (len(errors) > 0), 'No    errors    were    found    on    the    form'
