Beispiel #1
0
def test_create_project(mock_cc, capsys):
    response_message = "foobar"

    mock_client = MagicMock(no_config=False)
    mock_client.create_project.return_value = \
        MagicMock(message=response_message)
    mock_cc.create_from_file_config.return_value = mock_client

    main.main(argv=[
        "create", "foo",
        "--chroot", "f20", "--chroot", "f21",
        "--description", "desc string",
        "--instructions", "instruction string",
        "--repo", "repo1", "--repo", "repo2",
        "--initial-pkgs", "pkg1"
    ])

    stdout, stderr = capsys.readouterr()

    mock_client.create_project.assert_called_with(
        username=None, projectname="foo", description="desc string",
        instructions="instruction string", chroots=["f20", "f21"],
        repos=["repo1", "repo2"], initial_pkgs=["pkg1"])

    assert "{0}\n".format(response_message) in stdout
Beispiel #2
0
def test_create_build_wait_succeeded_no_sleep(mock_cc, mock_time, capsys):
    response_message = "foobar"

    mock_client = MagicMock(no_config=False)
    mock_client.create_new_build.return_value = MagicMock(
        output="ok",
        message=response_message,
        builds_list=[
            MagicMock(build_id=x)
            for x in range(3)
        ])
    mock_client.get_build_details.return_value = MagicMock(
        status="succeeded", output="ok"
    )
    mock_cc.create_from_file_config.return_value = mock_client
    main.main(argv=[
        "build",
        "copr_name", "http://example.com/pkgs.srpm"
    ])

    stdout, stderr = capsys.readouterr()

    assert response_message in stdout
    assert "Created builds" in stdout
    assert "Watching build" in stdout
    assert not mock_time.sleep.called
Beispiel #3
0
    def test_create_build_wait_failed_complex(self, build_proxy_get,
                                              create_from_url, auth_check,
                                              config_from_file, mock_time,
                                              capsys):
        create_from_url.return_value = Munch(projectname="foo", id=1)
        self.stage = 0

        def incr(*args, **kwargs):
            self.stage += 1

        def result_map(*args, **kwargs):
            if self.stage == 0:
                return Munch(state="pending")
            elif self.stage == 1:
                smap = {0: "pending", 1: "starting", 2: "running"}
                return Munch(state=smap[kwargs["build_id"]])
            elif self.stage == 2:
                smap = {0: "failed", 1: "running", 2: "succeeded"}
                return Munch(state=smap[kwargs["build_id"]])
            elif self.stage == 3:
                smap = {0: "failed", 1: "failed", 2: "succeeded"}
                return Munch(state=smap[kwargs["build_id"]])

        mock_time.sleep.side_effect = incr
        build_proxy_get.side_effect = result_map

        with pytest.raises(SystemExit) as err:
            main.main(
                argv=["build", "copr_name", "http://example.com/pkgs.srpm"])

        stdout, stderr = capsys.readouterr()
        assert "Created builds" in stdout
        assert "Watching build" in stdout
        assert "Build(s) 1 failed" in stderr
        assert len(mock_time.sleep.call_args_list) == 3
Beispiel #4
0
def test_download_build(mock_cc, mock_sp, capsys):
    mock_client = MagicMock(no_config=False)
    mock_client.get_build_details.return_value = \
        MagicMock(
            data={"chroots": {
                u'epel-6-x86_64': u'succeeded', u'epel-6-i386': u'succeeded'
            }},
            src_pkg="http://example/python/python-copr-1.50-1.fc20.src.rpm",
            results="http://example.com/results/",
        )
    mock_cc.create_from_file_config.return_value = mock_client

    mock_sp.call.return_value = None
    main.main(argv=["download-build", "foo"])
    stdout, stderr = capsys.readouterr()

    expected_sp_call_args = [
        mock.call([
            'wget', '-r', '-nH', '--no-parent', '--reject', "'index.html*'",
            '-P', u'./epel-6-x86_64', '--cut-dirs', '6',
            'http://example.com/results/epel-6-x86_64/python-copr-1.50-1.fc20/'
        ]),
        mock.call([
            'wget', '-r', '-nH', '--no-parent', '--reject', "'index.html*'",
            '-P', u'./epel-6-i386', '--cut-dirs', '6',
            'http://example.com/results/epel-6-i386/python-copr-1.50-1.fc20/'
        ])
    ]

    assert mock_sp.call.call_args_list == expected_sp_call_args
