Example #1
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)
            chained_validators = [
                v.ValidPasswordsMatch('new_password', 'password_confirmation')
            ]
        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))
            chained_validators = [
                v.ValidPasswordsMatch('password', 'password_confirmation')
            ]

        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, if_missing=None)
        extern_type = v.UnicodeString(strip=True, if_missing=None)
Example #2
0
    def test_UniqSystemEmail(self):
        validator = v.UniqSystemEmail(old_data={})

        assert '*****@*****.**' == validator.to_python('*****@*****.**')

        email = base.TEST_USER_REGULAR2_EMAIL
        with pytest.raises(formencode.Invalid):
            validator.to_python(email)
Example #3
0
    def test_UniqSystemEmail(self):
        validator = v.UniqSystemEmail(old_data={})

        self.assertEqual('*****@*****.**',
                         validator.to_python('*****@*****.**'))

        email = TEST_USER_REGULAR2_EMAIL
        self.assertRaises(formencode.Invalid, validator.to_python, email)
Example #4
0
 def test_register_err_same_email_case_sensitive(self):
     response = self.app.post(
         url(controller='login', action='register'), {
             'username': '******',
             'password': '******',
             'password_confirmation': 'test12',
             'email': '*****@*****.**',
             'firstname': 'test',
             'lastname': 'test'
         })
     msg = validators.UniqSystemEmail()()._messages['email_taken']
     response.mustcontain(msg)
Example #5
0
 def test_register_err_same_email_case_sensitive(self):
     response = self.app.post(base.url(controller='login', action='register'),
                                         {'username': '******',
                                          'password': '******',
                                          'password_confirmation': 'test12',
                                          'email': base.TEST_USER_ADMIN_EMAIL.title(),
                                          'firstname': 'test',
                                          'lastname': 'test',
                                          '_session_csrf_secret_token': self.session_csrf_secret_token()})
     with test_context(self.app):
         msg = validators.UniqSystemEmail()()._messages['email_taken']
     response.mustcontain(msg)
Example #6
0
    def test_register_err_same_email(self):
        response = self.app.post(
            url(controller='login', action='register'), {
                'username': '******',
                'password': '******',
                'password_confirmation': 'test12',
                'email': TEST_USER_ADMIN_EMAIL,
                'firstname': 'test',
                'lastname': 'test'
            })

        with test_context(self.app):
            msg = validators.UniqSystemEmail()()._messages['email_taken']
        response.mustcontain(msg)
Example #7
0
 class _UserExtraEmailForm(formencode.Schema):
     email = All(v.UniqSystemEmail(), v.Email(not_empty=True))