Example #1
0
def test_push_remote_not_exist(patched_isfile, patched_push_git, patched_debrand,
                               patched_default_tries, config_file, key_file,
                               pushdir, capsys, mock_koji_session,
                               mock_koji_pathinfo, default_config,
                               cmd_args, package, expected_extra_dir):

    patched_default_tries.return_value = 1

    options = [
        '-v',
        '-c', config_file,
        '--push',
        'c7',
    ] + cmd_args

    mmd_str, _ = get_test_mmd_str_and_dict()
    binfo = {'extra': {'typeinfo': {'module': {'modulemd_str': mmd_str}}}}
    mock_koji_session.return_value.getBuild.return_value = binfo
    mock_koji_pathinfo.return_value.typedir.return_value = MODULES_PATH

    CONFIG_DEFAULTS['pagure_repo_init_api'] = 'https://pagure_git_url/api/0/new'
    CONFIG_DEFAULTS['pagure_api_key_file'] = key_file

    def side_eff():
        # create dummy remote repo to succeed git calls
        cmd = ['git', 'init', '--bare', 'grub2.git']
        check_call(cmd, cwd=pushdir)
        return '{"message": "Project \\"rpms/grub2\\" created"}'

    exists_original = os.path.exists
    repo_dir = os.path.join(
        default_config['gitdir'],
        expected_extra_dir,
        "%s.git" % package
    )
    with patch("os.path.exists") as mocked_exists:
        mocked_exists.side_effect = exists_original
        with patch.dict("alt_src.alt_src.CONFIG_DEFAULTS", CONFIG_DEFAULTS):
            with patch("alt_src.alt_src.urlopen") as mock_resp:
                mock_resp.return_value.read.side_effect = side_eff
                main(options)
                repo_dir = os.path.join(
                    default_config['gitdir'],
                    expected_extra_dir,
                    "%s.git" % package
                )
                mocked_exists.assert_any_call(repo_dir)

    std, _ = capsys.readouterr()
    missing_repo_str="Remote repo is missing: %s" % (
        default_config['git_push_url'] % {"package": package},
    )
    assert missing_repo_str in std
    assert "Initializing new repo:" in std
Example #2
0
def test_push_remote_exists(patched_isfile, patched_push_git, patched_debrand,
                            patched_default_tries, patched_get_output,
                            patched_log_cmd, patched_wipe_git_dir,
                            patched_push_lookaside,
                            config_file, key_file,
                            pushdir, capsys, mock_koji_session,
                            mock_koji_pathinfo, default_config,
                            cmd_args, package, expected_extra_dir):

    patched_default_tries.return_value = 1

    options = [
        '-v',
        '-c', config_file,
        '--push',
        'c7',
    ] + cmd_args

    def patched_get_output_sf(cmd, *args, **kwargs):
        if cmd[:2] == ["git", "ls-remote"]:
            ret = ("", 0)
        else:
            ret = patched_get_output.get_original()(cmd, *args, **kwargs)

        return ret

    patched_get_output.side_effect = patched_get_output_sf

    mmd_str, _ = get_test_mmd_str_and_dict()
    binfo = {'extra': {'typeinfo': {'module': {'modulemd_str': mmd_str}}}}
    mock_koji_session.return_value.getBuild.return_value = binfo
    mock_koji_pathinfo.return_value.typedir.return_value = MODULES_PATH

    CONFIG_DEFAULTS['pagure_repo_init_api'] = 'https://pagure_git_url/api/0/new'
    CONFIG_DEFAULTS['pagure_api_key_file'] = key_file

    exists_original = os.path.exists
    repo_dir = os.path.join(
        default_config['gitdir'],
        expected_extra_dir,
        "%s.git" % package
    )
    with patch("os.path.exists") as mocked_exists:
        mocked_exists.side_effect = exists_original
        with patch.dict("alt_src.alt_src.CONFIG_DEFAULTS", CONFIG_DEFAULTS):
            main(options)
            mocked_exists.assert_any_call(repo_dir)

    std, _ = capsys.readouterr()
    assert "Initializing new repo:" not in std
Example #3
0
def test_option_alias(config_file, pushdir, lookasidedir, default_config,
                      capsys):

    rpm = 'grub2-2.02-0.64.el7'

    options = ['-c', config_file, '--brew', rpm, os.path.join(RPMS_PATH, rpm)]

    with patch("alt_src.alt_src.setup_logging",
               side_effect=RuntimeError) as mocked_logging:
        try:
            main(options)
        except RuntimeError:
            pass
        assert hasattr(mocked_logging.mock_calls[0], 'koji')