コード例 #1
0
ファイル: __init__.py プロジェクト: fkalinski/git-review
 def _simple_change(self, change_text, commit_message, file_=None):
     """Helper method to create small changes and commit them."""
     if file_ is None:
         file_ = self._dir('test', 'test_file.txt')
     utils.write_to_file(file_, change_text.encode())
     self._run_git('add', file_)
     self._run_git('commit', '-m', commit_message)
コード例 #2
0
    def _configure_ssh(self, ssh_addr, ssh_port):
        """Setup ssh and scp to run with special options."""

        os.mkdir(self.ssh_dir)

        ssh_key = utils.run_cmd('ssh-keyscan', '-p', str(ssh_port), ssh_addr)
        utils.write_to_file(self._dir('ssh', 'known_hosts'), ssh_key.encode())
        self.addCleanup(os.remove, self._dir('ssh', 'known_hosts'))

        # Attach known_hosts to test results if anything fails
        self.attach_on_exception(self._dir('ssh', 'known_hosts'))

        for cmd in ('ssh', 'scp'):
            cmd_file = self._dir('ssh', cmd)
            s = '#!/bin/sh\n' \
                '/usr/bin/%s -i %s -o UserKnownHostsFile=%s ' \
                '-o IdentitiesOnly=yes ' \
                '-o PasswordAuthentication=no $@' % \
                (cmd,
                 self._dir('gsite', 'test_ssh_key'),
                 self._dir('ssh', 'known_hosts'))
            utils.write_to_file(cmd_file, s.encode())
            os.chmod(cmd_file, os.stat(cmd_file).st_mode | stat.S_IEXEC)

        os.environ['PATH'] = self.ssh_dir + os.pathsep + os.environ['PATH']
        os.environ['GIT_SSH'] = self._dir('ssh', 'ssh')
コード例 #3
0
ファイル: __init__.py プロジェクト: jcarlosgdl/git-review
 def _simple_change(self, change_text, commit_message, file_=None):
     """Helper method to create small changes and commit them."""
     if file_ is None:
         file_ = self._dir("test", "test_file.txt")
     utils.write_to_file(file_, change_text.encode())
     self._run_git("add", file_)
     self._run_git("commit", "-m", commit_message)
コード例 #4
0
ファイル: __init__.py プロジェクト: jcarlosgdl/git-review
 def _create_gitreview_file(self):
     cfg = "[gerrit]\n" "scheme=%s\n" "host=%s\n" "port=%s\n" "project=test/test_project.git"
     parsed = urlparse(self.project_uri)
     host_port = parsed.netloc.rpartition("@")[-1]
     host, __, port = host_port.partition(":")
     cfg %= parsed.scheme, host, port
     utils.write_to_file(self._dir("test", ".gitreview"), cfg.encode())
コード例 #5
0
ファイル: __init__.py プロジェクト: h4ck3rm1k3/git-review-old
    def _configure_ssh(self, ssh_addr, ssh_port):
        """Setup ssh and scp to run with special options."""

        os.mkdir(self.ssh_dir)

        ssh_key = utils.run_cmd('ssh-keyscan', '-p', str(ssh_port), ssh_addr)
        utils.write_to_file(self._dir('ssh', 'known_hosts'), ssh_key.encode())
        self.addCleanup(os.remove, self._dir('ssh', 'known_hosts'))

        # Attach known_hosts to test results if anything fails
        @self.addOnException
        def add_known_hosts(exc_info):
            known_hosts = self._dir('ssh', 'known_hosts')
            if os.path.exists(known_hosts):
                content.attach_file(self, known_hosts)
            else:
                self.addDetail('known_hosts',
                               content.text_content('Not found'))

        for cmd in ('ssh', 'scp'):
            cmd_file = self._dir('ssh', cmd)
            s = '#!/bin/sh\n' \
                '/usr/bin/%s -i %s -o UserKnownHostsFile=%s $@' % \
                (cmd,
                 self._dir('gsite', 'test_ssh_key'),
                 self._dir('ssh', 'known_hosts'))
            utils.write_to_file(cmd_file, s.encode())
            os.chmod(cmd_file, os.stat(cmd_file).st_mode | stat.S_IEXEC)

        os.environ['PATH'] = self.ssh_dir + os.pathsep + os.environ['PATH']
        os.environ['GIT_SSH'] = self._dir('ssh', 'ssh')
