示例#1
0
async def test_keep_index_versions_stores_different_prior_versions(
    mirror: Mirror, ) -> None:
    simple_path = Path("web/simple/foo")
    versions_path = simple_path / "versions"
    mirror.packages_to_sync = {"foo": 1}
    mirror.keep_index_versions = 2

    with freeze_time("2018-10-27"):
        package = Package("foo", 1, mirror)
        await package.sync(mirror.filters)
        assert not mirror.errors

    mirror.packages_to_sync = {"foo": 1}
    with freeze_time("2018-10-28"):
        package = Package("foo", 1, mirror)
        await package.sync(mirror.filters)
        assert not mirror.errors

    version_files = sorted(os.listdir(versions_path))
    assert len(version_files) == 2
    assert version_files[0].startswith("index_1_2018-10-27")
    assert version_files[1].startswith("index_1_2018-10-28")
    link_path = simple_path / "index.html"
    assert os.path.islink(link_path)
    assert os.path.basename(os.readlink(str(link_path))) == version_files[1]
示例#2
0
async def test_keep_index_versions_stores_one_prior_version(
        mirror: Mirror) -> None:
    mirror.packages_to_sync = {"foo": ""}
    mirror.keep_index_versions = 1
    package = Package("foo", 1, mirror)
    await package.sync(mirror.filters)
    assert not mirror.errors

    simple_path = Path("web/simple/foo")
    versions_path = simple_path / "versions"
    version_files = os.listdir(versions_path)
    assert len(version_files) == 1
    assert version_files[
        0] == f"index_{package.serial}_{make_time_stamp()}.html"
    link_path = simple_path / "index.html"
    assert link_path.is_symlink()
    assert os.path.basename(os.readlink(str(link_path))) == version_files[0]
示例#3
0
async def test_keep_index_versions_removes_old_versions(
        mirror: Mirror) -> None:
    simple_path = Path("web/simple/foo/")
    versions_path = simple_path / "versions"
    versions_path.mkdir(parents=True)
    (versions_path / "index_1_2018-10-26T000000Z.html").touch()
    (versions_path / "index_1_2018-10-27T000000Z.html").touch()

    mirror.keep_index_versions = 2
    with freeze_time("2018-10-28"):
        package = Package("foo", 1, mirror)
        await package.sync(mirror.filters)

    version_files = sorted(f for f in versions_path.iterdir())
    assert len(version_files) == 2
    assert version_files[0].name.startswith("index_1_2018-10-27")
    assert version_files[1].name.startswith("index_1_2018-10-28")
    link_path = simple_path / "index.html"
    assert link_path.is_symlink()
    assert os.path.basename(os.readlink(
        str(link_path))) == version_files[1].name