Пример #1
0
async def test_mirror_sync_package_download_mirror_fails(
    mirror: BandersnatchMirror,
) -> None:
    mirror.master.all_packages = mock.AsyncMock(return_value={"foo": 1})  # type: ignore
    mirror.json_save = True
    # Recall bootstrap so we have the json dirs
    mirror._bootstrap()
    # This download mirror URL does not work, forcing not to fallback
    mirror.download_mirror = "https://not-working.example.com"
    mirror.download_mirror_no_fallback = True

    with mock.patch("bandersnatch.mirror.logger.exception") as mock_log:
        await mirror.synchronize()
        # 3 calls are:
        # * Tried and failed to get /packages/any/f/foo/foo.zip
        # * Tried and failed to get /packages/2.7/f/foo/foo.whl
        # * Declared error on syncing package foo@1
        assert mock_log.call_count == 3
Пример #2
0
async def test_mirror_sync_package_download_mirror(
    mirror: BandersnatchMirror,
) -> None:
    mirror.master.all_packages = mock.AsyncMock(return_value={"foo": 1})  # type: ignore
    mirror.json_save = True
    # Recall bootstrap so we have the json dirs
    mirror._bootstrap()
    # This download mirror URL works, forcing not to fallback
    mirror.download_mirror = "https://pypi-mirror.example.com/pypi"
    mirror.download_mirror_no_fallback = True
    await mirror.synchronize()

    assert """\
json{0}foo
last-modified
packages{0}2.7{0}f{0}foo{0}foo.whl
packages{0}any{0}f{0}foo{0}foo.zip
pypi{0}foo{0}json
simple{0}foo{0}index.html
simple{0}index.html""".format(
        sep
    ) == utils.find(
        mirror.webdir, dirs=False
    )
    assert (
        open("web{0}simple{0}index.html".format(sep)).read()
        == """\
<!DOCTYPE html>
<html>
  <head>
    <title>Simple Index</title>
  </head>
  <body>
    <a href="foo/">foo</a><br/>
  </body>
</html>"""
    )
    assert open("status", "rb").read() == b"1"