コード例 #6
0
ファイル: __init__.py プロジェクト: germaino/git-review
    def _configure_ssh(self, ssh_addr, ssh_port):
        """Setup ssh and scp to run with special options."""

        os.mkdir(self.ssh_dir)

        ssh_key = utils.run_cmd("ssh-keyscan", "-p", str(ssh_port), ssh_addr)
        utils.write_to_file(self._dir("ssh", "known_hosts"), ssh_key.encode())
        self.addCleanup(os.remove, self._dir("ssh", "known_hosts"))

        # Attach known_hosts to test results if anything fails
        self.attach_on_exception(self._dir("ssh", "known_hosts"))

        for cmd in ("ssh", "scp"):
            cmd_file = self._dir("ssh", cmd)
            s = (
                "#!/bin/sh\n"
                "/usr/bin/%s -i %s -o UserKnownHostsFile=%s "
                "-o IdentitiesOnly=yes "
                "-o PasswordAuthentication=no $@"
                % (cmd, self._dir("gsite", "test_ssh_key"), self._dir("ssh", "known_hosts"))
            )
            utils.write_to_file(cmd_file, s.encode())
            os.chmod(cmd_file, os.stat(cmd_file).st_mode | stat.S_IEXEC)

        os.environ["PATH"] = self.ssh_dir + os.pathsep + os.environ["PATH"]
        os.environ["GIT_SSH"] = self._dir("ssh", "ssh")
コード例 #7
0
ファイル: __init__.py プロジェクト: fkalinski/git-review
    def _configure_ssh(self, ssh_addr, ssh_port):
        """Setup ssh and scp to run with special options."""

        os.mkdir(self.ssh_dir)

        ssh_key = utils.run_cmd('ssh-keyscan', '-p', str(ssh_port), ssh_addr)
        utils.write_to_file(self._dir('ssh', 'known_hosts'), ssh_key.encode())
        self.addCleanup(os.remove, self._dir('ssh', 'known_hosts'))

        # Attach known_hosts to test results if anything fails
        self.attach_on_exception(self._dir('ssh', 'known_hosts'))

        for cmd in ('ssh', 'scp'):
            cmd_file = self._dir('ssh', cmd)
            s = '#!/bin/sh\n' \
                '/usr/bin/%s -i %s -o UserKnownHostsFile=%s ' \
                '-o IdentitiesOnly=yes ' \
                '-o PasswordAuthentication=no $@' % \
                (cmd,
                 self._dir('gsite', 'test_ssh_key'),
                 self._dir('ssh', 'known_hosts'))
            utils.write_to_file(cmd_file, s.encode())
            os.chmod(cmd_file, os.stat(cmd_file).st_mode | stat.S_IEXEC)

        os.environ['PATH'] = self.ssh_dir + os.pathsep + os.environ['PATH']
        os.environ['GIT_SSH'] = self._dir('ssh', 'ssh')
コード例 #8
0
ファイル: __init__.py プロジェクト: h4ck3rm1k3/git-review-old
 def _simple_change(self, change_text, commit_message,
                    file_=None):
     """Helper method to create small changes and commit them."""
     if file_ is None:
         file_ = self._dir('test', 'test_file.txt')
     utils.write_to_file(file_, change_text.encode())
     self._run_git('add', file_)
     self._run_git('commit', '-m', commit_message)
コード例 #9
0
ファイル: __init__.py プロジェクト: germaino/git-review
 def _create_gitreview_file(self, **kwargs):
     cfg = "[gerrit]\n" "scheme=%s\n" "host=%s\n" "port=%s\n" "project=test/test_project.git\n" "%s"
     parsed = urlparse(self.project_uri)
     host_port = parsed.netloc.rpartition("@")[-1]
     host, __, port = host_port.partition(":")
     extra = "\n".join("%s=%s" % kv for kv in kwargs.items())
     cfg %= parsed.scheme, host, port, extra
     utils.write_to_file(self._dir("test", ".gitreview"), cfg.encode())
コード例 #10
0
ファイル: __init__.py プロジェクト: fkalinski/git-review
 def _simple_amend(self, change_text, file_=None):
     """Helper method to amend existing commit with change."""
     if file_ is None:
         file_ = self._dir('test', 'test_file_new.txt')
     utils.write_to_file(file_, change_text.encode())
     self._run_git('add', file_)
     # cannot use --no-edit because it does not exist in older git
     message = self._run_git('log', '-1', '--format=%s\n\n%b')
     self._run_git('commit', '--amend', '-m', message)
コード例 #11
0
ファイル: __init__.py プロジェクト: germaino/git-review
 def _simple_amend(self, change_text, file_=None):
     """Helper method to amend existing commit with change."""
     if file_ is None:
         file_ = self._dir("test", "test_file_new.txt")
     utils.write_to_file(file_, change_text.encode())
     self._run_git("add", file_)
     # cannot use --no-edit because it does not exist in older git
     message = self._run_git("log", "-1", "--format=%s\n\n%b")
     self._run_git("commit", "--amend", "-m", message)