Beispiel #5
0
def test_status_response(config_from_file, build_proxy_get, capsys):
    response_status = "foobar"
    build_proxy_get.return_value = MagicMock(state=response_status)

    main.main(argv=["status", "123"])
    out, err = capsys.readouterr()
    assert "{0}\n".format(response_status) in out
Beispiel #6
0
def test_list_project_empty_list(config_from_file, get_list, capsys):
    get_list.return_value = []
    main.main(argv=["list", "projectname"])

    out, err = capsys.readouterr()
    assert "error" not in out
    assert "No copr retrieved for user: dummy"
Beispiel #7
0
def test_create_build_wait_unknown_build_status(mock_cc, capsys):
    response_message = "foobar"

    mock_client = MagicMock(no_config=False)
    mock_client.create_new_build.return_value = MagicMock(
        output="ok",
        message=response_message,
        builds_list=[
            MagicMock(build_id=x)
            for x in ["1", "2", "3"]
        ])
    mock_client.get_build_details.return_value = MagicMock(
        output="ok", status="unknown"
    )
    mock_cc.create_from_file_config.return_value = mock_client
    with pytest.raises(SystemExit) as err:
        main.main(argv=[
            "build",
            "copr_name", "http://example.com/pkgs.srpm"
        ])
        assert err.value.code == 1

    stdout, stderr = capsys.readouterr()
    assert response_message in stdout
    assert "Created builds" in stdout
    assert "Watching build" in stdout
Beispiel #8
0
def test_edit_permissions_output(ocnfig, action):
    def test_me(args, expected_output):
        main.main(['edit-permissions'] + args)
        args = action.call_args[0][0]
        assert args.permissions == expected_output

    with pytest.raises(SystemExit) as err:
        main.main(['edit-permissions'])
    assert err.value.code == 2
    assert len(action.call_args_list) == 0

    test_me(['some/project'], None)
    test_me(['some/project', '--admin', 'a', '--admin', 'b'], {
        'a': {
            'admin': 'approved'
        },
        'b': {
            'admin': 'approved'
        }
    })
    test_me(['some/project', '--admin', 'praiskup=nothing', '--admin', 'b'], {
        'b': {
            'admin': 'approved'
        },
        'praiskup': {
            'admin': 'nothing'
        }
    })
    test_me(['some/project', '--builder', 'praiskup', '--admin', 'praiskup'],
            {'praiskup': {
                'admin': 'approved',
                'builder': 'approved'
            }})
Beispiel #9
0
def test_download_build_select_chroot(mock_cc, mock_sp, capsys):
    mock_client = MagicMock(no_config=False)
    mock_client.get_build_details.return_value = \
        MagicMock(
            data={"chroots": {
                u'epel-6-x86_64': u'succeeded', u'epel-6-i386': u'succeeded'
            }},
            results_by_chroot={
                u'epel-6-x86_64': u'http://example.com/results/epel-6-x86_64/python-copr-1.50-1.fc20',
                u'epel-6-i386': u'http://example.com/results/epel-6-i386/python-copr-1.50-1.fc20',
            }
        )
    mock_cc.create_from_file_config.return_value = mock_client

    mock_sp.call.return_value = None
    main.main(argv=["download-build", "foo", "-r", "epel-6-x86_64"])
    stdout, stderr = capsys.readouterr()
    expected_sp_call_args = [
        mock.call([
            'wget', '-r', '-nH', '--no-parent', '--reject', "'index.html*'",
            '-P', u'./epel-6-x86_64', '--cut-dirs', '6',
            'http://example.com/results/epel-6-x86_64/python-copr-1.50-1.fc20'
        ]),
    ]

    assert mock_sp.call.call_args_list == expected_sp_call_args
