Changeset - 82ea8d67fc62
[Not reviewed]
default
0 5 0
Mads Kiilerich - 10 years ago 2015-07-23 00:52:29
madski@unity3d.com
validators: cleanup of message wording

NotReviewedRevisions was unused and could thus got the big cleanup ...
5 files changed with 19 insertions and 79 deletions:
0 comments (0 inline, 0 general)
kallithea/model/user.py
Show inline comments
 
@@ -252,14 +252,14 @@ class UserModel(BaseModel):
 
        if not cur_user:
 
            cur_user = getattr(get_current_authuser(), 'username', None)
 
        user = self._get_user(user)
 

	
 
        if user.username == User.DEFAULT_USER:
 
            raise DefaultUserException(
 
                _("You can't remove this user since it's"
 
                  " crucial for entire application"))
 
                _("You can't remove this user since it is"
 
                  " crucial for the entire application"))
 
        if user.repositories:
 
            repos = [x.repo_name for x in user.repositories]
 
            raise UserOwnsReposException(
 
                _('User "%s" still owns %s repositories and cannot be '
 
                  'removed. Switch owners or remove those repositories: %s')
 
                % (user.username, len(repos), ', '.join(repos)))
kallithea/model/validators.py
Show inline comments
 
@@ -92,17 +92,17 @@ def UniqueListFromString():
 

	
 
def ValidUsername(edit=False, old_data={}):
 
    class _validator(formencode.validators.FancyValidator):
 
        messages = {
 
            'username_exists': _('Username "%(username)s" already exists'),
 
            'system_invalid_username':
 
                _('Username "%(username)s" is forbidden'),
 
                _('Username "%(username)s" cannot be used'),
 
            'invalid_username':
 
                _('Username may only contain alphanumeric characters '
 
                    'underscores, periods or dashes and must begin with '
 
                    'alphanumeric character or underscore')
 
                  'underscores, periods or dashes and must begin with an '
 
                  'alphanumeric character or underscore')
 
        }
 

	
 
        def validate_python(self, value, state):
 
            if value in ['default', 'new_user']:
 
                msg = M(self, 'system_invalid_username', state, username=value)
 
                raise formencode.Invalid(msg, value, state)
 
@@ -297,15 +297,15 @@ def ValidPasswordsMatch(passwd='new_pass
 
    return _validator
 

	
 

	
 
def ValidAuth():
 
    class _validator(formencode.validators.FancyValidator):
 
        messages = {
 
            'invalid_password': _('invalid password'),
 
            'invalid_username': _('invalid user name'),
 
            'disabled_account': _('Your account is disabled')
 
            'invalid_password': _('Invalid password'),
 
            'invalid_username': _('Invalid username'),
 
            'disabled_account': _('Account has been disabled')
 
        }
 

	
 
        def validate_python(self, value, state):
 
            from kallithea.lib import auth_modules
 

	
 
            password = value['password']
 
@@ -343,13 +343,13 @@ def ValidAuthToken():
 

	
 

	
 
def ValidRepoName(edit=False, old_data={}):
 
    class _validator(formencode.validators.FancyValidator):
 
        messages = {
 
            'invalid_repo_name':
 
                _('Repository name %(repo)s is disallowed'),
 
                _('Repository name %(repo)s is not allowed'),
 
            'repository_exists':
 
                _('Repository named %(repo)s already exists'),
 
            'repository_in_group_exists': _('Repository "%(repo)s" already '
 
                                            'exists in group "%(group)s"'),
 
            'same_group_exists': _('Repository group with name "%(repo)s" '
 
                                   'already exists')
 
@@ -465,13 +465,13 @@ def ValidCloneUri():
 
                raise Exception('clone from URI %s not allowed' % (url))
 

	
 
    class _validator(formencode.validators.FancyValidator):
 
        messages = {
 
            'clone_uri': _('Invalid repository URL'),
 
            'invalid_clone_uri': _('Invalid repository URL. It must be a '
 
                                    'valid http, https, ssh, svn+http or svn+https URL'),
 
                                   'valid http, https, ssh, svn+http or svn+https URL'),
 
        }
 

	
 
        def validate_python(self, value, state):
 
            repo_type = value.get('repo_type')
 
            url = value.get('clone_uri')
 

	
 
@@ -703,13 +703,13 @@ def ValidPath():
 
    return _validator
 

	
 

	
 
def UniqSystemEmail(old_data={}):
 
    class _validator(formencode.validators.FancyValidator):
 
        messages = {
 
            'email_taken': _('This e-mail address is already taken')
 
            'email_taken': _('This e-mail address is already in use')
 
        }
 

	
 
        def _to_python(self, value, state):
 
            return value.lower()
 

	
 
        def validate_python(self, value, state):
 
@@ -723,13 +723,13 @@ def UniqSystemEmail(old_data={}):
 
    return _validator
 

	
 

	
 
def ValidSystemEmail():
 
    class _validator(formencode.validators.FancyValidator):
 
        messages = {
 
            'non_existing_email': _('e-mail "%(email)s" does not exist.')
 
            'non_existing_email': _('E-mail address "%(email)s" not found')
 
        }
 

	
 
        def _to_python(self, value, state):
 
            return value.lower()
 

	
 
        def validate_python(self, value, state):
 
@@ -769,45 +769,12 @@ def AttrLoginValidator():
 
        }
 
        messages['empty'] = messages['invalid_cn']
 

	
 
    return _validator
 

	
 

	
 