コード例 #12
0
ファイル: __init__.py プロジェクト: trishika/git-review
    def setUp(self):
        """Configure testing environment.

        Prepare directory for the testing and clone test Git repository.
        Require Gerrit war file in the .gerrit directory to run Gerrit local.
        """
        super(BaseGitReviewTestCase, self).setUp()
        self.useFixture(fixtures.Timeout(2 * 60, True))
        BaseGitReviewTestCase._test_counter += 1

        # ensures git-review command runs in local mode (for functional tests)
        self.useFixture(
            fixtures.EnvironmentVariable('GITREVIEW_LOCAL_MODE', ''))

        self.init_dirs()
        ssh_addr, ssh_port, http_addr, http_port, self.site_dir = \
            self._pick_gerrit_port_and_dir()
        self.gerrit_host, self.gerrit_port = ssh_addr, ssh_port

        self.test_dir = self._dir('site', 'tmp', 'test_project')
        self.ssh_dir = self._dir('site', 'tmp', 'ssh')
        self.project_ssh_uri = (
            'ssh://test_user@%s:%s/test/test_project.git' % (
                ssh_addr, ssh_port))
        self.project_http_uri = (
            'http://*****:*****@%s:%s/test/test_project.git' % (
                http_addr, http_port))

        self._run_gerrit(ssh_addr, ssh_port, http_addr, http_port)
        self._configure_ssh(ssh_addr, ssh_port)

        # create Gerrit empty project
        self._run_gerrit_cli('create-project', '--empty-commit',
                             '--name', 'test/test_project')

        # ensure user proxy conf doesn't interfere with tests
        os.environ['no_proxy'] = os.environ['NO_PROXY'] = '*'

        # prepare repository for the testing
        self._run_git('clone', self.project_uri)
        utils.write_to_file(self._dir('test', 'test_file.txt'),
                            'test file created'.encode())
        self._create_gitreview_file()

        # push changes to the Gerrit
        self._run_git('add', '--all')
        self._run_git('commit', '-m', 'Test file and .gitreview added.')
        self._run_git('push', 'origin', 'master')
        shutil.rmtree(self.test_dir)

        # go to the just cloned test Git repository
        self._run_git('clone', self.project_uri)
        self._run_git('remote', 'add', 'gerrit', self.project_uri)
        self.addCleanup(shutil.rmtree, self.test_dir)

        # ensure user is configured for all tests
        self._configure_gitreview_username()
コード例 #13
0
 def _simple_amend(self, change_text, file_=None):
     """Helper method to amend existing commit with change."""
     if file_ is None:
         file_ = self._dir('test', 'test_file_new.txt')
     utils.write_to_file(file_, change_text.encode())
     self._run_git('add', file_)
     # cannot use --no-edit because it does not exist in older git
     message = self._run_git('log', '-1', '--format=%s\n\n%b')
     self._run_git('commit', '--amend', '-m', message)
コード例 #14
0
ファイル: __init__.py プロジェクト: liuyang1/git-review
    def setUp(self):
        """Configure testing environment.

        Prepare directory for the testing and clone test Git repository.
        Require Gerrit war file in the .gerrit directory to run Gerrit local.
        """
        super(BaseGitReviewTestCase, self).setUp()
        self.useFixture(fixtures.Timeout(2 * 60, True))
        BaseGitReviewTestCase._test_counter += 1

        # ensures git-review command runs in local mode (for functional tests)
        self.useFixture(
            fixtures.EnvironmentVariable('GITREVIEW_LOCAL_MODE', ''))

        self.init_dirs()
        ssh_addr, ssh_port, http_addr, http_port, self.site_dir = \
            self._pick_gerrit_port_and_dir()
        self.gerrit_host, self.gerrit_port = ssh_addr, ssh_port

        self.test_dir = self._dir('site', 'tmp', 'test_project')
        self.ssh_dir = self._dir('site', 'tmp', 'ssh')
        self.project_ssh_uri = ('ssh://test_user@%s:%s/test/test_project.git' %
                                (ssh_addr, ssh_port))
        self.project_http_uri = (
            'http://*****:*****@%s:%s/test/test_project.git' %
            (http_addr, http_port))

        self._run_gerrit(ssh_addr, ssh_port, http_addr, http_port)
        self._configure_ssh(ssh_addr, ssh_port)

        # create Gerrit empty project
        self._run_gerrit_cli('create-project', '--empty-commit', '--name',
                             'test/test_project')

        # ensure user proxy conf doesn't interfere with tests
        os.environ['no_proxy'] = os.environ['NO_PROXY'] = '*'

        # prepare repository for the testing
        self._run_git('clone', self.project_uri)
        utils.write_to_file(self._dir('test', 'test_file.txt'),
                            'test file created'.encode())
        self._create_gitreview_file()

        # push changes to the Gerrit
        self._run_git('add', '--all')
        self._run_git('commit', '-m', 'Test file and .gitreview added.')
        self._run_git('push', 'origin', 'master')
        shutil.rmtree(self.test_dir)

        # go to the just cloned test Git repository
        self._run_git('clone', self.project_uri)
        self._run_git('remote', 'add', 'gerrit', self.project_uri)
        self.addCleanup(shutil.rmtree, self.test_dir)

        # ensure user is configured for all tests
        self._configure_gitreview_username()