Beispiel #10
0
def test_create_project(mock_cc, capsys):
    response_message = "foobar"

    mock_client = MagicMock(no_config=False)
    mock_client.create_project.return_value = \
        MagicMock(message=response_message)
    mock_cc.create_from_file_config.return_value = mock_client

    main.main(argv=[
        "create", "foo", "--chroot", "f20", "--chroot", "f21", "--description",
        "desc string", "--instructions", "instruction string", "--repo",
        "repo1", "--repo", "repo2", "--initial-pkgs", "pkg1"
    ])

    stdout, stderr = capsys.readouterr()

    mock_client.create_project.assert_called_with(
        auto_prune=True,
        username=None,
        persistent=False,
        projectname="foo",
        description="desc string",
        instructions="instruction string",
        chroots=["f20", "f21"],
        repos=["repo1", "repo2"],
        initial_pkgs=["pkg1"],
        unlisted_on_hp=None,
        disable_createrepo=None,
        enable_net=False,
        use_bootstrap_container=None)

    assert "{0}\n".format(response_message) in stdout
Beispiel #11
0
def test_list_project_no_username2(config_from_file, capsys):
    with pytest.raises(SystemExit) as err:
        main.main(argv=["list"])

    assert exit_wrap(err.value) == 6
    out, err = capsys.readouterr()
    assert "Pass username to command or add it to `~/.config/copr`" in err
Beispiel #12
0
def test_edit_permissions_request(ocnfig, action):
    def test_me(args, expected_output):
        main.main(['request-permissions'] + args)
        args = action.call_args[0][0]
        assert args.permissions == expected_output

    with pytest.raises(SystemExit) as err:
        main.main(['request-permissions'])
    assert err.value.code == 2
    assert len(action.call_args_list) == 0

    test_me(['some/project'], None)

    with pytest.raises(SystemExit) as err:
        test_me(['some/project', '--admin', '--admin'], None)
    with pytest.raises(SystemExit) as err:
        test_me(['some/project', '--admin', '--admin', 'b'], None)
    assert err.value.code == 2

    test_me(['some/project', '--admin', 'bad_status'],
            {'your user': {
                'admin': 'bad_status'
            }})
    test_me(['some/project', '--admin', '--builder'],
            {'your user': {
                'admin': 'request',
                'builder': 'request'
            }})
    test_me(  # we don't parse '=' here
        ['some/project', '--admin', 'bad_status=nothing'],
        {'your user': {
            'admin': 'bad_status=nothing'
        }})
Beispiel #13
0
def test_create_build_wait_unknown_build_status(mock_cc, capsys):
    response_message = "foobar"

    mock_client = MagicMock(no_config=False)
    mock_client.create_new_build.return_value = MagicMock(
        output="ok",
        message=response_message,
        builds_list=[
            MagicMock(build_id=x)
            for x in ["1", "2", "3"]
        ])
    mock_client.get_build_details.return_value = MagicMock(
        output="ok", status="unknown"
    )
    mock_cc.create_from_file_config.return_value = mock_client
    with pytest.raises(SystemExit) as err:
        main.main(argv=[
            "build",
            "copr_name", "http://example.com/pkgs.srpm"
        ])
        assert err.value.code == 1

    stdout, stderr = capsys.readouterr()
    assert response_message in stdout
    assert "Created builds" in stdout
    assert "Watching build" in stdout
Beispiel #14
0
def test_create_project(mock_cc, capsys):
    response_message = "foobar"

    mock_client = MagicMock(no_config=False)
    mock_client.create_project.return_value = \
        MagicMock(message=response_message)
    mock_cc.create_from_file_config.return_value = mock_client

    main.main(argv=[
        "create", "foo",
        "--chroot", "f20", "--chroot", "f21",
        "--description", "desc string",
        "--instructions", "instruction string",
        "--repo", "repo1", "--repo", "repo2",
        "--initial-pkgs", "pkg1"
    ])

    stdout, stderr = capsys.readouterr()

    mock_client.create_project.assert_called_with(
        projectname="foo", description="desc string",
        instructions="instruction string", chroots=["f20", "f21"],
        repos=["repo1", "repo2"], initial_pkgs=["pkg1"])

    assert "{}\n".format(response_message) in stdout
