Example #1
0
File: svn_fs.py Project: t2y/trac
 def setUp(self):
     self.env = EnvironmentStub()
     repositories = self.env.config['repositories']
     dbprovider = DbRepositoryProvider(self.env)
     dbprovider.add_repository(REPOS_NAME, self.path, 'direct-svnfs')
     dbprovider.modify_repository(REPOS_NAME, {'url': URL})
     self.repos = self.env.get_repository(REPOS_NAME)
Example #2
0
File: svn_fs.py Project: t2y/trac
 def setUp(self):
     self.env = EnvironmentStub()
     dbprovider = DbRepositoryProvider(self.env)
     dbprovider.add_repository(REPOS_NAME, self.path, 'svn')
     dbprovider.modify_repository(REPOS_NAME, {'url': URL})
     self.repos = self.env.get_repository(REPOS_NAME)
     self.repos.sync()
Example #3
0
 def test_node_in_hidden_default_repos(self):
     self.grant_perm('anonymous', 'BROWSER_VIEW', 'FILE_VIEW')
     provider = DbRepositoryProvider(self.env)
     provider.modify_repository('(default)', {'hidden': 'enabled'})
     req = MockRequest(self.env, path_info='/browser/blah-blah-file')
     template, data = self.process_request(req)
     self.assertEqual('', data['reponame'])
     self.assertEqual('blah-blah-file', data['path'])
Example #4
0
 def test_node_in_hidden_default_repos(self):
     self.grant_perm('anonymous', 'BROWSER_VIEW', 'FILE_VIEW')
     provider = DbRepositoryProvider(self.env)
     provider.modify_repository('(default)', {'hidden': 'enabled'})
     req = self.create_request(path_info='/browser/blah-blah-file')
     template, data, content_type = self.process_request(req)
     self.assertEqual('', data['reponame'])
     self.assertEqual('blah-blah-file', data['path'])
Example #5
0
 def test_repository_index_with_hidden_default_repos(self):
     self.grant_perm('anonymous', 'BROWSER_VIEW', 'FILE_VIEW')
     provider = DbRepositoryProvider(self.env)
     provider.modify_repository('(default)', {'hidden': 'enabled'})
     req = self.create_request(path_info='/browser/')
     template, data, content_type = self.process_request(req)
     self.assertEqual(None, data['repos'])
     repo_data = data['repo']  # for repository index
     self.assertEqual('allow', repo_data['repositories'][0][0])
     self.assertEqual('raise', repo_data['repositories'][1][0])
     self.assertEqual(2, len(repo_data['repositories']))
Example #6
0
 def test_repository_index_with_hidden_default_repos(self):
     self.grant_perm('anonymous', 'BROWSER_VIEW', 'FILE_VIEW')
     provider = DbRepositoryProvider(self.env)
     provider.modify_repository('(default)', {'hidden': 'enabled'})
     req = self.create_request(path_info='/browser/')
     template, data, content_type = self.process_request(req)
     self.assertEqual(None, data['repos'])
     repo_data = data['repo']  # for repository index
     self.assertEqual('allow', repo_data['repositories'][0][0])
     self.assertEqual('raise', repo_data['repositories'][1][0])
     self.assertEqual(2, len(repo_data['repositories']))