コード例 #15
0
ファイル: __init__.py プロジェクト: jcarlosgdl/git-review
    def ensure_gerrit_war(self):
        # check if gerrit.war file exists in .gerrit directory
        if not os.path.exists(self.gerrit_dir):
            os.mkdir(self.gerrit_dir)

        if not os.path.exists(self.gerrit_war):
            print("Downloading Gerrit binary from %s..." % WAR_URL)
            resp = urlopen(WAR_URL)
            utils.write_to_file(self.gerrit_war, resp.read())
            print("Saved to %s" % self.gerrit_war)
コード例 #16
0
ファイル: __init__.py プロジェクト: liuyang1/git-review
    def ensure_gerrit_war(self):
        # check if gerrit.war file exists in .gerrit directory
        if not os.path.exists(self.gerrit_dir):
            os.mkdir(self.gerrit_dir)

        if not os.path.exists(self.gerrit_war):
            print("Downloading Gerrit binary from %s..." % WAR_URL)
            resp = urlopen(WAR_URL)
            utils.write_to_file(self.gerrit_war, resp.read())
            print("Saved to %s" % self.gerrit_war)
コード例 #17
0
    def ensure_gerrit_war(self):
        # check if gerrit.war file exists in .gerrit directory
        if not os.path.exists(self.gerrit_dir):
            os.mkdir(self.gerrit_dir)

        if not os.path.exists(self._dir('gerrit', 'gerrit.war')):
            resp = urlopen('http://gerrit-releases.storage.googleapis.com/'
                           'gerrit-2.6.1.war')

            utils.write_to_file(self._dir('gerrit', 'gerrit.war'), resp.read())
コード例 #18
0
 def _create_gitreview_file(self):
     cfg = ('[gerrit]\n'
            'scheme=%s\n'
            'host=%s\n'
            'port=%s\n'
            'project=test/test_project.git')
     parsed = urlparse(self.project_uri)
     host_port = parsed.netloc.rpartition('@')[-1]
     host, __, port = host_port.partition(':')
     cfg %= parsed.scheme, host, port
     utils.write_to_file(self._dir('test', '.gitreview'), cfg.encode())
コード例 #19
0
    def ensure_gerrit_war(self):
        # check if gerrit.war file exists in .gerrit directory
        if not os.path.exists(self.gerrit_dir):
            os.mkdir(self.gerrit_dir)

        if not os.path.exists(self.gerrit_war):
            print("Downloading Gerrit binary from %s..." % WAR_URL)
            resp = requests.get(WAR_URL)
            if resp.status_code != 200:
                raise RuntimeError("Problem requesting Gerrit war")
            utils.write_to_file(self.gerrit_war, resp.content)
            print("Saved to %s" % self.gerrit_war)
コード例 #20
0
ファイル: __init__.py プロジェクト: fkalinski/git-review
    def ensure_gerrit_war(self):
        # check if gerrit.war file exists in .gerrit directory
        if not os.path.exists(self.gerrit_dir):
            os.mkdir(self.gerrit_dir)

        if not os.path.exists(self.gerrit_war):
            print("Downloading Gerrit binary from %s..." % WAR_URL)
            resp = requests.get(WAR_URL)
            if resp.status_code != 200:
                raise RuntimeError("Problem requesting Gerrit war")
            utils.write_to_file(self.gerrit_war, resp.content)
            print("Saved to %s" % self.gerrit_war)
コード例 #21
0
ファイル: __init__.py プロジェクト: fkalinski/git-review
 def _create_gitreview_file(self, **kwargs):
     cfg = ('[gerrit]\n'
            'scheme=%s\n'
            'host=%s\n'
            'port=%s\n'
            'project=test/test_project.git\n'
            '%s')
     parsed = urlparse(self.project_uri)
     host_port = parsed.netloc.rpartition('@')[-1]
     host, __, port = host_port.partition(':')
     extra = '\n'.join('%s=%s' % kv for kv in kwargs.items())
     cfg %= parsed.scheme, host, port, extra
     utils.write_to_file(self._dir('test', '.gitreview'), cfg.encode())