Beispiel #15
0
def test_create_project(config_from_file, project_proxy_add, capsys):
    main.main(argv=[
        "create", "foo", "--chroot", "f20", "--chroot", "f21", "--description",
        "desc string", "--instructions", "instruction string", "--repo",
        "repo1", "--repo", "repo2", "--initial-pkgs", "pkg1"
    ])
    stdout, stderr = capsys.readouterr()

    project_proxy_add.assert_called_once()
    args, kwargs = project_proxy_add.call_args
    assert kwargs == {
        "auto_prune": True,
        "ownername": None,
        "persistent": False,
        "projectname": "foo",
        "description": "desc string",
        "instructions": "instruction string",
        "chroots": ["f20", "f21"],
        "additional_repos": ["repo1", "repo2"],
        "unlisted_on_hp": None,
        "devel_mode": None,
        "enable_net": False,
        "use_bootstrap_container": None,
        "delete_after_days": None,
        "multilib": False,
        "module_hotfixes": False,
    }
    assert stdout == "New project was successfully created.\n"
Beispiel #16
0
def test_create_build_wait_succeeded_no_sleep(mock_cc, mock_time, capsys):
    response_message = "foobar"

    mock_client = MagicMock(no_config=False)
    mock_client.create_new_build.return_value = MagicMock(
        output="ok",
        message=response_message,
        builds_list=[
            MagicMock(build_id=x)
            for x in range(3)
        ])
    mock_client.get_build_details.return_value = MagicMock(
        status="succeeded", output="ok"
    )
    mock_cc.create_from_file_config.return_value = mock_client
    main.main(argv=[
        "build",
        "copr_name", "http://example.com/pkgs.srpm"
    ])

    stdout, stderr = capsys.readouterr()

    assert response_message in stdout
    assert "Created builds" in stdout
    assert "Watching build" in stdout
    assert not mock_time.sleep.called
Beispiel #17
0
def test_download_build_select_chroot(config_from_file,
                                      build_chroot_proxy_get_list,
                                      build_proxy_get, mock_sp, capsys):
    build_proxy_get.return_value = MagicMock(
        repo_url=
        "http://example.com/results/epel-6-x86_64/python-copr-1.50-1.fc20")

    mock_ch1 = MagicMock()
    mock_ch1.configure_mock(
        name="epel-6-x86_64",
        result_url=
        "http://example.com/results/epel-6-x86_64/python-copr-1.50-1.fc20")

    mock_ch2 = MagicMock()
    mock_ch2.configure_mock(
        name="epel-6-i386",
        result_url=
        "http://example.com/results/epel-6-i386/python-copr-1.50-1.fc20")
    build_chroot_proxy_get_list.return_value = [mock_ch1, mock_ch2]

    mock_sp.call.return_value = None
    main.main(argv=["download-build", "foo", "-r", "epel-6-x86_64"])
    stdout, stderr = capsys.readouterr()
    expected_sp_call_args = [
        mock.call([
            'wget', '-r', '-nH', '--no-parent', '--reject', '"index.html*"',
            '-e', 'robots=off', '--no-verbose', '-P', u'./epel-6-x86_64',
            '--cut-dirs', '6',
            'http://example.com/results/epel-6-x86_64/python-copr-1.50-1.fc20'
        ]),
    ]

    assert mock_sp.call.call_args_list == expected_sp_call_args
Beispiel #18
0
def test_status_response_no_args(capsys):
    with pytest.raises(SystemExit) as err:
        main.main(argv=["status"])

    assert exit_wrap(err.value) == 2

    stdout, stderr = capsys.readouterr()
    assert "usage: copr" in stderr
Beispiel #19
0
def test_debug_by_status_response(config_from_file, build_proxy_get, capsys):
    response_status = "foobar"
    build_proxy_get.return_value = MagicMock(state=response_status)

    main.main(argv=["--debug", "status", "123"])
    stdout, stderr = capsys.readouterr()
    assert "{0}\n".format(response_status) in stdout
    assert "Debug log enabled " in stderr
Beispiel #20
0
def test_list_project_no_username(mock_cc, capsys):
    mock_cc.create_from_file_config.side_effect = CoprNoConfException()

    with pytest.raises(SystemExit) as err:
        main.main(argv=["list"])

    assert err.value.code == 6
    out, err = capsys.readouterr()
    assert "Pass username to command or create `~/.config/copr`" in out
