예제 #1
0
def test_main_reads_config_values(mirror_mock: mock.MagicMock,
                                  tmpdir: Path) -> None:
    base_config_path = Path(bandersnatch.__file__).parent / "unittest.conf"
    diff_file = Path(tempfile.gettempdir()) / "srv/pypi/mirrored-files"
    config_lines = [
        f"diff-file = {diff_file.as_posix()}\n"
        if line.startswith("diff-file") else line
        for line in base_config_path.read_text().splitlines()
    ]
    config_path = tmpdir / "unittest.conf"
    config_path.write_text("\n".join(config_lines), encoding="utf-8")
    sys.argv = ["bandersnatch", "-c", str(config_path), "mirror"]
    assert config_path.exists()
    main(asyncio.new_event_loop())
    (homedir, master), kwargs = mirror_mock.call_args_list[0]

    assert Path("/srv/pypi") == homedir
    assert isinstance(master, bandersnatch.master.Master)
    assert {
        "stop_on_error": False,
        "hash_index": False,
        "workers": 3,
        "root_uri": "",
        "json_save": False,
        "digest_name": "sha256",
        "keep_index_versions": 0,
        "release_files_save": True,
        "storage_backend": "filesystem",
        "diff_file": diff_file,
        "diff_append_epoch": False,
        "diff_full_path": diff_file,
        "cleanup": False,
        "compare_method": "hash",
    } == kwargs
예제 #2
0
def test_main_help(capfd):
    sys.argv = ["bandersnatch", "--help"]
    with pytest.raises(SystemExit):
        main(asyncio.new_event_loop())
    out, err = capfd.readouterr()
    assert out.startswith("usage: bandersnatch")
    assert "" == err
예제 #3
0
def test_main_reads_custom_config_values(mirror_mock, logging_mock, customconfig):
    conffile = str(customconfig / "bandersnatch.conf")
    sys.argv = ["bandersnatch", "-c", conffile, "mirror"]
    main()
    (log_config, kwargs) = logging_mock.call_args_list[0]
    assert log_config == (str(customconfig / "bandersnatch-log.conf"),)
    assert mirror_mock().synchronize.called
예제 #4
0
def test_main_help(capfd):
    sys.argv = ['bandersnatch', '--help']
    with pytest.raises(SystemExit):
        main()
    out, err = capfd.readouterr()
    assert out.startswith('usage: bandersnatch')
    assert '' == err
예제 #5
0
def test_main_create_config(caplog, tmpdir):
    sys.argv = ['bandersnatch', '-c', str(tmpdir / 'bandersnatch.conf'),
                'mirror']
    with pytest.raises(SystemExit):
        main()
    assert 'creating default config' in caplog.text()
    assert os.path.exists(str(tmpdir / 'bandersnatch.conf'))
예제 #6
0
def test_main_reads_custom_config_values(mirror_mock, logging_mock,
                                         customconfig):
    setup()
    conffile = str(customconfig / "bandersnatch.conf")
    sys.argv = ["bandersnatch", "-c", conffile, "mirror"]
    main(asyncio.new_event_loop())
    (log_config, _kwargs) = logging_mock.call_args_list[0]
    assert log_config == (str(customconfig / "bandersnatch-log.conf"), )
예제 #7
0
def test_main_reads_custom_config_values(
        mirror_mock, logging_mock, customconfig):
    conffile = str(customconfig / 'bandersnatch.conf')
    sys.argv = ['bandersnatch', '-c', conffile, 'mirror']
    main()
    (log_config, kwargs) = logging_mock.call_args_list[0]
    assert log_config == (str(customconfig / 'bandersnatch-log.conf'),)
    assert not mirror_mock.call_args[1]['delete_packages']
    assert mirror_mock().synchronize.called
예제 #8
0
def test_main_reads_config_values(mirror_mock):
    config = os.path.dirname(bandersnatch.__file__) + '/default.conf'
    sys.argv = ['bandersnatch', '-c', config, 'mirror']
    assert os.path.exists(config)
    assert isinstance(bandersnatch.mirror.Mirror, mock.Mock)
    main()
    (homedir, master), kwargs = mirror_mock.call_args_list[0]
    assert '/srv/pypi' == homedir
    assert isinstance(master, bandersnatch.master.Master)
    assert {'delete_packages': True,
            'stop_on_error': False,
            'workers': 3} == kwargs
    assert mirror_mock().synchronize.called