Example #7
0
def do_upgrade(env, version, cursor):
    """Replace list of repositories in [trac] repository_sync_per_request
    with boolean values [repositories] <repos>.sync_per_request and a list
    of repositories in [gitweb-repositories] sync_per_request. Move and
    rename the Gitweb configuration options from the [git] section to
    the [gitweb-repositories] section.
    """
    backup_config_file(env, '.db32.bak')
    repos_sync_per_request = \
        env.config.getlist('trac', 'repository_sync_per_request', '(default)')

    for suffix in ('base', 'list', 'url'):
        option_name = 'projects_' + suffix
        env.config.set('gitweb-repositories', option_name,
                       env.config.get('git', option_name))
        env.config.remove('git', option_name)
        env.log.info("Moved [git] %s -> [gitweb-repositories] %s", option_name,
                     option_name)

    rm = RepositoryManager(env)
    if repos_sync_per_request:
        for name, _ in rm.get_repositories():
            sync_per_request = (name or '(default)') in repos_sync_per_request
            if sync_per_request:
                env.config.set('repositories', name + '.sync_per_request',
                               'true')
                env.log.info("Enabled sync_per_request for %s", name)

        gwrp = GitwebProjectsRepositoryProvider(env)
        gitweb_repo_names = [name for name, _ in gwrp.get_repositories()]
        sync_per_request = \
            ', '.join(set(gitweb_repo_names) & set(repos_sync_per_request))
        env.config.set('gitweb-repositories', 'sync_per_request',
                       sync_per_request)
        env.log.info("Enabled sync_per_request for %s", sync_per_request)

        db_provider = DbRepositoryProvider(env)
        for name, _ in db_provider.get_repositories():
            sync_per_request = (name or '(default)') in repos_sync_per_request
            changes = {'sync_per_request': sync_per_request}
            db_provider.modify_repository(name, changes)
            if sync_per_request:
                env.log.info("Enabled sync_per_request for %s", name)

    env.config.remove('trac', 'repository_sync_per_request')
    env.log.info("Removed [trac] repository_sync_per_request option")
    env.config.save()
    rm.reload_repositories()