Beispiel #21
0
def test_error_no_args(capsys):
    for func_name in ["status", "build", "delete", "create"]:
        with pytest.raises(SystemExit) as err:
            main.main(argv=[func_name])

        assert exit_wrap(err.value) == 2

        stdout, stderr = capsys.readouterr()
        assert "usage: copr" in stderr
Beispiel #22
0
def test_list_project_no_username2(mock_cc, capsys):
    mock_cc.create_from_file_config.return_value = CoprClient()

    with pytest.raises(SystemExit) as err:
        main.main(argv=["list"])

    assert err.value.code == 6
    out, err = capsys.readouterr()
    assert "Pass username to command or add it to `~/.config/copr`" in out
Beispiel #23
0
def test_error_keyboard_interrupt(config_from_file, build_proxy_get, capsys):
    build_proxy_get.side_effect = KeyboardInterrupt()

    with pytest.raises(SystemExit) as err:
        main.main(argv=["status", "123"])

    assert exit_wrap(err.value) == 1
    stdout, stderr = capsys.readouterr()
    assert "Interrupted by user" in stderr
Beispiel #24
0
def test_list_project_no_username(config_from_file, capsys):
    config_from_file.side_effect = copr.v3.CoprNoConfigException()

    with pytest.raises(SystemExit) as err:
        main.main(argv=["list"])

    assert exit_wrap(err.value) == 6
    out, err = capsys.readouterr()
    assert "Pass username to command or create `~/.config/copr`" in err
Beispiel #25
0
def test_list_project_no_username(mock_cc, capsys):
    mock_cc.create_from_file_config.side_effect = CoprNoConfException()

    with pytest.raises(SystemExit) as err:
        main.main(argv=["list"])

    assert err.value.code == 6
    out, err = capsys.readouterr()
    assert "Pass username to command or create `~/.config/copr`" in out
Beispiel #26
0
def test_list_project_no_username2(mock_cc, capsys):
    mock_cc.create_from_file_config.return_value = CoprClient()

    with pytest.raises(SystemExit) as err:
        main.main(argv=["list"])

    assert err.value.code == 6
    out, err = capsys.readouterr()
    assert "Pass username to command or add it to `~/.config/copr`" in out
Beispiel #27
0
def test_error_copr_build_exception(config_from_file, action_build, capsys):
    error_msg = "error message"
    action_build.side_effect = CoprBuildException(error_msg)

    with pytest.raises(SystemExit) as err:
        main.main(argv=["build", "prj1", "src1"])

    assert exit_wrap(err.value) == 4
    stdout, stderr = capsys.readouterr()
    assert error_msg in stderr
Beispiel #28
0
def test_error_copr_unknown_response(config_from_file, action_status, capsys):
    error_msg = "error message"
    action_status.side_effect = CoprUnknownResponseException(error_msg)

    with pytest.raises(SystemExit) as err:
        main.main(argv=["status", "123"])

    assert exit_wrap(err.value) == 5
    stdout, stderr = capsys.readouterr()
    assert error_msg in stderr
Beispiel #29
0
def test_list_chroots(config, list_chroots):
    list_chroots.return_value = Munch({
        "fedora-18-x86_64": "",
        "fedora-17-x86_64": "A short chroot comment",
        "fedora-17-i386":
        "Chroot comment containing [url with four\nwords](https://copr.fedorainfracloud.org/)",
        "fedora-rawhide-i386": "",
    })

    main.main(argv=["list-chroots"])
Beispiel #30
0
def test_cancel_build_response(mock_cc, capsys):
    response_status = "foobar"

    mock_client = MagicMock(no_config=False, )
    mock_client.cancel_build.return_value = MagicMock(status=response_status)
    mock_cc.create_from_file_config.return_value = mock_client

    main.main(argv=["cancel", "123"])
    out, err = capsys.readouterr()
    assert "{}\n".format(response_status) in out
Beispiel #31
0
def test_error_copr_common_exception(config_from_file, build_proxy_get, capsys):
    error_msg = "error message"
    build_proxy_get.side_effect = copr.v3.CoprException(error_msg)

    with pytest.raises(SystemExit) as err:
        main.main(argv=["status", "123"])

    assert exit_wrap(err.value) == 3
    stdout, stderr = capsys.readouterr()
    assert error_msg in stderr
