def test_obscpio_create_archive(self): tc_name = inspect.stack()[0][3] cl_name = self.__class__.__name__ c_dir = os.path.join(self.tmp_dir, tc_name) f_dir = os.path.join(self.fixtures_dir, tc_name, 'repo') shutil.copytree(f_dir, c_dir) scmlogs = ScmInvocationLogs('git', c_dir) scmlogs.next('start-test') fixture = GitFixtures(c_dir, scmlogs) fixture.init() scm_object = Git(self.cli, self.tasks) scm_object.clone_dir = fixture.repo_path scm_object.arch_dir = fixture.repo_path outdir = os.path.join(self.tmp_dir, cl_name, tc_name, 'out') self.cli.outdir = outdir arch = ObsCpio() os.makedirs(outdir) arch.create_archive( scm_object, cli = self.cli, basename = 'test', dstname = 'test', version = '0.1.1' )
def test_obscpio_broken_link(self): tc_name = inspect.stack()[0][3] cl_name = self.__class__.__name__ c_dir = os.path.join(self.tmp_dir, tc_name) scmlogs = ScmInvocationLogs('git', c_dir) scmlogs.next('start-test') fixture = GitFixtures(c_dir, scmlogs) fixture.init() scm_object = Git(self.cli, self.tasks) scm_object.clone_dir = fixture.repo_path scm_object.arch_dir = fixture.repo_path outdir = os.path.join(self.tmp_dir, cl_name, tc_name, 'out') cwd = os.getcwd() print("cwd = %s" % cwd) os.chdir(fixture.repo_path) os.symlink('non-existant-file', 'broken-link') fixture.run('add broken-link') fixture.run("commit -m 'added broken-link'") os.chdir(cwd) self.cli.outdir = outdir arch = ObsCpio() os.makedirs(outdir) arch.create_archive( scm_object, cli = self.cli, basename = 'test', dstname = 'test', version = '0.1.1' )
def test_git_repoc_hash_wo_subdir(self): '''Test to get git repocache dir without subdir''' scm_object = Git(self.cli, self.tasks) scm_object.url = 'https://github.com/openSUSE/obs-service-tar_scm.git' repohash = scm_object.get_repocache_hash(None) self.assertEqual( repohash, 'c0f3245498ad916e9ee404acfd7aa59e29d53b7a063a8609735c1284c67b2161')
def test_git_repoc_hash_w_subdir(self): ''' This test case proves that subdir is ignored in TarSCM.base.scm.get_repocache_hash ''' scm_object = Git(self.cli, self.tasks) scm_object.url = 'https://github.com/openSUSE/obs-service-tar_scm.git' repohash = scm_object.get_repocache_hash('subdir') self.assertEqual( repohash, 'c0f3245498ad916e9ee404acfd7aa59e29d53b7a063a8609735c1284c67b2161')
def test_method__dstname(self): ''' basename != dstname basename is the package name or given by '--filename' dstname includes version string This is important for obscpio/obsinfo ''' tc_name = inspect.stack()[0][3] version = '0.1.1' scm_object = Git(self.cli, self.tasks) scm_object.clone_dir = os.path.join(self.fixtures_dir, tc_name) (dst, chgv, bname) = self.tasks._dstname(scm_object, version) self.assertEqual(tc_name, bname) self.assertEqual('%s-%s' % (tc_name, version), dst) self.assertEqual(chgv, version)
def test_calc_dir_to_clone_to(self): clone_dirs = [ '/local/repo.git', '/local/repo/.git', '/local/repo/.git/', 'http://remote/repo.git;param?query#fragment', 'http://remote/repo/.git;param?query#fragment', ] scm = Git(self.cli, self.tasks) for cdir in clone_dirs: scm.url = cdir scm._calc_dir_to_clone_to("") # pylint: disable=protected-access self.assertTrue(scm.clone_dir.endswith('/repo')) self.tasks.cleanup()
def test_cache_locking(self): scm = Git(self.cli, self.tasks) scm.clone_dir = '.' scm.lock_cache() fname = scm.lock_file.name scm.unlock_cache() assert os.path.exists(fname) == 0
def test_obscpio_create_archive(self): tc_name = inspect.stack()[0][3] cl_name = self.__class__.__name__ scm_object = Git(self.cli, self.tasks) scm_object.clone_dir = os.path.join(self.fixtures_dir, tc_name, 'repo') scm_object.arch_dir = os.path.join(self.fixtures_dir, tc_name, 'repo') outdir = os.path.join(self.tmp_dir, cl_name, tc_name, 'out') self.cli.outdir = outdir arch = ObsCpio() os.makedirs(outdir) arch.create_archive( scm_object, cli = self.cli, basename = 'test', dstname = 'test', version = '0.1.1' )
def test_no_parent_tag(self): fix = self.fixtures r_dir = os.path.join(self.test_dir, 'repo') os.chdir(r_dir) # remove autogenerate gitfixtures shutil.rmtree(os.path.join(r_dir)) # create fix.create_repo(r_dir) fix.touch('f1') fix.safe_run('add .') fix.safe_run('commit -m "initial commit"') # prepare test f_args = FakeCli() f_tasks = FakeTasks() git = Git(f_args, f_tasks) p_tag = git._detect_parent_tag(f_args) self.assertEqual(p_tag, '')
def test_no_parent_tag(self): fix = self.fixtures r_dir = os.path.join(self.test_dir, 'repo') os.chdir(r_dir) # remove autogenerate gitfixtures shutil.rmtree(os.path.join(r_dir)) # create fix.create_repo(r_dir) f_h = open('f1', 'a') f_h.close() fix.safe_run('add .') fix.safe_run('commit -m "initial commit"') # prepare test f_args = FakeCli() f_tasks = FakeTasks() git = Git(f_args, f_tasks) p_tag = git._detect_parent_tag(f_args) self.assertEqual(p_tag, '')
def test_obscpio_create_archive(self): tc_name = inspect.stack()[0][3] cl_name = self.__class__.__name__ c_dir = os.path.join(self.tmp_dir, tc_name) f_dir = os.path.join(self.fixtures_dir, tc_name, 'repo') shutil.copytree(f_dir, c_dir) scmlogs = ScmInvocationLogs('git', c_dir) scmlogs.nextlog('start-test') fixture = GitFixtures(c_dir, scmlogs) fixture.init() scm_object = Git(self.cli, self.tasks) scm_object.clone_dir = fixture.repo_path scm_object.arch_dir = fixture.repo_path outdir = os.path.join(self.tmp_dir, cl_name, tc_name, 'out') self.cli.outdir = outdir arch = ObsCpio() os.makedirs(outdir) version = '0.1.1' (dst, chgv, bname) = self.tasks._dstname(scm_object, version) arch.create_archive( scm_object, cli = self.cli, basename = bname, dstname = dst, version = chgv ) cpiofile = os.path.join(outdir, "%s-%s.obscpio" % (bname, version)) infofile = os.path.join(outdir, bname + ".obsinfo") self.assertTrue(os.path.isfile(cpiofile)) self.assertTrue(os.path.isfile(infofile)) with io.open(infofile, 'r', encoding='UTF-8') as fhl: data = yaml.safe_load(fhl) self.assertDictEqual( data, { 'name': bname, 'version': chgv, 'mtime': 1234567890, 'commit': data['commit']})
def test_check_url_valid(self): tc_arr = [ { 'obj': Git(self.cli, self.tasks), 'urls': [ 'http://example.com', 'https://example.com', 'ftp://example.com', 'ftps://example.com', 'git://example.com', 'ssh://example.com', 'example.com:/path/to/remote/repo', '[email protected]:/path/to/remote/repo', '[email protected]:/path/to/remote/repo', '[email protected]:/path/to/remote/repo', ] }, { 'obj': Bzr(self.cli, self.tasks), 'urls': [ 'http://example.com', 'https://example.com', 'ftp://example.com', 'aftp://example.com', 'bzr://example.com', 'lp://example.com', ] }, { 'obj': Hg(self.cli, self.tasks), 'urls': [ 'http://example.com', 'https://example.com', ] }, { 'obj': Svn(self.cli, self.tasks), 'urls': [ 'http://example.com', 'https://example.com', 'svn://example.com', ] }, ] for tca in tc_arr: for url in tca['urls']: tca['obj'].url = url self.assertTrue(tca['obj'].check_url())
def test_git_mirror_arg_insert(self): f_args = FakeCli() f_tasks = FakeTasks() git = Git(f_args, f_tasks) git.fetch_specific_revision = mock.MagicMock() git.repodir = '/tmp' git.pardir = '/foo' clone_url = 'https://clone_url' clone_dir = '/tmp/clone_dir' git.url = clone_url git.clone_dir = clone_dir with mock.patch.object(Helpers, 'safe_run') as mock_save_run: git.fetch_upstream_scm() ((command,), kwargs) = mock_save_run.call_args # noqa: E501 pylint: disable=W0612 expected_command = [ 'git', '-c', 'http.proxy=http://myproxy', 'clone', '--mirror', clone_url, clone_dir] self.assertEqual(expected_command, command)
def test_obscpio_create_archive(self): tc_name = inspect.stack()[0][3] cl_name = self.__class__.__name__ c_dir = os.path.join(self.tmp_dir, tc_name) f_dir = os.path.join(self.fixtures_dir, tc_name, 'repo') shutil.copytree(f_dir, c_dir) scmlogs = ScmInvocationLogs('git', c_dir) scmlogs.next('start-test') fixture = GitFixtures(c_dir, scmlogs) fixture.init() scm_object = Git(self.cli, self.tasks) scm_object.clone_dir = fixture.repo_path scm_object.arch_dir = fixture.repo_path outdir = os.path.join(self.tmp_dir, cl_name, tc_name, 'out') self.cli.outdir = outdir arch = ObsCpio() os.makedirs(outdir) arch.create_archive(scm_object, cli=self.cli, basename='test', dstname='test', version='0.1.1')
def test_check_url_invalid(self): invalid = [ 'Xhttp://example.com', 'Xhttps://example.com', 'Xftp://example.com', 'Xftps://example.com', 'Xaftp://example.com', 'Xbzr://example.com', 'Xlp://example.com', 'Xgit://example.com', 'Xssh://example.com', 'Xsvn://example.com', '/lala/nana', '/tmp/[email protected]:my/local/path' '/tmp/example.com:my/local/path' ] scms = [ Git(self.cli, self.tasks), Bzr(self.cli, self.tasks), Hg(self.cli, self.tasks), Svn(self.cli, self.tasks), ] for scm in scms: for url in invalid: print("%r %s" % (scm, url)) scm.url = url self.assertFalse(scm.check_url())
def test__git_log_cmd_with_subdir(self, safe_run_mock): scm = Git(self.cli, self.tasks) # pylint: disable=unused-variable,protected-access new_cmd = scm._log_cmd(['-n1'], 'subdir') # noqa safe_run_mock.assert_called_once_with( ['git', 'log', '-n1', '--', 'subdir'], cwd=None)
def test__git_log_cmd_with_subdir(self, safe_run_mock): scm = Git(self.cli, self.tasks) # pylint: disable=unused-variable,protected-access new_cmd = scm._log_cmd(['-n1'], 'subdir') # noqa safe_run_mock.assert_called_once_with(['git', 'log', '-n1', '--', 'subdir'], cwd=None)