コード例 #22
0
ファイル: __init__.py プロジェクト: h4ck3rm1k3/git-review-old
    def ensure_gerrit_war(self):
        # check if gerrit.war file exists in .gerrit directory
        if not os.path.exists(self.gerrit_dir):
            os.mkdir(self.gerrit_dir)

        if not os.path.exists(self._dir('gerrit', 'gerrit.war')):
            resp = urlopen(
                'http://gerrit-releases.storage.googleapis.com/'
                'gerrit-2.6.1.war'
            )

            utils.write_to_file(self._dir('gerrit', 'gerrit.war'),
                                resp.read())
コード例 #23
0
 def _create_gitreview_file(self, **kwargs):
     cfg = ('[gerrit]\n'
            'scheme=%s\n'
            'host=%s\n'
            'port=%s\n'
            'project=test/test_project.git\n'
            '%s')
     parsed = urlparse(self.project_uri)
     host_port = parsed.netloc.rpartition('@')[-1]
     host, __, port = host_port.partition(':')
     extra = '\n'.join('%s=%s' % kv for kv in kwargs.items())
     cfg %= parsed.scheme, host, port, extra
     utils.write_to_file(self._dir('test', '.gitreview'), cfg.encode())
コード例 #24
0
    def setUp(self):
        """Configure testing environment.

        Prepare directory for the testing and clone test Git repository.
        Require Gerrit war file in the .gerrit directory to run Gerrit local.
        """
        super(BaseGitReviewTestCase, self).setUp()
        self.useFixture(fixtures.Timeout(2 * 60, True))
        BaseGitReviewTestCase._test_counter += 1

        self.init_dirs()
        ssh_addr, ssh_port, http_addr, http_port, self.site_dir = \
            self._pick_gerrit_port_and_dir()
        self.gerrit_host, self.gerrit_port = ssh_addr, ssh_port

        self.test_dir = self._dir('site', 'tmp', 'test_project')
        self.ssh_dir = self._dir('site', 'tmp', 'ssh')
        self.project_ssh_uri = ('ssh://test_user@%s:%s/test/test_project.git' %
                                (ssh_addr, ssh_port))
        self.project_http_uri = (
            'http://*****:*****@%s:%s/test/test_project.git' %
            (http_addr, http_port))

        self._run_gerrit(ssh_addr, ssh_port, http_addr, http_port)
        self._configure_ssh(ssh_addr, ssh_port)

        # create Gerrit empty project
        self._run_gerrit_cli('create-project', '--empty-commit', '--name',
                             'test/test_project')

        # prepare repository for the testing
        self._run_git('clone', self.project_uri)
        utils.write_to_file(self._dir('test', 'test_file.txt'),
                            'test file created'.encode())
        cfg = ('[gerrit]\n'
               'host=%s\n'
               'port=%s\n'
               'project=test/test_project.git' % (ssh_addr, ssh_port))
        utils.write_to_file(self._dir('test', '.gitreview'), cfg.encode())

        # push changes to the Gerrit
        self._run_git('add', '--all')
        self._run_git('commit', '-m', 'Test file and .gitreview added.')
        self._run_git('push', 'origin', 'master')
        shutil.rmtree(self.test_dir)

        # go to the just cloned test Git repository
        self._run_git('clone', self.project_uri)
        self._run_git('remote', 'add', 'gerrit', self.project_uri)
        self.addCleanup(shutil.rmtree, self.test_dir)
