async def factory() -> TestClient: return await aiohttp_client( setup_tus( web.Application(), upload_path=TEST_UPLOAD_PATH, upload_url=TEST_UPLOAD_URL, ))
def create_app(argv: List[str] = None) -> web.Application: upload_path = Path(tempfile.gettempdir()) / "aiohttp-tus-app-uploads" upload_path.mkdir(mode=0o755, exist_ok=True) print("aiohttp_tus test app") print(f"Uploading files to {upload_path.absolute()}\n") app = setup_tus(web.Application(), upload_path=upload_path) app["aiohttp_tus_upload_path"] = upload_path app.on_shutdown.append(remove_upload_path) return app
async def test_mutltiple_tus_upload_urls(aiohttp_client, loop): upload = partial(tus.upload, file_name=TEST_FILE_NAME) with tempfile.TemporaryDirectory(prefix="aiohttp_tus") as temp_path: base_path = Path(temp_path) app = web.Application() for idx in range(1, NUMBER + 1): setup_tus(app, upload_path=base_path / str(idx), upload_url=f"/{idx}/uploads") client = await aiohttp_client(app) for idx in range(1, NUMBER + 1): with open(TEST_FILE_PATH, "rb") as handler: await loop.run_in_executor( None, upload, handler, get_upload_url(client, f"/{idx}/uploads")) expected_path = base_path / str(idx) / TEST_FILE_NAME assert expected_path.exists() assert expected_path.read_bytes() == TEST_FILE_PATH.read_bytes()
def create_app(argv: List[str] = None) -> web.Application: upload_path = Path(tempfile.gettempdir()) / "aiohttp-tus-example-uploads" upload_path.mkdir(mode=0o755, exist_ok=True) app = setup_tus( web.Application(client_max_size=get_client_max_size()), upload_path=upload_path, ) app[APP_UPLOAD_PATH_KEY] = upload_path setup_jinja2(app, loader=jinja2.FileSystemLoader( Path(__file__).parent / "templates")) app.router.add_get("/", views.index) app.on_shutdown.append(remove_upload_path) print("aiohttp-tus example app") print(f"Uploading files to {upload_path.absolute()}\n") return app
async def factory( *, upload_url: str, upload_suffix: str = None, allow_overwrite_files: bool = False, on_upload_done: ResourceCallback = None, decorator: Decorator = None, ) -> TestClient: with tempfile.TemporaryDirectory(prefix="aiohttp_tus") as temp_path: base_path = Path(temp_path) app = setup_tus( web.Application(), upload_path=base_path / upload_suffix if upload_suffix else base_path, upload_url=upload_url, allow_overwrite_files=allow_overwrite_files, on_upload_done=on_upload_done, decorator=decorator, ) yield await aiohttp_client(app)