Esempio n. 1
0
    def test_update_group_parent(self):

        sg1 = self.__make_group('initial', parent_id=self.g1.group_id)

        new_sg1 = self.__update_group(sg1.group_id, 'after', parent_id=self.g1.group_id)
        self.assertTrue(self.__check_path('test1', 'after'))
        self.assertEqual(Group.get_by_group_name('test1/initial'), None)


        new_sg1 = self.__update_group(sg1.group_id, 'after', parent_id=self.g3.group_id)
        self.assertTrue(self.__check_path('test3', 'after'))
        self.assertEqual(Group.get_by_group_name('test3/initial'), None)


        new_sg1 = self.__update_group(sg1.group_id, 'hello')
        self.assertTrue(self.__check_path('hello'))

        self.assertEqual(Group.get_by_group_name('hello'), new_sg1)
Esempio n. 2
0
    def __make_group(self, path, desc='desc', parent_id=None,
                     skip_if_exists=False):

        gr = Group.get_by_group_name(path)
        if gr and skip_if_exists:
            return gr

        form_data = dict(group_name=path,
                         group_description=desc,
                         group_parent_id=parent_id)
        gr = ReposGroupModel().create(form_data)
        return gr
Esempio n. 3
0
        def to_python(self, value, state):

            repo_name = value.get('repo_name')

            slug = repo_name_slug(repo_name)
            if slug in [ADMIN_PREFIX, '']:
                e_dict = {'repo_name': _('This repository name is disallowed')}
                raise formencode.Invalid('', value, state, error_dict=e_dict)


            if value.get('repo_group'):
                gr = Group.get(value.get('repo_group'))
                group_path = gr.full_path
                # value needs to be aware of group name in order to check
                # db key This is an actual just the name to store in the
                # database
                repo_name_full = group_path + Group.url_sep() + repo_name
                
            else:
                group_path = ''
                repo_name_full = repo_name


            value['repo_name_full'] = repo_name_full
            rename = old_data.get('repo_name') != repo_name_full
            create = not edit
            if  rename or create:

                if group_path != '':
                    if RepoModel().get_by_repo_name(repo_name_full,):
                        e_dict = {'repo_name':_('This repository already '
                                                'exists in a group "%s"') %
                                  gr.group_name}
                        raise formencode.Invalid('', value, state,
                                                 error_dict=e_dict)
                elif Group.get_by_group_name(repo_name_full):
                        e_dict = {'repo_name':_('There is a group with this'
                                                ' name already "%s"') %
                                  repo_name_full}
                        raise formencode.Invalid('', value, state,
                                                 error_dict=e_dict)

                elif RepoModel().get_by_repo_name(repo_name_full):
                        e_dict = {'repo_name':_('This repository '
                                                'already exists')}
                        raise formencode.Invalid('', value, state,
                                                 error_dict=e_dict)

            return value
Esempio n. 4
0
    def create_repo(self, apiuser, name, owner_name, description='', 
                    repo_type='hg', private=False):
        """
        Create a repository

        :param apiuser
        :param name
        :param description
        :param type
        :param private
        :param owner_name
        """

        try:
            try:
                owner = User.get_by_username(owner_name)
            except NoResultFound:
                raise JSONRPCError('unknown user %s' % owner)

            if self.get_repo(apiuser, name):
                raise JSONRPCError("repo %s already exist" % name)

            groups = name.split('/')
            real_name = groups[-1]
            groups = groups[:-1]
            parent_id = None
            for g in groups:
                group = Group.get_by_group_name(g)
                if not group:
                    group = ReposGroupModel().create(dict(group_name=g,
                                                  group_description='',
                                                  group_parent_id=parent_id))
                parent_id = group.group_id

            RepoModel().create(dict(repo_name=real_name,
                                     repo_name_full=name,
                                     description=description,
                                     private=private,
                                     repo_type=repo_type,
                                     repo_group=parent_id,
                                     clone_uri=None), owner)
        except Exception:
            log.error(traceback.format_exc())
            raise JSONRPCError('failed to create repository %s' % name)
Esempio n. 5
0
    def test_rename_single_group(self):
        sg1 = self.__make_group('initial')

        new_sg1 = self.__update_group(sg1.group_id, 'after')
        self.assertTrue(self.__check_path('after'))
        self.assertEqual(Group.get_by_group_name('initial'), None)
Esempio n. 6
0
 def show_by_name(self, group_name):
     id_ = Group.get_by_group_name(group_name).group_id
     return self.show(id_)