Beispiel #32
0
def test_cancel_build_response(mock_cc, capsys):
    response_status = "foobar"

    mock_client = MagicMock(no_config=False, )
    mock_client.cancel_build.return_value = MagicMock(status=response_status)
    mock_cc.create_from_file_config.return_value = mock_client

    main.main(argv=["cancel", "123"])
    out, err = capsys.readouterr()
    assert "{0}\n".format(response_status) in out
Beispiel #33
0
def test_create_build_wait_keyboard_interrupt(config_from_file,
                                              build_proxy_get, create_from_url,
                                              autch_check, capsys):
    create_from_url.return_value = Munch(projectname="foo", id=123)
    build_proxy_get.side_effect = KeyboardInterrupt

    main.main(argv=["build", "copr_name", "http://example.com/pkgs.srpm"])

    stdout, stderr = capsys.readouterr()
    assert "Created builds" in stdout
    assert "Watching build" in stdout
Beispiel #34
0
def test_error_keyboard_interrupt(mock_cc, capsys):
    mock_client = MagicMock(no_config=False)
    mock_client.get_build_details.side_effect = KeyboardInterrupt()
    mock_cc.create_from_file_config.return_value = mock_client

    with pytest.raises(SystemExit) as err:
        main.main(argv=["status", "123"])

    assert err.value.code == 1
    stdout, stderr = capsys.readouterr()
    assert "Interrupted by user" in stderr
Beispiel #35
0
def test_delete_project(mock_cc, capsys):
    response_message = "foobar"

    mock_client = MagicMock(no_config=False)
    mock_client.delete_project.return_value = \
        MagicMock(message=response_message)
    mock_cc.create_from_file_config.return_value = mock_client

    main.main(argv=["delete", "foo"])
    out, err = capsys.readouterr()
    assert "{0}\n".format(response_message) in out
Beispiel #36
0
def test_delete_project(mock_cc, capsys):
    response_message = "foobar"

    mock_client = MagicMock(no_config=False)
    mock_client.delete_project.return_value = \
        MagicMock(message=response_message)
    mock_cc.create_from_file_config.return_value = mock_client

    main.main(argv=["delete", "foo"])
    out, err = capsys.readouterr()
    assert "{}\n".format(response_message) in out
Beispiel #37
0
def test_error_keyboard_interrupt(mock_cc, capsys):
    mock_client = MagicMock(no_config=False)
    mock_client.get_build_details.side_effect = KeyboardInterrupt()
    mock_cc.create_from_file_config.return_value = mock_client

    with pytest.raises(SystemExit) as err:
        main.main(argv=["status", "123"])

    assert err.value.code == 1
    stdout, stderr = capsys.readouterr()
    assert "Interrupted by user" in stderr
Beispiel #38
0
def test_create_build_wait_succeeded_no_sleep(config_from_file,
                                              build_proxy_get, create_from_url,
                                              auth_check, mock_time, capsys):
    create_from_url.return_value = Munch(projectname="foo", id=123)
    build_proxy_get.return_value = Munch(state="succeeded")
    main.main(argv=["build", "copr_name", "http://example.com/pkgs.srpm"])

    stdout, stderr = capsys.readouterr()
    assert "Created builds" in stdout
    assert "Watching build" in stdout
    assert not mock_time.sleep.called
Beispiel #39
0
def test_create_build_wait_error_status(config_from_file, build_proxy_get,
                                        create_from_url, auth_check, capsys):
    create_from_url.return_value = Munch(projectname="foo", id=123)
    build_proxy_get.side_effect = copr.v3.CoprRequestException()
    with pytest.raises(SystemExit) as err:
        main.main(argv=["build", "copr_name", "http://example.com/pkgs.srpm"])
        assert exit_wrap(err.value) == 1

    stdout, stderr = capsys.readouterr()
    assert "Created builds" in stdout
    assert "Watching build" in stdout
Beispiel #40
0
def test_status_response(mock_cc, capsys):
    response_status = "foobar"

    mock_client = MagicMock(no_config=False)
    mock_client.get_build_details.return_value = \
        MagicMock(status=response_status)
    mock_cc.create_from_file_config.return_value = mock_client

    main.main(argv=["status", "123"])
    out, err = capsys.readouterr()
    assert "{}\n".format(response_status) in out