Example #8
0
class DbRepositoryProviderTestCase(unittest.TestCase):
    def setUp(self):
        self.env = EnvironmentStub()
        self.db_provider = DbRepositoryProvider(self.env)

    def tearDown(self):
        self.env.reset_db()

    def verify_raises(self, exc, message, func, *args, **kwargs):
        try:
            func(*args, **kwargs)
            self.fail('%s not raised' % exc.__name__)
        except exc as e:
            self.assertEqual(message, unicode(e))

    def do_remove(self, reponame, message):
        self.verify_raises(TracError, message,
                           self.db_provider.remove_repository, reponame)

    def do_modify(self, reponame, changes, message):
        self.verify_raises(TracError, message,
                           self.db_provider.modify_repository, reponame,
                           changes)

    def do_alias(self, reponame, target, message):
        self.verify_raises(TracError, message, self.db_provider.add_alias,
                           reponame, target)

    def test_add_alias(self):
        self.db_provider.add_repository('', '/path/to/repos')
        self.db_provider.add_repository('target', '/path/to/repos')
        self.db_provider.add_alias('blah1', '')
        self.db_provider.add_alias('blah2', '(default)')
        self.db_provider.add_alias('blah3', 'target')
        repositories = RepositoryManager(self.env).get_all_repositories()
        self.assertEqual(['', 'blah1', 'blah2', 'blah3', 'target'],
                         sorted(repositories))
        self.assertEqual('', repositories['blah1']['alias'])
        self.assertEqual('', repositories['blah2']['alias'])
        self.assertEqual('target', repositories['blah3']['alias'])

    def test_add_alias_to_non_existent_repository(self):
        self.do_alias('', '', 'Repository "(default)" doesn\'t exist')
        self.do_alias('', '(default)', 'Repository "(default)" doesn\'t exist')
        self.do_alias('blah', '', 'Repository "(default)" doesn\'t exist')
        self.do_alias('blah', '(default)',
                      'Repository "(default)" doesn\'t exist')
        self.do_alias('blah', 'blah', 'Repository "blah" doesn\'t exist')
        self.do_alias('', 'blah', 'Repository "blah" doesn\'t exist')
        self.do_alias('(default)', 'blah', 'Repository "blah" doesn\'t exist')

    def test_add_alias_to_repository_in_tracini(self):
        config = self.env.config
        config.set('repositories', '.dir', '/path/to/repos')
        config.set('repositories', '.type', '')
        config.set('repositories', 'target.dir', '/path/to/repos')
        config.set('repositories', 'target.type', '')
        config.set('repositories', 'alias-default.alias', '')
        config.set('repositories', 'alias-target.alias', 'target')
        self.db_provider.add_alias('blah1', '')
        self.db_provider.add_alias('blah2', 'target')
        self.assertRaises(TracError, self.db_provider.add_alias, 'blah3',
                          'notfound')
        repositories = RepositoryManager(self.env).get_all_repositories()
        self.assertEqual(
            ['', 'alias-default', 'alias-target', 'blah1', 'blah2', 'target'],
            sorted(repositories))
        self.assertEqual('', repositories['blah1']['alias'])
        self.assertEqual('target', repositories['blah2']['alias'])

    def test_add_alias_to_alias(self):
        config = self.env.config
        config.set('repositories', 'target.dir', '/path/to/repos')
        config.set('repositories', 'target.type', '')
        config.set('repositories', '.alias', 'target')
        config.set('repositories', 'alias.alias', 'target')
        self.do_alias('blah', '',
                      'Cannot create an alias to the alias "(default)"')
        self.do_alias('blah', '(default)',
                      'Cannot create an alias to the alias "(default)"')
        self.do_alias('blah', 'alias',
                      'Cannot create an alias to the alias "alias"')

    def test_remove_repository_used_in_aliases(self):
        self.db_provider.add_repository('', '/path/to/repos')
        self.db_provider.add_repository('blah', '/path/to/repos')
        self.db_provider.add_alias('alias-blah', 'blah')
        self.db_provider.add_alias('alias-default', '')
        self.do_remove(
            '', 'Cannot remove the repository "(default)" used in '
            'aliases')
        self.do_remove(
            '(default)', 'Cannot remove the repository "(default)" '
            'used in aliases')
        self.do_remove(
            'blah', 'Cannot remove the repository "blah" used in '
            'aliases')

    def test_modify_repository_used_in_aliases(self):
        self.db_provider.add_repository('', '/path/to/repos')
        self.db_provider.add_repository('blah', '/path/to/repos')
        self.db_provider.add_alias('alias-blah', 'blah')
        self.db_provider.add_alias('alias-default', '')
        self.do_modify(
            '', {'name': 'new-name'},
            'Cannot rename the repository "(default)" used in '
            'aliases')
        self.do_modify(
            '(default)', {'name': 'new-name'},
            'Cannot rename the repository "(default)" used in '
            'aliases')
        self.do_modify('blah', {'name': 'new-name'},
                       'Cannot rename the repository "blah" used in aliases')
        self.db_provider.modify_repository('', {'dir': '/path/to/new-path'})