コード例 #25
0
ファイル: __init__.py プロジェクト: h4ck3rm1k3/git-review-old
    def setUp(self):
        """Configure testing environment.

        Prepare directory for the testing and clone test Git repository.
        Require Gerrit war file in the .gerrit directory to run Gerrit local.
        """
        super(BaseGitReviewTestCase, self).setUp()
        self.useFixture(fixtures.Timeout(2 * 60, True))
        BaseGitReviewTestCase._test_counter += 1

        self.init_dirs()
        ssh_addr, ssh_port, http_addr, http_port, self.site_dir = \
            self._pick_gerrit_port_and_dir()
        self.gerrit_host, self.gerrit_port = ssh_addr, ssh_port

        self.test_dir = self._dir('site', 'tmp', 'test_project')
        self.ssh_dir = self._dir('site', 'tmp', 'ssh')
        self.project_uri = 'ssh://test_user@%s:%s/test/test_project.git' % (
            ssh_addr, ssh_port)

        self._run_gerrit(ssh_addr, ssh_port, http_addr, http_port)
        self._configure_ssh(ssh_addr, ssh_port)

        # create Gerrit empty project
        self._run_gerrit_cli('create-project', '--empty-commit',
                             '--name', 'test/test_project')

        # prepare repository for the testing
        self._run_git('clone', self.project_uri)
        utils.write_to_file(self._dir('test', 'test_file.txt'),
                            'test file created'.encode())
        cfg = ('[gerrit]\n'
               'host=%s\n'
               'port=%s\n'
               'project=test/test_project.git' % (ssh_addr, ssh_port))
        utils.write_to_file(self._dir('test', '.gitreview'), cfg.encode())

        # push changes to the Gerrit
        self._run_git('add', '--all')
        self._run_git('commit', '-m', 'Test file and .gitreview added.')
        self._run_git('push', 'origin', 'master')
        shutil.rmtree(self.test_dir)

        # go to the just cloned test Git repository
        self._run_git('clone', self.project_uri)
        self._run_git('remote', 'add', 'gerrit', self.project_uri)
        self.addCleanup(shutil.rmtree, self.test_dir)
コード例 #26
0
ファイル: __init__.py プロジェクト: jcarlosgdl/git-review
    def setUp(self):
        """Configure testing environment.

        Prepare directory for the testing and clone test Git repository.
        Require Gerrit war file in the .gerrit directory to run Gerrit local.
        """
        super(BaseGitReviewTestCase, self).setUp()
        self.useFixture(fixtures.Timeout(2 * 60, True))
        BaseGitReviewTestCase._test_counter += 1

        self.init_dirs()
        ssh_addr, ssh_port, http_addr, http_port, self.site_dir = self._pick_gerrit_port_and_dir()
        self.gerrit_host, self.gerrit_port = ssh_addr, ssh_port

        self.test_dir = self._dir("site", "tmp", "test_project")
        self.ssh_dir = self._dir("site", "tmp", "ssh")
        self.project_ssh_uri = "ssh://test_user@%s:%s/test/test_project.git" % (ssh_addr, ssh_port)
        self.project_http_uri = "http://*****:*****@%s:%s/test/test_project.git" % (http_addr, http_port)

        self._run_gerrit(ssh_addr, ssh_port, http_addr, http_port)
        self._configure_ssh(ssh_addr, ssh_port)

        # create Gerrit empty project
        self._run_gerrit_cli("create-project", "--empty-commit", "--name", "test/test_project")

        # ensure user proxy conf doesn't interfere with tests
        os.environ["NO_PROXY"] = "*"

        # prepare repository for the testing
        self._run_git("clone", self.project_uri)
        utils.write_to_file(self._dir("test", "test_file.txt"), "test file created".encode())
        self._create_gitreview_file()

        # push changes to the Gerrit
        self._run_git("add", "--all")
        self._run_git("commit", "-m", "Test file and .gitreview added.")
        self._run_git("push", "origin", "master")
        shutil.rmtree(self.test_dir)

        # go to the just cloned test Git repository
        self._run_git("clone", self.project_uri)
        self._run_git("remote", "add", "gerrit", self.project_uri)
        self.addCleanup(shutil.rmtree, self.test_dir)

        # ensure user is configured for all tests
        self._configure_gitreview_username()
コード例 #27
0
ファイル: __init__.py プロジェクト: stettberger/git-review
    def setUp(self):
        """Configure testing environment.

        Prepare directory for the testing and clone test Git repository.
        Require Gerrit war file in the .gerrit directory to run Gerrit local.
        """
        super(BaseGitReviewTestCase, self).setUp()

        self.init_dirs()
        self._pick_gerrit_port_and_dir()

        self.test_dir = self._dir('site', 'tmp', 'test_project')
        self.ssh_dir = self._dir('site', 'tmp', 'ssh')
        self.project_uri = 'ssh://test_user@localhost:%s/' \
            'test/test_project.git' % self.gerrit_port

        self._run_gerrit()
        self._configure_ssh()

        # create Gerrit empty project
        self._run_gerrit_cli('create-project', '--empty-commit', '--name',
                             'test/test_project')

        # prepare repository for the testing
        self._run_git('clone', self.project_uri)
        utils.write_to_file(self._dir('test', 'test_file.txt'),
                            'test file created'.encode())
        cfg = ('[gerrit]\n'
               'host=localhost\n'
               'port=%s\n'
               'project=test/test_project.git' % self.gerrit_port)
        utils.write_to_file(self._dir('test', '.gitreview'), cfg.encode())

        # push changes to the Gerrit
        self._run_git('add', '--all')
        self._run_git('commit', '-m', 'Test file and .gitreview added.')
        self._run_git('push', 'origin', 'master')
        shutil.rmtree(self.test_dir)

        # go to the just cloned test Git repository
        self._run_git('clone', self.project_uri)
        self._run_git('remote', 'add', 'gerrit', self.project_uri)
        self.addCleanup(shutil.rmtree, self.test_dir)