예제 #9
0
def test_main_throws_exception_on_unsupported_digest_name(customconfig):
    conffile = str(customconfig / "bandersnatch.conf")
    parser = configparser.ConfigParser()
    parser.read(conffile)
    parser["mirror"]["digest_name"] = "foobar"
    del parser["mirror"]["log-config"]
    with open(conffile, "w") as fp:
        parser.write(fp)
    sys.argv = ["bandersnatch", "-c", conffile, "mirror"]

    with pytest.raises(ValueError) as e:
        main()

    assert "foobar is not supported" in str(e.value)
예제 #10
0
def test_main_create_config(caplog, tmpdir):
    sys.argv = [
        "bandersnatch", "-c",
        str(tmpdir / "bandersnatch.conf"), "mirror"
    ]
    assert main() == 1
    assert "creating default config" in caplog.text
    assert os.path.exists(str(tmpdir / "bandersnatch.conf"))
예제 #11
0
def test_main_create_config(caplog, tmpdir):
    sys.argv = [
        "bandersnatch", "-c",
        str(tmpdir / "bandersnatch.conf"), "mirror"
    ]
    assert main(asyncio.new_event_loop()) == 1
    assert "creating default config" in caplog.text
    conf_path = Path(tmpdir) / "bandersnatch.conf"
    assert conf_path.exists()
예제 #12
0
def test_main_reads_config_values(mirror_mock):
    config = os.path.dirname(bandersnatch.__file__) + "/default.conf"
    sys.argv = ["bandersnatch", "-c", config, "mirror"]
    assert os.path.exists(config)
    assert isinstance(bandersnatch.mirror.Mirror, mock.Mock)
    main()
    (homedir, master), kwargs = mirror_mock.call_args_list[0]
    assert "/srv/pypi" == homedir
    assert isinstance(master, bandersnatch.master.Master)
    assert {
        "stop_on_error": False,
        "hash_index": False,
        "workers": 3,
        "root_uri": None,
        "json_save": False,
        "digest_name": "sha256",
    } == kwargs
    assert mirror_mock().synchronize.called
예제 #13
0
def test_main_cant_create_config(caplog, tmpdir):
    sys.argv = [
        "bandersnatch",
        "-c",
        str(tmpdir / "foo" / "bandersnatch.conf"),
        "mirror",
    ]
    assert main() == 1
    assert "creating default config" in caplog.text
    assert "Could not create config file" in caplog.text
    assert not os.path.exists(str(tmpdir / "bandersnatch.conf"))
예제 #14
0
def test_main_reads_config_values(mirror_mock: mock.MagicMock):
    config_path = Path(bandersnatch.__file__).parent / "unittest.conf"
    sys.argv = ["bandersnatch", "-c", str(config_path), "mirror"]
    assert config_path.exists()
    main(asyncio.new_event_loop())
    (homedir, master), kwargs = mirror_mock.call_args_list[0]

    assert "/srv/pypi" == homedir
    assert isinstance(master, bandersnatch.master.Master)
    assert {
        "stop_on_error": False,
        "hash_index": False,
        "workers": 3,
        "root_uri": "",
        "json_save": False,
        "digest_name": "sha256",
        "keep_index_versions": 0,
        "diff_file": "/tmp/pypi/mirrored-files",
        "diff_append_epoch": False,
        "diff_full_path": "/tmp/pypi/mirrored-files",
    } == kwargs
예제 #15
0
def test_main_cant_create_config(caplog: LogCaptureFixture,
                                 tmpdir: Path) -> None:
    sys.argv = [
        "bandersnatch",
        "-c",
        str(tmpdir / "foo" / "bandersnatch.conf"),
        "mirror",
    ]
    assert main(asyncio.new_event_loop()) == 1
    assert "creating default config" in caplog.text
    assert "Could not create config file" in caplog.text
    conf_path = Path(tmpdir) / "bandersnatch.conf"
    assert not conf_path.exists()