Ejemplo n.º 1
0
    def test_ValidPasswordsMatch(self):
        validator = v.ValidPasswordsMatch()
        self.assertRaises(formencode.Invalid, validator.to_python, {
            'password': '******',
            'password_confirmation': 'pass2'
        })

        self.assertRaises(formencode.Invalid, validator.to_python, {
            'new_password': '******',
            'password_confirmation': 'pass2'
        })

        self.assertEqual(
            {
                'new_password': '******',
                'password_confirmation': 'pass'
            },
            validator.to_python({
                'new_password': '******',
                'password_confirmation': 'pass'
            }))

        self.assertEqual({
            'password': '******',
            'password_confirmation': 'pass'
        },
                         validator.to_python({
                             'password': '******',
                             'password_confirmation': 'pass'
                         }))
Ejemplo n.º 2
0
    class _UserForm(formencode.Schema):
        allow_extra_fields = True
        filter_extra_fields = True
        username = All(v.UnicodeString(strip=True, min=1, not_empty=True),
                       v.ValidUsername(edit, old_data))
        if edit:
            new_password = All(
                v.ValidPassword(),
                v.UnicodeString(strip=False, min=6, not_empty=False))
            password_confirmation = All(
                v.ValidPassword(),
                v.UnicodeString(strip=False, min=6, not_empty=False),
            )
            admin = v.StringBoolean(if_missing=False)
        else:
            password = All(v.ValidPassword(),
                           v.UnicodeString(strip=False, min=6, not_empty=True))
            password_confirmation = All(
                v.ValidPassword(),
                v.UnicodeString(strip=False, min=6, not_empty=False))

        active = v.StringBoolean(if_missing=False)
        firstname = v.UnicodeString(strip=True, min=1, not_empty=False)
        lastname = v.UnicodeString(strip=True, min=1, not_empty=False)
        email = All(v.Email(not_empty=True), v.UniqSystemEmail(old_data))

        chained_validators = [v.ValidPasswordsMatch()]
Ejemplo n.º 3
0
    class _UserForm(formencode.Schema):
        allow_extra_fields = True
        filter_extra_fields = True
        username = All(v.UnicodeString(strip=True, min=1, not_empty=True),
                       v.ValidUsername(edit, old_data))
        if edit:
            new_password = All(
                v.ValidPassword(),
                v.UnicodeString(strip=False, min=6, not_empty=False))
            password_confirmation = All(
                v.ValidPassword(),
                v.UnicodeString(strip=False, min=6, not_empty=False),
            )
            admin = v.StringBoolean(if_missing=False)
        else:
            password = All(v.ValidPassword(),
                           v.UnicodeString(strip=False, min=6, not_empty=True))
            password_confirmation = All(
                v.ValidPassword(),
                v.UnicodeString(strip=False, min=6, not_empty=False))

        password_change = v.StringBoolean(if_missing=False)
        create_repo_group = v.StringBoolean(if_missing=False)

        active = v.StringBoolean(if_missing=False)
        firstname = v.UnicodeString(strip=True, min=1, not_empty=False)
        lastname = v.UnicodeString(strip=True, min=1, not_empty=False)
        email = All(v.Email(not_empty=True), v.UniqSystemEmail(old_data))
        extern_name = v.UnicodeString(strip=True)
        extern_type = v.UnicodeString(strip=True)
        language = v.OneOf(available_languages,
                           hideList=False,
                           testValueList=True,
                           if_missing=None)
        chained_validators = [v.ValidPasswordsMatch()]
Ejemplo n.º 4
0
 def test_register_password_mismatch(self):
     response = self.app.post(
         url(controller='login', action='register'), {
             'username': '******',
             'password': '******',
             'password_confirmation': 'qwe123',
             'email': '*****@*****.**',
             'firstname': 'test',
             'lastname': 'test'
         })
     msg = validators.ValidPasswordsMatch()._messages['password_mismatch']
     response.mustcontain(msg)
Ejemplo n.º 5
0
    class _PasswordChangeForm(formencode.Schema):
        allow_extra_fields = True
        filter_extra_fields = True

        current_password = v.ValidOldPassword(username)(not_empty=True)
        new_password = All(v.ValidPassword(),
                           v.UnicodeString(strip=False, min=6))
        new_password_confirmation = All(v.ValidPassword(),
                                        v.UnicodeString(strip=False, min=6))

        chained_validators = [
            v.ValidPasswordsMatch('new_password', 'new_password_confirmation')
        ]
def test_ValidPasswordsMatch():
    validator = v.ValidPasswordsMatch()
    pytest.raises(
        formencode.Invalid,
        validator.to_python, {'password': '******',
                              'password_confirmation': 'pass2'})

    pytest.raises(
        formencode.Invalid,
        validator.to_python, {'new_password': '******',
                              'password_confirmation': 'pass2'})

    assert {'new_password': '******', 'password_confirmation': 'pass'} == \
        validator.to_python({'new_password': '******',
                             'password_confirmation': 'pass'})

    assert {'password': '******', 'password_confirmation': 'pass'} == \
        validator.to_python({'password': '******',
                             'password_confirmation': 'pass'})