Beispiel #41
0
def test_status_response_no_args(mock_cc, capsys):
    mock_client = MagicMock(no_config=False)
    mock_cc.create_from_file_config.return_value = mock_client

    with pytest.raises(SystemExit) as err:
        main.main(argv=["status"])

    assert err.value.code == 2

    stdout, stderr = capsys.readouterr()
    assert "usage: copr" in stderr
    assert "too few arguments" in stderr
Beispiel #42
0
def test_debug_by_status_response(mock_cc, capsys):
    response_status = "foobar"

    mock_client = MagicMock(no_config=False)
    mock_client.get_build_details.return_value = \
        MagicMock(status=response_status)
    mock_cc.create_from_file_config.return_value = mock_client

    main.main(argv=["--debug", "status", "123"])
    stdout, stderr = capsys.readouterr()
    assert "{0}\n".format(response_status) in stdout
    assert "Debug log enabled " in stderr
Beispiel #43
0
def test_list_project_empty_list(mock_cc, capsys):
    mock_client = MagicMock(no_config=False, username="******")
    mock_cc.create_from_file_config.return_value = mock_client

    mock_response = MagicMock(CoprResponse(None, None, None),
                              output="ok", projects_list=[])

    mock_client.get_projects_list.return_value = mock_response
    main.main(argv=["list", "projectname"])

    out, err = capsys.readouterr()
    assert "error" not in out
    assert "No copr retrieved for user: dummy"
Beispiel #44
0
def test_cancel_build_no_config(mock_cc, capsys):
    mock_cc.create_from_file_config.side_effect = CoprNoConfException()

    with pytest.raises(SystemExit) as err:
        main.main(argv=["cancel", "123400"])

    assert err.value.code == 6
    out, err = capsys.readouterr()
    assert ("Error: Operation requires api authentication\n"
            "File `~/.config/copr` is missing or incorrect\n") in out

    expected_warning = no_config_warning.format("~/.config/copr")
    assert expected_warning in out
Beispiel #45
0
def test_error_no_args(mock_cc, capsys):
    mock_client = MagicMock(no_config=False)
    mock_cc.create_from_file_config.return_value = mock_client

    for func_name in ["status", "build", "delete", "create"]:
        with pytest.raises(SystemExit) as err:
            main.main(argv=[func_name])

        assert err.value.code == 2

        stdout, stderr = capsys.readouterr()
        assert "usage: copr" in stderr
        assert "too few arguments" in stderr
Beispiel #46
0
def test_error_copr_build_exception(mock_cc, capsys):
    error_msg = "error message"

    mock_client = MagicMock(no_config=False)
    mock_client.create_new_build.side_effect = \
        CoprBuildException(error_msg)
    mock_cc.create_from_file_config.return_value = mock_client

    with pytest.raises(SystemExit) as err:
        main.main(argv=["build", "prj1", "src1"])

    assert err.value.code == 4
    stdout, stderr = capsys.readouterr()
    assert error_msg in stderr
Beispiel #47
0
def test_error_copr_request(mock_cc, capsys):
    error_msg = "error message"

    mock_client = MagicMock(no_config=False)
    mock_client.get_build_details.side_effect = CoprRequestException(error_msg)
    mock_cc.create_from_file_config.return_value = mock_client

    with pytest.raises(SystemExit) as err:
        main.main(argv=["status", "123"])

    assert err.value.code == 1
    stdout, stderr = capsys.readouterr()
    assert "Something went wrong" in stderr
    assert error_msg in stderr
Beispiel #48
0
def test_error_copr_unknown_response(mock_cc, capsys):
    error_msg = "error message"

    mock_client = MagicMock(no_config=False)
    mock_client.get_build_details.side_effect = \
        CoprUnknownResponseException(error_msg)
    mock_cc.create_from_file_config.return_value = mock_client

    with pytest.raises(SystemExit) as err:
        main.main(argv=["status", "123"])

    assert err.value.code == 5
    stdout, stderr = capsys.readouterr()
    assert error_msg in stderr
