async def test_verify_url_exception(tmp_path: Path) -> None: class FakeArgs: delete = True dry_run = False json_update = False workers = 2 fa = FakeArgs() fc = FakeConfig() master = Master(fc.get("mirror", "master")) url_fetch_404 = AsyncMock(side_effect=ClientResponseError( code=404, history=(), request_info=None)) master.url_fetch = url_fetch_404 # type: ignore jsonpath = tmp_path / "web" / "json" jsonpath.mkdir(parents=True, exist_ok=True) jsonfile = jsonpath / "bandersnatch" with jsonfile.open("w") as f: f.write( '{"releases":{"1.0":["url":"https://unittests.org/packages/a0/a0/a0a0/package-1.0.0.exe"}]}}' # noqa: E501 ) all_package_files: List[str] = [] await verify(master, fc, "bandersnatch", tmp_path, all_package_files, fa) # type: ignore # noqa: E501 assert jsonfile.exists() assert not all_package_files
async def test_get_latest_json_404(tmp_path: Path) -> None: class FakeArgs: delete = True dry_run = False json_update = True workers = 2 fa = FakeArgs() fc = FakeConfig() master = Master(fc.get("mirror", "master")) url_fetch_404 = AsyncMock(side_effect=ClientResponseError( code=404, history=(), request_info=None)) master.url_fetch = url_fetch_404 # type: ignore jsonpath = tmp_path / "web" / "json" jsonpath.mkdir(parents=True) jsonfile = jsonpath / "bandersnatch" jsonfile.touch() all_package_files: List[str] = [] await verify(master, fc, "bandersnatch", tmp_path, all_package_files, fa) # type: ignore # noqa: E501 assert not jsonfile.exists() assert not all_package_files
async def test_get_latest_json(monkeypatch: MonkeyPatch) -> None: config = FakeConfig() executor = ThreadPoolExecutor(max_workers=2) json_path = Path(gettempdir()) / f"unittest_{os.getpid()}.json" master = Master("https://unittest.org") master.url_fetch = do_nothing # type: ignore await get_latest_json(master, json_path, config, executor) # type: ignore
async def test_get_latest_json_timeout(tmp_path: Path) -> None: class FakeArgs: delete = True dry_run = False json_update = True workers = 2 fa = FakeArgs() fc = FakeConfig() master = Master(fc.get("mirror", "master")) url_fetch_timeout = AsyncMock(side_effect=ServerTimeoutError) master.url_fetch = url_fetch_timeout # type: ignore jsonpath = tmp_path / "web" / "json" jsonpath.mkdir(parents=True) jsonfile = jsonpath / "bandersnatch" jsonfile.touch() all_package_files: List[str] = [] await verify(master, fc, "bandersnatch", tmp_path, all_package_files, fa) # type: ignore # noqa: E501 assert jsonfile.exists() assert not all_package_files