def test_sync_repo(config_file, pushdir, lookasidedir, branch, name, version, release, default_config, capsys): """Tests whether sync_repo function is able to recover from git fetch error""" nvr = '-'.join([name, version, release]) workdir = default_config['gitdir'] + '/rpms/grub2.git' # simulates broken repo in gitdir os.makedirs(workdir) # init simulated remote git repo path = os.path.join(pushdir, "grub2.git") os.makedirs(path) cmd = ['git', 'init'] check_call(cmd, cwd=path) default_config['git_fetch_url'] = default_config['git_push_url'] mock_options = MagicMock(git_push_url=os.path.join(pushdir, '%(package)s.git'), source=tempfile.mkstemp(dir=pushdir)[1], koji=False, log_level='DEBUG', config=default_config) # clean handlers so they don't interfere with this test remove_handlers() # setup logger for capturing stdout/stderr logger = logging.getLogger("altsrc") logger.setLevel(logging.DEBUG) handler = logging.StreamHandler(sys.stdout) logger.addHandler(handler) with patch('alt_src.alt_src.Stager.git_push_url', return_value=workdir): stager = Stager(mock_options) # do a bit more setup for test stager.nvr = nvr stager.checkout = workdir stager.package = "grub2" # run desired function, should return without any error stager.sync_repo() out, err = capsys.readouterr() out_lines = out.splitlines() # It should not have logged an ERROR assert_that(err, empty()) # It should have logged a certain WARNINGs about cloning new repo assert_that(out, not_(empty())) assert 'Unable to fetch remote repo' in out_lines assert 'Removing local cache: %s' % workdir in out_lines assert 'Re-initializing repo' in out_lines remove_handlers()
def stager_setup(request, read_source, rule_cfg, options, checkout_dir, spec_file, work_dir, rules_dir): # pylint:disable=unused-argument with patch('os.path.isfile') as patched_isfile: s = Stager(options) s.checkout = str(checkout_dir) s.workdir = str(work_dir) s.log_cmd = MagicMock() s.get_output = MagicMock() s.get_output.side_effect = [('', 0), ('x\n', 0), ('\n', 0)] yield (s, str(spec_file), str(rules_dir), patched_isfile, str(checkout_dir))
def test_mmd_no_changelog(mock_koji_session, mock_koji_pathinfo): mmd_str, mmd_dict = get_test_mmd_str_and_dict() mock_koji_pathinfo.return_value.rpm.return_value = "test_relpath" binfo = {'extra': {'typeinfo': {'module': {'modulemd_str': mmd_str}}}} mock_koji_session.return_value.getBuild.return_value = binfo mock_options = MagicMock(koji=True, source="build_nvr:modulemd.src.txt") with patch('os.path.isfile', return_value=True): processor = Stager(mock_options) processor.source_file = os.path.join(MODULES_PATH, "modulemd.src.txt") processor.read_source_file() processor.prep_changelog([]) fn = '%s/changelog.txt' % processor.workdir assert_that(os.path.exists(fn), equal_to(False)) assert_that(processor.package, equal_to(mmd_dict['name']))