コード例 #28
0
ファイル: __init__.py プロジェクト: stettberger/git-review
    def _configure_ssh(self):
        """Setup ssh and scp to run with special options."""

        os.mkdir(self.ssh_dir)

        ssh_key = utils.run_cmd('ssh-keyscan', '-p', str(self.gerrit_port),
                                'localhost')
        utils.write_to_file(self._dir('ssh', 'known_hosts'), ssh_key.encode())
        self.addCleanup(os.remove, self._dir('ssh', 'known_hosts'))

        for cmd in ('ssh', 'scp'):
            cmd_file = self._dir('ssh', cmd)
            s = '#!/bin/sh\n' \
                '/usr/bin/%s -i %s -o UserKnownHostsFile=%s $@' % \
                (cmd,
                 self._dir('gsite', 'test_ssh_key'),
                 self._dir('ssh', 'known_hosts'))
            utils.write_to_file(cmd_file, s.encode())
            os.chmod(cmd_file, os.stat(cmd_file).st_mode | stat.S_IEXEC)

        os.environ['PATH'] = self.ssh_dir + os.pathsep + os.environ['PATH']
        os.environ['GIT_SSH'] = self._dir('ssh', 'ssh')
コード例 #29
0
    def _configure_ssh(self):
        """Setup ssh and scp to run with special options."""

        os.mkdir(self.ssh_dir)

        ssh_key = utils.run_cmd('ssh-keyscan', '-p', str(self.gerrit_port),
                                'localhost')
        utils.write_to_file(self._dir('ssh', 'known_hosts'), ssh_key.encode())
        self.addCleanup(os.remove, self._dir('ssh', 'known_hosts'))

        for cmd in ('ssh', 'scp'):
            cmd_file = self._dir('ssh', cmd)
            s = '#!/bin/sh\n' \
                '/usr/bin/%s -i %s -o UserKnownHostsFile=%s $@' % \
                (cmd,
                 self._dir('gsite', 'test_ssh_key'),
                 self._dir('ssh', 'known_hosts'))
            utils.write_to_file(cmd_file, s.encode())
            os.chmod(cmd_file, os.stat(cmd_file).st_mode | stat.S_IEXEC)

        os.environ['PATH'] = self.ssh_dir + os.pathsep + os.environ['PATH']
        os.environ['GIT_SSH'] = self._dir('ssh', 'ssh')
コード例 #30
0
ファイル: __init__.py プロジェクト: germaino/git-review
    def setUp(self):
        """Configure testing environment.

        Prepare directory for the testing and clone test Git repository.
        Require Gerrit war file in the .gerrit directory to run Gerrit local.
        """
        super(BaseGitReviewTestCase, self).setUp()
        self.useFixture(fixtures.Timeout(2 * 60, True))
        BaseGitReviewTestCase._test_counter += 1

        # ensures git-review command runs in local mode (for functional tests)
        self.useFixture(fixtures.EnvironmentVariable("GITREVIEW_LOCAL_MODE", ""))

        self.init_dirs()
        ssh_addr, ssh_port, http_addr, http_port, self.site_dir = self._pick_gerrit_port_and_dir()
        self.gerrit_host, self.gerrit_port = ssh_addr, ssh_port

        self.test_dir = self._dir("site", "tmp", "test_project")
        self.ssh_dir = self._dir("site", "tmp", "ssh")
        self.project_ssh_uri = "ssh://test_user@%s:%s/test/test_project.git" % (ssh_addr, ssh_port)
        self.project_http_uri = "http://*****:*****@%s:%s/test/test_project.git" % (http_addr, http_port)

        self._run_gerrit(ssh_addr, ssh_port, http_addr, http_port)
        self._configure_ssh(ssh_addr, ssh_port)

        # create Gerrit empty project
        self._run_gerrit_cli("create-project", "--empty-commit", "--name", "test/test_project")

        # ensure user proxy conf doesn't interfere with tests
        os.environ["no_proxy"] = os.environ["NO_PROXY"] = "*"

        # isolate tests from user and system git configuration
        self.home_dir = self._dir("site", "tmp", "home")
        self.xdg_config_dir = self._dir("home", ".xdgconfig")
        os.environ["HOME"] = self.home_dir
        os.environ["XDG_CONFIG_HOME"] = self.xdg_config_dir
        os.environ["GIT_CONFIG_NOSYSTEM"] = "1"
        os.environ["EMAIL"] = "*****@*****.**"
        if not os.path.exists(self.home_dir):
            os.mkdir(self.home_dir)
        if not os.path.exists(self.xdg_config_dir):
            os.mkdir(self.xdg_config_dir)
        self.addCleanup(shutil.rmtree, self.home_dir)

        # prepare repository for the testing
        self._run_git("clone", self.project_uri)
        utils.write_to_file(self._dir("test", "test_file.txt"), "test file created".encode())
        self._create_gitreview_file()

        # push changes to the Gerrit
        self._run_git("add", "--all")
        self._run_git("commit", "-m", "Test file and .gitreview added.")
        self._run_git("push", "origin", "master")
        shutil.rmtree(self.test_dir)

        # go to the just cloned test Git repository
        self._run_git("clone", self.project_uri)
        self.configure_gerrit_remote()
        self.addCleanup(shutil.rmtree, self.test_dir)

        # ensure user is configured for all tests
        self._configure_gitreview_username()
