예제 #1
0
def test_search_no_repos(arg_parser, config, capsys, monkeypatch):
    monkeypatch.setattr(aptly_api.parts.repos.ReposAPISection, "list",
                        lambda *args: [])
    monkeypatch.setattr(aptly_api.parts.repos.ReposAPISection,
                        "search_packages", lambda *args: [])
    args = arg_parser.parse_args(["search", "python3.6"])
    with pytest.raises(aptly_ctl.exceptions.AptlyCtlError) as e:
        rc = search(config, args)
    stdout, _ = capsys.readouterr()
    assert stdout == ""
예제 #2
0
def test_search_in_one_repo(arg_parser, config, capsys, monkeypatch,
                            mocked_repos_list, mocked_repos_search_packages):
    monkeypatch.setattr(aptly_api.parts.repos.ReposAPISection, "list",
                        mocked_repos_list)
    monkeypatch.setattr(aptly_api.parts.repos.ReposAPISection,
                        "search_packages", mocked_repos_search_packages)
    args = arg_parser.parse_args(
        ["search", "-r", "stretch_main", "Name (% python3*)"])
    rc = search(config, args)
    stdout, _ = capsys.readouterr()
    assert rc == 0
    assert stdout == '"stretch_main/Pamd64 python3.6 3.6.7-1 656e12e8d5fa96a0"\n'
예제 #3
0
def test_search_multiple_queries(arg_parser, config, capsys, monkeypatch,
                                 mocked_repos_list,
                                 mocked_repos_search_packages):
    monkeypatch.setattr(aptly_api.parts.repos.ReposAPISection, "list",
                        mocked_repos_list)
    monkeypatch.setattr(aptly_api.parts.repos.ReposAPISection,
                        "search_packages", mocked_repos_search_packages)
    args = arg_parser.parse_args(["search", "python3.6", "aptly"])
    rc = search(config, args)
    stdout, _ = capsys.readouterr()
    assert rc == 0
    assert stdout == '"stretch_main/Pamd64 python3.6 3.6.7-1 656e12e8d5fa96a0"\n' + \
                    '"stretch_main/Pamd64 aptly 1.3.0+ds1-2 f7673868294f03c1"\n'
예제 #4
0
def test_search_non_existent_repo(arg_parser, config, capsys, monkeypatch,
                                  mocked_repos_list,
                                  mocked_repos_search_packages):
    monkeypatch.setattr(aptly_api.parts.repos.ReposAPISection, "list",
                        mocked_repos_list)
    monkeypatch.setattr(aptly_api.parts.repos.ReposAPISection,
                        "search_packages", mocked_repos_search_packages)
    args = arg_parser.parse_args(["search", "-r", "blabla", "python3.6"])
    with pytest.raises(aptly_ctl.exceptions.AptlyCtlError) as e:
        rc = search(config, args)
    stdout, _ = capsys.readouterr()
    assert stdout == ""
    assert e._excinfo[1].args[0].status_code == 404
    assert "local repo with name blabla not found" in e._excinfo[1].args[
        0].args[0].lower()
예제 #5
0
def test_search_name_search_shortcut(arg_parser, config, capsys, monkeypatch,
                                     mocked_repos_list,
                                     mocked_repos_search_packages):
    monkeypatch.setattr(aptly_api.parts.repos.ReposAPISection, "list",
                        mocked_repos_list)
    monkeypatch.setattr(aptly_api.parts.repos.ReposAPISection,
                        "search_packages", mocked_repos_search_packages)
    args = arg_parser.parse_args(["search", "-n", "python3.*"])
    rc = search(config, args)
    stdout, _ = capsys.readouterr()
    assert rc == 0
    assert stdout == '"stretch_extra/Pall python3-pip 9.0.1-2.3 52e9433afcb1e613"\n' + \
                    '"stretch_extra/Pall python3-wheel 0.30.0-0.2 dca6d5ca7e3f5e6f"\n' + \
                    '"stretch_main/Pamd64 python3.6 3.6.7-1 656e12e8d5fa96a0"\n' + \
                    '"stretch_nightly/Pall python3-setuptools 40.5.0-1 4d5a70b19b984324"\n'
예제 #6
0
def test_search_in_multiple_repos(arg_parser, config, capsys, monkeypatch,
                                  mocked_repos_list,
                                  mocked_repos_search_packages):
    monkeypatch.setattr(aptly_api.parts.repos.ReposAPISection, "list",
                        mocked_repos_list)
    monkeypatch.setattr(aptly_api.parts.repos.ReposAPISection,
                        "search_packages", mocked_repos_search_packages)
    args = arg_parser.parse_args([
        "search", "-r", "stretch_main", "-r", "stretch_nightly",
        "Name (% python3*)"
    ])
    rc = search(config, args)
    stdout, _ = capsys.readouterr()
    assert rc == 0
    assert stdout == '"stretch_main/Pamd64 python3.6 3.6.7-1 656e12e8d5fa96a0"\n' + \
                    '"stretch_nightly/Pall python3-setuptools 40.5.0-1 4d5a70b19b984324"\n'
예제 #7
0
def test_search_incorrect_query(arg_parser, config, capsys, monkeypatch,
                                mocked_repos_list):
    monkeypatch.setattr(aptly_api.parts.repos.ReposAPISection, "list",
                        mocked_repos_list)

    def mocked_repos_search_packages(*args):
        raise aptly_api.AptlyAPIException(
            "400 - Bad Request - parsing failed: unexpected token <EOL>: expecting ')'",
            status_code=400)

    monkeypatch.setattr(aptly_api.parts.repos.ReposAPISection,
                        "search_packages", mocked_repos_search_packages)
    args = arg_parser.parse_args(["search", "Name (~ python3.*"])
    with pytest.raises(aptly_ctl.exceptions.AptlyCtlError) as e:
        rc = search(config, args)
    stdout, _ = capsys.readouterr()
    assert stdout == ""
    assert 'Bad query "Name (~ python3.*": unexpected token <EOL>: expecting \')\'' in e._excinfo[
        1].args[0]