Example #9
0
File: api.py Project: pkdevbox/trac
class DbRepositoryProviderTestCase(unittest.TestCase):

    def setUp(self):
        self.env = EnvironmentStub()
        self.db_provider = DbRepositoryProvider(self.env)

    def tearDown(self):
        self.env.reset_db()

    def verify_raises(self, exc, message, func, *args, **kwargs):
        try:
            func(*args, **kwargs)
            self.fail('%s not raised' % exc.__name__)
        except exc as e:
            self.assertEqual(message, unicode(e))

    def do_remove(self, reponame, message):
        self.verify_raises(TracError, message,
                           self.db_provider.remove_repository, reponame)

    def do_modify(self, reponame, changes, message):
        self.verify_raises(TracError, message,
                           self.db_provider.modify_repository, reponame,
                           changes)

    def do_alias(self, reponame, target, message):
        self.verify_raises(TracError, message, self.db_provider.add_alias,
                           reponame, target)

    def test_add_alias(self):
        self.db_provider.add_repository('', '/path/to/repos')
        self.db_provider.add_repository('target', '/path/to/repos')
        self.db_provider.add_alias('blah1', '')
        self.db_provider.add_alias('blah2', '(default)')
        self.db_provider.add_alias('blah3', 'target')
        repositories = RepositoryManager(self.env).get_all_repositories()
        self.assertEqual(['', 'blah1', 'blah2', 'blah3', 'target'],
                         sorted(repositories))
        self.assertEqual('', repositories['blah1']['alias'])
        self.assertEqual('', repositories['blah2']['alias'])
        self.assertEqual('target', repositories['blah3']['alias'])

    def test_add_alias_to_non_existent_repository(self):
        self.do_alias('', '',
                      'Repository "(default)" doesn\'t exist')
        self.do_alias('', '(default)',
                      'Repository "(default)" doesn\'t exist')
        self.do_alias('blah', '',
                      'Repository "(default)" doesn\'t exist')
        self.do_alias('blah', '(default)',
                      'Repository "(default)" doesn\'t exist')
        self.do_alias('blah', 'blah', 'Repository "blah" doesn\'t exist')
        self.do_alias('', 'blah', 'Repository "blah" doesn\'t exist')
        self.do_alias('(default)', 'blah', 'Repository "blah" doesn\'t exist')

    def test_add_alias_to_repository_in_tracini(self):
        config = self.env.config
        config.set('repositories', '.dir', '/path/to/repos')
        config.set('repositories', '.type', '')
        config.set('repositories', 'target.dir', '/path/to/repos')
        config.set('repositories', 'target.type', '')
        config.set('repositories', 'alias-default.alias', '')
        config.set('repositories', 'alias-target.alias', 'target')
        self.db_provider.add_alias('blah1', '')
        self.db_provider.add_alias('blah2', 'target')
        self.assertRaises(TracError, self.db_provider.add_alias, 'blah3',
                          'notfound')
        repositories = RepositoryManager(self.env).get_all_repositories()
        self.assertEqual(['', 'alias-default', 'alias-target', 'blah1',
                          'blah2', 'target'], sorted(repositories))
        self.assertEqual('', repositories['blah1']['alias'])
        self.assertEqual('target', repositories['blah2']['alias'])

    def test_add_alias_to_alias(self):
        config = self.env.config
        config.set('repositories', 'target.dir', '/path/to/repos')
        config.set('repositories', 'target.type', '')
        config.set('repositories', '.alias', 'target')
        config.set('repositories', 'alias.alias', 'target')
        self.do_alias('blah', '',
                      'Cannot create an alias to the alias "(default)"')
        self.do_alias('blah', '(default)',
                      'Cannot create an alias to the alias "(default)"')
        self.do_alias('blah', 'alias',
                      'Cannot create an alias to the alias "alias"')

    def test_remove_repository_used_in_aliases(self):
        self.db_provider.add_repository('', '/path/to/repos')
        self.db_provider.add_repository('blah', '/path/to/repos')
        self.db_provider.add_alias('alias-blah', 'blah')
        self.db_provider.add_alias('alias-default', '')
        self.do_remove('', 'Cannot remove the repository "(default)" used in '
                           'aliases')
        self.do_remove('(default)', 'Cannot remove the repository "(default)" '
                                    'used in aliases')
        self.do_remove('blah', 'Cannot remove the repository "blah" used in '
                               'aliases')

    def test_modify_repository_used_in_aliases(self):
        self.db_provider.add_repository('', '/path/to/repos')
        self.db_provider.add_repository('blah', '/path/to/repos')
        self.db_provider.add_alias('alias-blah', 'blah')
        self.db_provider.add_alias('alias-default', '')
        self.do_modify('', {'name': 'new-name'},
                       'Cannot rename the repository "(default)" used in '
                       'aliases')
        self.do_modify('(default)', {'name': 'new-name'},
                       'Cannot rename the repository "(default)" used in '
                       'aliases')
        self.do_modify('blah', {'name': 'new-name'},
                       'Cannot rename the repository "blah" used in aliases')
        self.db_provider.modify_repository('', {'dir': '/path/to/new-path'})