def test_ValidRepoGroup(self):
        validator = v.ValidRepoGroup()
        model = RepoGroupModel()
        with pytest.raises(formencode.Invalid):
            validator.to_python({
                'group_name': base.HG_REPO,
            })
        gr = model.create(group_name='test_gr',
                          group_description='desc',
                          parent=None,
                          just_db=True,
                          owner=base.TEST_USER_ADMIN_LOGIN)
        with pytest.raises(formencode.Invalid):
            validator.to_python({
                'group_name': gr.group_name,
            })

        validator = v.ValidRepoGroup(edit=True,
                                     old_data={'group_id': gr.group_id})
        with pytest.raises(formencode.Invalid):
            validator.to_python({
                'group_name': gr.group_name + 'n',
                'parent_group_id': gr.group_id
            })
        model.delete(gr)
Exemple #2
0
    class _RepoGroupForm(formencode.Schema):
        allow_extra_fields = True
        filter_extra_fields = False

        group_name = All(
            v.UnicodeString(strip=True, min=1, not_empty=True),
            v.SlugifyName(),
            v.ValidRegex(
                msg=_('Name must not contain only digits'))(r'(?!^\d+$)^.+$'))
        group_description = v.UnicodeString(strip=True, min=1, not_empty=False)
        group_copy_permissions = v.StringBoolean(if_missing=False)

        if edit:
            #FIXME: do a special check that we cannot move a group to one of
            #its children
            pass

        parent_group_id = All(
            v.CanCreateGroup(can_create_in_root),
            v.OneOf(repo_group_ids,
                    hideList=False,
                    testValueList=True,
                    if_missing=None,
                    not_empty=True), v.Int(min=-1, not_empty=True))
        enable_locking = v.StringBoolean(if_missing=False)
        chained_validators = [v.ValidRepoGroup(edit, old_data)]
Exemple #3
0
    def test_ValidRepoGroup(self):
        validator = v.ValidRepoGroup()
        model = RepoGroupModel()
        self.assertRaises(formencode.Invalid, validator.to_python,
                          {'group_name': HG_REPO, })
        gr = model.create(group_name='test_gr', group_description='desc',
                          parent=None,
                          just_db=True,
                          owner=TEST_USER_ADMIN_LOGIN)
        self.assertRaises(formencode.Invalid,
                          validator.to_python, {'group_name': gr.group_name, })

        validator = v.ValidRepoGroup(edit=True,
                                      old_data={'group_id':  gr.group_id})
        self.assertRaises(formencode.Invalid,
                          validator.to_python, {
                                        'group_name': gr.group_name + 'n',
                                        'group_parent_id': gr.group_id
                                        })
        model.delete(gr)