def NotReviewedRevisions(repo_id):
 
    class _validator(formencode.validators.FancyValidator):
 
        messages = {
 
            'rev_already_reviewed':
 
                  _('Revisions %(revs)s are already part of pull request '
 
                    'or have set status')
 
        }
 

	
 
        def validate_python(self, value, state):
 
            # check revisions if they are not reviewed, or a part of another
 
            # pull request
 
            statuses = ChangesetStatus.query()\
 
                .filter(ChangesetStatus.revision.in_(value))\
 
                .filter(ChangesetStatus.repo_id == repo_id)\
 
                .all()
 

	
 
            errors = []
 
            for cs in statuses:
 
                if cs.pull_request_id:
 
                    errors.append(['pull_req', cs.revision[:12]])
 
                elif cs.status:
 
                    errors.append(['status', cs.revision[:12]])
 

	
 
            if errors:
 
                revs = ','.join([x[1] for x in errors])
 
                msg = M(self, 'rev_already_reviewed', state, revs=revs)
 
                raise formencode.Invalid(msg, value, state,
 
                    error_dict=dict(revisions=revs)
 
                )
 

	
 
    return _validator
 

	
 

	
 
def ValidIp():
 
    class _validator(CIDR):
 
        messages = dict(
 
            badFormat=_('Please enter a valid IPv4 or IPv6 address'),
 
            illegalBits=_('The network size (bits) must be within the range'
 
                ' of 0-32 (not %(bits)r)')
kallithea/tests/functional/test_login.py
Show inline comments
 
@@ -126,14 +126,14 @@ class TestLoginController(TestController
 

	
 
    def test_login_wrong_username_password(self):
 
        response = self.app.post(url(controller='login', action='index'),
 
                                 {'username': 'error',
 
                                  'password': 'test12'})
 

	
 
        response.mustcontain('invalid user name')
 
        response.mustcontain('invalid password')
 
        response.mustcontain('Invalid username')
 
        response.mustcontain('Invalid password')
 

	
 
    # verify that get arguments are correctly passed along login redirection
 

	
 
    @parameterized.expand([
 
        ({'foo':'one', 'bar':'two'}, ('foo=one', 'bar=two')),
 
        ({'blue': u'blå'.encode('utf-8'), 'green':u'grøn'},
 
@@ -184,14 +184,14 @@ class TestLoginController(TestController
 
        response = self.app.post(url(controller='login', action='index',
 
                                     came_from = '/_admin/users',
 
                                     **args),
 
                                 {'username': 'error',
 
                                  'password': 'test12'})
 

	
 
        response.mustcontain('invalid user name')
 
        response.mustcontain('invalid password')
 
        response.mustcontain('Invalid username')
 
        response.mustcontain('Invalid password')
 
        for encoded in args_encoded:
 
            self.assertIn(encoded, response.form.action)
 

	
 
    #==========================================================================
 
    # REGISTRATIONS
 
    #==========================================================================
 
@@ -257,13 +257,13 @@ class TestLoginController(TestController
 
                                             'firstname': 'test',
 
                                             'lastname': 'test'})
 

	
 
        response.mustcontain('An email address must contain a single @')
 
        response.mustcontain('Username may only contain '
 
                'alphanumeric characters underscores, '
 
                'periods or dashes and must begin with '
 
                'periods or dashes and must begin with an '
 
                'alphanumeric character')
 

	
 
    def test_register_err_case_sensitive(self):
 
        usr = TEST_USER_ADMIN_LOGIN.title()
 
        response = self.app.post(url(controller='login', action='register'),
 
                                            {'username': usr,
kallithea/tests/functional/test_my_account.py
Show inline comments
 
@@ -48,13 +48,13 @@ class TestMyAccountController(TestContro
 
    def test_my_account_my_emails_add_existing_email(self):
 
        self.log_user()
 
        response = self.app.get(url('my_account_emails'))
 
        response.mustcontain('No additional emails specified')
 
        response = self.app.post(url('my_account_emails'),
 
                                 {'new_email': TEST_USER_REGULAR_EMAIL, '_authentication_token': self.authentication_token()})
 
        self.checkSessionFlash(response, 'This e-mail address is already taken')
 
        self.checkSessionFlash(response, 'This e-mail address is already in use')
 

	
 
    def test_my_account_my_emails_add_mising_email_in_form(self):
 
        self.log_user()
 
        response = self.app.get(url('my_account_emails'))
 
        response.mustcontain('No additional emails specified')
 
        response = self.app.post(url('my_account_emails'),)
 
@@ -158,13 +158,13 @@ class TestMyAccountController(TestContro
 
                                    firstname='NewName',
 
                                    lastname='NewLastname',
 
                                    email=new_email,
 
                                    _authentication_token=self.authentication_token())
 
                                )
 

	
 
        response.mustcontain('This e-mail address is already taken')
 
        response.mustcontain('This e-mail address is already in use')
 

	
 
    def test_my_account_update_err(self):
 
        self.log_user(TEST_USER_REGULAR2_LOGIN, TEST_USER_REGULAR2_PASS)
 

	
 
        new_email = 'newmail.pl'
 
        response = self.app.post(url('my_account'),
kallithea/tests/other/test_validators.py
Show inline comments
 
@@ -228,33 +228,6 @@ class TestRepoGroups(BaseTestCase):
 
            validator = v.LdapLibValidator()
 
            self.assertRaises(v.LdapImportError, validator.to_python, 'err')
 

	
 
    def test_AttrLoginValidator(self):
 
        validator = v.AttrLoginValidator()
 
        self.assertEqual('DN_attr', validator.to_python('DN_attr'))
 

	
 
    def test_NotReviewedRevisions(self):
 
        user = ChangesetStatusModel()._get_user(TEST_USER_ADMIN_LOGIN)
 
        repo = Repository.get_by_repo_name(HG_REPO)
 
        validator = v.NotReviewedRevisions(repo.repo_id)
 
        rev = '0' * 40
 
        # add status for a rev, that should throw an error because it is already
 
        # reviewed
 
        new_comment = ChangesetComment()
 
        new_comment.repo = repo
 
        new_comment.author = user
 
        new_comment.text = u''
 
        Session().add(new_comment)
 
        Session().flush()
 
        new_status = ChangesetStatus()
 
        new_status.author = user
 
        new_status.repo = repo
 
        new_status.status = ChangesetStatus.STATUS_APPROVED
 
        new_status.comment = new_comment
 
        new_status.revision = rev
 
        Session().add(new_status)
 
        Session().commit()
 
        try:
 
            self.assertRaises(formencode.Invalid, validator.to_python, [rev])
 
        finally:
 
            Session().delete(new_status)
 
            Session().commit()
0 comments (0 inline, 0 general)