Ejemplo n.º 1
0
    def test_panel_not_exists_when_no_repository_connectors(self):
        """Repositories admin panel is not present when there are
        no repository connectors enabled.
        """
        req = MockRequest(self.env)
        rap = RepositoryAdminPanel(self.env)
        panels = [panel for panel in rap.get_admin_panels(req)]

        self.assertEqual(0, len(panels))
Ejemplo n.º 2
0
    def test_panel_exists_when_repository_connectors(self):
        """Repositories admin panel is present when there are
        repository connectors enabled.
        """
        self.env.enable_component(self.RepositoryConnector)
        req = MockRequest(self.env)
        rap = RepositoryAdminPanel(self.env)
        panels = [panel for panel in rap.get_admin_panels(req)]

        self.assertEqual(1, len(panels))
Ejemplo n.º 3
0
 def test_render_admin_with_alias_to_default_repos(self):
     db_provider = DbRepositoryProvider(self.env)
     db_provider.add_alias('', '')
     db_provider.add_alias('blah', '')
     panel = RepositoryAdminPanel(self.env)
     req = Mock(method='GET', chrome={}, args={}, session={},
                abs_href=Href('/'), href=Href('/'), locale=None,
                perm=MockPerm(), authname='anonymous', tz=utc)
     template, data = panel.render_admin_panel(req, 'versioncontrol',
                                               'repository', '')
     repositories = data['repositories']
     self.assertEqual('', repositories['']['name'])
     self.assertEqual('', repositories['']['alias'])
     self.assertEqual('blah', repositories['blah']['name'])
     self.assertEqual('', repositories['blah']['alias'])
Ejemplo n.º 4
0
    def _do_create(self, name, type, owner, dir=None):
        rm = RepositoryManager(self.env)
        base_directory = rm.get_base_directory(type)
        directory = os.path.join(base_directory, dir or name)

        if os.path.lexists(directory):
            raise AdminCommandError(
                _('Directory "%(name)s" already exists', name=directory))

        rap = RepositoryAdminPanel(self.env)
        prefixes = [
            os.path.join(self.env.path, prefix)
            for prefix in rap.allowed_repository_dir_prefixes
        ]
        if prefixes and not any(
                is_path_below(directory, prefix) for prefix in prefixes):
            add_warning(
                req,
                _(
                    "The repository directory must be located "
                    "below one of the following directories: "
                    "%(dirs)s",
                    dirs=', '.join(prefixes)))

            if rm.get_repository(name):
                raise AdminCommandError(
                    _('Repository "%(name)s" already '
                      'exists', name=name))
        repo = {'name': name, 'type': type, 'owner': owner, 'dir': directory}
        rm.create(repo)
Ejemplo n.º 5
0
    def test_render_admin_with_alias_to_default_repos(self):
        with self.env.db_transaction as db:
            # Add aliases to non-existent default repository
            db.executemany(
                "INSERT INTO repository (id, name, value) VALUES (%s, %s, %s)",
                [(1, 'name', ''), (1, 'dir', None), (1, 'alias', ''),
                 (2, 'name', 'blah'), (2, 'dir', None), (2, 'alias', '')])

        panel = RepositoryAdminPanel(self.env)
        req = MockRequest(self.env)
        template, data = panel.render_admin_panel(req, 'versioncontrol',
                                                  'repository', '')
        repositories = data['repositories']
        self.assertNotEqual({}, repositories)
        self.assertEqual('', repositories['']['name'])
        self.assertEqual('', repositories['']['alias'])
        self.assertEqual('blah', repositories['blah']['name'])
        self.assertEqual('', repositories['blah']['alias'])
Ejemplo n.º 6
0
    def test_panel_exists_when_repository_connectors(self):
        """Repositories admin panel is present when there are
        repository connectors enabled.
        """
        class RepositoryConnector(Component):
            implements(IRepositoryConnector)

            def get_supported_types(self):
                yield 'RepositoryConnector', 1

            def get_repository(self, repos_type, repos_dir, params):
                pass

        req = MockRequest(self.env)
        rap = RepositoryAdminPanel(self.env)
        panels = [panel for panel in rap.get_admin_panels(req)]

        self.assertEqual(1, len(panels))
Ejemplo n.º 7
0
    def test_render_admin_with_alias_to_default_repos(self):
        with self.env.db_transaction as db:
            # Add aliases to non-existent default repository
            db.executemany(
                "INSERT INTO repository (id, name, value) VALUES (%s, %s, %s)",
                [(1, 'name', ''),     (1, 'dir', None), (1, 'alias', ''),
                 (2, 'name', 'blah'), (2, 'dir', None), (2, 'alias', '')])

        panel = RepositoryAdminPanel(self.env)
        req = Mock(method='GET', chrome={}, args={}, session={},
                   abs_href=Href('/'), href=Href('/'), locale=None,
                   perm=MockPerm(), authname='anonymous', tz=utc)
        template, data = panel.render_admin_panel(req, 'versioncontrol',
                                                  'repository', '')
        repositories = data['repositories']
        self.assertNotEqual({}, repositories)
        self.assertEqual('', repositories['']['name'])
        self.assertEqual('', repositories['']['alias'])
        self.assertEqual('blah', repositories['blah']['name'])
        self.assertEqual('', repositories['blah']['alias'])
Ejemplo n.º 8
0
 def test_render_admin_with_alias_to_default_repos(self):
     db_provider = DbRepositoryProvider(self.env)
     db_provider.add_alias('', '')
     db_provider.add_alias('blah', '')
     panel = RepositoryAdminPanel(self.env)
     req = Mock(method='GET',
                chrome={},
                args={},
                session={},
                abs_href=Href('/'),
                href=Href('/'),
                locale=None,
                perm=MockPerm(),
                authname='anonymous',
                tz=utc)
     template, data = panel.render_admin_panel(req, 'versioncontrol',
                                               'repository', '')
     repositories = data['repositories']
     self.assertEqual('', repositories['']['name'])
     self.assertEqual('', repositories['']['alias'])
     self.assertEqual('blah', repositories['blah']['name'])
     self.assertEqual('', repositories['blah']['alias'])
Ejemplo n.º 9
0
    def _check_and_update_repository(self, req, repo, old_repo=None):
        """Check if a repository is valid, does not already exist,
        update the dict and add a warning message otherwise.
        """
        if not repo['dir']:
            add_warning(req, _("The directory is missing."))
            return False

        rm = RepositoryManager(self.env)
        base_directory = rm.get_base_directory(repo['type'])
        directory = os.path.join(base_directory, repo['dir'])

        if not old_repo or old_repo.directory != directory:
            if os.path.lexists(directory):
                add_warning(req, _('Directory "%(name)s" already exists',
                                   name=directory))
                return False

        rap = RepositoryAdminPanel(self.env)
        prefixes = [os.path.join(self.env.path, prefix)
                    for prefix in rap.allowed_repository_dir_prefixes]
        if prefixes and not any(is_path_below(directory, prefix)
                                for prefix in prefixes):
            add_warning(req, _("The repository directory must be located "
                               "below one of the following directories: "
                               "%(dirs)s", dirs=', '.join(prefixes)))
            return False

        if not old_repo or old_repo.reponame != repo['name']:
            if rm.get_repository(repo['name']):
                add_warning(req, _('Repository "%(name)s" already exists',
                                   name=repo['name']))
                return False

        repo.update({'dir': directory})
        return True