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 17 insertions and 77 deletions:
0 comments (0 inline, 0 general)
kallithea/model/user.py
Show inline comments
 
@@ -255,8 +255,8 @@ class UserModel(BaseModel):
 

	
 
        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(
kallithea/model/validators.py
Show inline comments
 
@@ -95,10 +95,10 @@ def ValidUsername(edit=False, old_data={
 
        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 '
 
                  'underscores, periods or dashes and must begin with an '
 
                    'alphanumeric character or underscore')
 
        }
 

	
 
@@ -300,9 +300,9 @@ def ValidPasswordsMatch(passwd='new_pass
 
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):
 
@@ -346,7 +346,7 @@ 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 '
 
@@ -706,7 +706,7 @@ def ValidPath():
 
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):
 
@@ -726,7 +726,7 @@ def UniqSystemEmail(old_data={}):
 
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):
 
@@ -772,39 +772,6 @@ def AttrLoginValidator():
 
    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(
kallithea/tests/functional/test_login.py
Show inline comments
 
@@ -129,8 +129,8 @@ class TestLoginController(TestController
 
                                 {'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
 

	
 
@@ -187,8 +187,8 @@ class TestLoginController(TestController
 
                                 {'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)
 

	
 
@@ -260,7 +260,7 @@ class TestLoginController(TestController
 
        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):
kallithea/tests/functional/test_my_account.py
Show inline comments
 
@@ -51,7 +51,7 @@ class TestMyAccountController(TestContro
 
        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()
 
@@ -161,7 +161,7 @@ class TestMyAccountController(TestContro
 
                                    _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)
kallithea/tests/other/test_validators.py
Show inline comments
 
@@ -231,30 +231,3 @@ class TestRepoGroups(BaseTestCase):
 
    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)