コード例 #31
0
ファイル: __init__.py プロジェクト: SusieMurphy/git-review
    def setUp(self):
        """Configure testing environment.

        Prepare directory for the testing and clone test Git repository.
        Require Gerrit war file in the .gerrit directory to run Gerrit local.
        """
        super(BaseGitReviewTestCase, self).setUp()
        self.useFixture(fixtures.Timeout(2 * 60, True))
        BaseGitReviewTestCase._test_counter += 1

        # ensures git-review command runs in local mode (for functional tests)
        self.useFixture(
            fixtures.EnvironmentVariable('GITREVIEW_LOCAL_MODE', ''))

        self.init_dirs()
        ssh_addr, ssh_port, http_addr, http_port, self.site_dir = \
            self._pick_gerrit_port_and_dir()
        self.gerrit_host, self.gerrit_port = ssh_addr, ssh_port

        self.test_dir = self._dir('site', 'tmp', 'test_project')
        self.ssh_dir = self._dir('site', 'tmp', 'ssh')
        self.project_ssh_uri = (
            'ssh://test_user@%s:%s/test/test_project.git' % (
                ssh_addr, ssh_port))
        self.project_http_uri = (
            'http://*****:*****@%s:%s/test/test_project.git' % (
                http_addr, http_port))

        self._run_gerrit(ssh_addr, ssh_port, http_addr, http_port)
        self._configure_ssh(ssh_addr, ssh_port)

        # create Gerrit empty project
        self._run_gerrit_cli('create-project', '--empty-commit',
                             '--name', 'test/test_project')

        # ensure user proxy conf doesn't interfere with tests
        os.environ['no_proxy'] = os.environ['NO_PROXY'] = '*'

        # isolate tests from user and system git configuration
        self.home_dir = self._dir('site', 'tmp', 'home')
        self.xdg_config_dir = self._dir('home', '.xdgconfig')
        os.environ['HOME'] = self.home_dir
        os.environ['XDG_CONFIG_HOME'] = self.xdg_config_dir
        os.environ['GIT_CONFIG_NOSYSTEM'] = "1"
        os.environ['EMAIL'] = "*****@*****.**"
        if not os.path.exists(self.home_dir):
            os.mkdir(self.home_dir)
        if not os.path.exists(self.xdg_config_dir):
            os.mkdir(self.xdg_config_dir)
        self.addCleanup(shutil.rmtree, self.home_dir)

        # prepare repository for the testing
        self._run_git('clone', self.project_uri)
        utils.write_to_file(self._dir('test', 'test_file.txt'),
                            'test file created'.encode())
        self._create_gitreview_file()

        # push changes to the Gerrit
        self._run_git('add', '--all')
        self._run_git('commit', '-m', 'Test file and .gitreview added.')
        self._run_git('push', 'origin', 'master')
        # push a branch to gerrit
        self._run_git('checkout', '-b', 'testbranch')
        utils.write_to_file(self._dir('test', 'test_file.txt'),
                            'test file branched'.encode())
        self._create_gitreview_file(defaultbranch='testbranch')
        self._run_git('add', '--all')
        self._run_git('commit', '-m', 'Branched.')
        self._run_git('push', 'origin', 'testbranch')
        # cleanup
        shutil.rmtree(self.test_dir)

        # go to the just cloned test Git repository
        self._run_git('clone', self.project_uri)
        self.configure_gerrit_remote()
        self.addCleanup(shutil.rmtree, self.test_dir)

        # ensure user is configured for all tests
        self._configure_gitreview_username()