Beispiel #49
0
def test_error_argument_error(mock_cc, mock_setup_parser, capsys):
    error_msg = "error message"

    mock_client = MagicMock(no_config=False)
    mock_cc.create_from_file_config.return_value = mock_client

    mock_setup_parser.return_value.parse_args.side_effect = \
        argparse.ArgumentTypeError(error_msg)

    with pytest.raises(SystemExit) as err:
        main.main(argv=["status", "123"])

    assert err.value.code == 2
    stdout, stderr = capsys.readouterr()
    assert error_msg in stderr
Beispiel #50
0
    def test_create_build_wait_failed_complex(self, mock_cc, mock_time, capsys):
        response_message = "foobar"

        mock_client = MagicMock(no_config=False)
        mock_client.create_new_build.return_value = MagicMock(
            output="ok",
            message=response_message,
            builds_list=[
                MagicMock(build_id=x)
                for x in range(3)
            ])

        self.stage = 0

        def incr(*args, **kwargs):
            self.stage += 1

        def result_map(build_id, *args, **kwargs):
            if self.stage == 0:
                return MagicMock(status="pending", output="ok")
            elif self.stage == 1:
                smap = {0: "pending", 1: "starting", 2: "running"}
                return MagicMock(status=smap[build_id], output="ok")
            elif self.stage == 2:
                smap = {0: "failed", 1: "running", 2: "succeeded"}
                return MagicMock(status=smap[build_id], output="ok")
            elif self.stage == 3:
                smap = {0: "failed", 1: "failed", 2: "succeeded"}
                return MagicMock(status=smap[build_id], output="ok")

        mock_time.sleep.side_effect = incr

        mock_client.get_build_details.side_effect = result_map
        mock_cc.create_from_file_config.return_value = mock_client

        with pytest.raises(SystemExit) as err:
            main.main(argv=[
                "build",
                "copr_name", "http://example.com/pkgs.srpm"
            ])

        stdout, stderr = capsys.readouterr()

        assert response_message in stdout
        assert "Created builds" in stdout
        assert "Watching build" in stdout
        assert "Build(s) 0, 1 failed" in stderr
        assert len(mock_time.sleep.call_args_list) == 3
Beispiel #51
0
def test_create_build_no_wait_error(mock_cc, capsys):
    response_message = "foobar"

    mock_client = MagicMock(no_config=False)
    mock_client.create_new_build.return_value = MagicMock(output="notok", error=response_message)

    mock_cc.create_from_file_config.return_value = mock_client

    main.main(argv=[
        "build", "--nowait",
        "copr_name", "http://example.com/pkgs.srpm"
    ])

    stdout, stderr = capsys.readouterr()
    assert response_message in stdout

    assert not mock_client._watch_build.called
Beispiel #52
0
def test_list_project(mock_cc, capsys):
    response_data = json.loads(read_res('list_projects_response.json'))
    expected_output = read_res('list_projects_expected.txt')

    # no config
    mock_cc.create_from_file_config.side_effect = CoprNoConfException()
    mocked_client = MagicMock(CoprClient(no_config=True))

    control_response = CoprResponse(client=None, method="", data=response_data,
                                    parsers=[ProjectListParser, CommonMsgErrorOutParser])
    mocked_client.get_projects_list.return_value = control_response
    mock_cc.return_value = mocked_client

    main.main(argv=["list", "rhscl"])

    out, err = capsys.readouterr()
    assert expected_output in out

    expected_warning = no_config_warning.format("~/.config/copr")
    assert expected_warning in out
Beispiel #53
0
def test_create_build_wait_keyboard_interrupt(mock_cc, capsys):
    response_message = "foobar"

    mock_client = MagicMock(no_config=False)
    mock_client.create_new_build.return_value = MagicMock(
        output="ok",
        message=response_message,
        builds_list=[
            MagicMock(build_id=x)
            for x in ["1", "2", "3"]
        ])
    mock_client.get_build_details.side_effect = KeyboardInterrupt

    mock_cc.create_from_file_config.return_value = mock_client

    main.main(argv=[
        "build",
        "copr_name", "http://example.com/pkgs.srpm"
    ])

    stdout, stderr = capsys.readouterr()
    assert response_message in stdout
    assert "Created builds" in stdout
    assert "Watching build" in stdout