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)
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')
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)
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())
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')
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")
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())
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)
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)
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()
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()
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)
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())
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())
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)
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())
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())
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)
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)
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()
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)
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')
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()
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()