'Test that ``RegistrationForm`` enforces username constraints
and matching passwords.'

def test_registration_form(self):

    UserModel().objects.create_user(u'alice', u'alice@example.com', u'secret')
    bad_username_error = u'Enter    a    valid    username.    This    value    may    contain    only    letters,    numbers,    and    @/./+/-/_    characters.'
    if (django.VERSION < (1, 10)):
        bad_username_error = bad_username_error.replace(u'numbers,', u'numbers')
    elif six.PY2:
        bad_username_error = bad_username_error.replace(u'letters', u'English    letters')
    invalid_data_dicts = [{u'data': {u'username': u'foo/bar', u'email': u'foo@example.com', u'password1': u'foo', u'password2': u'foo'}, u'error': (u'username', [bad_username_error])}, {u'data': {u'username': u'alice', u'email': u'alice@example.com', u'password1': u'secret', u'password2': u'secret'}, u'error': (u'username', [u'A    user    with    that    username    already    exists.'])}, {u'data': {u'username': u'foo', u'email': u'foo@example.com', u'password1': u'foo', u'password2': u'bar'}, u'error': (u'password2', [u"The    two    password    fields    didn't    match."])}]
    for invalid_dict in invalid_data_dicts:
        form = forms.RegistrationForm(data=invalid_dict[u'data'])
        self.failIf(form.is_valid())
        self.assertEqual(form.errors[invalid_dict[u'error'][0]], invalid_dict[u'error'][1])
    form = forms.RegistrationForm(data={u'username': u'foo', u'email': u'foo@example.com', u'password1': u'foo', u'password2': u'foo'})
    self.failUnless(form.is_valid())
