Exemplo n.º 1
0
async def test_upload_large_file(aiohttp_test_client, loop):
    upload = partial(tus.upload,
                     file_name=TEST_SCREENSHOT_NAME,
                     chunk_size=TEST_CHUNK_SIZE)

    async with aiohttp_test_client(upload_url=TEST_UPLOAD_URL) as client:
        with open(TEST_SCREENSHOT_PATH, "rb") as handler:
            await loop.run_in_executor(None, upload, handler,
                                       get_upload_url(client, TEST_UPLOAD_URL))
Exemplo n.º 2
0
async def test_decorated_upload_200(aiohttp_test_client, loop):
    upload = partial(
        tus.upload,
        file_name=TEST_FILE_NAME,
        headers={"Authorization": "Token secret-token"},
    )

    async with aiohttp_test_client(upload_url=TEST_UPLOAD_URL,
                                   decorator=login_required) as client:
        with open(TEST_FILE_PATH, "rb") as handler:
            await loop.run_in_executor(None, upload, handler,
                                       get_upload_url(client, TEST_UPLOAD_URL))
Exemplo n.º 3
0
async def test_overwrite_file_allowed(aiohttp_test_client, loop):
    upload = partial(tus.upload, file_name=TEST_FILE_NAME)

    async with aiohttp_test_client(upload_url=TEST_UPLOAD_URL,
                                   allow_overwrite_files=True) as client:
        tus_upload_url = get_upload_url(client, TEST_UPLOAD_URL)

        with open(TEST_FILE_PATH, "rb") as handler:
            await loop.run_in_executor(None, upload, handler, tus_upload_url)

        with open(TEST_FILE_PATH, "rb") as handler:
            await loop.run_in_executor(None, upload, handler, tus_upload_url)
Exemplo n.º 4
0
async def test_on_upload_callback(aiohttp_test_client, loop):
    data = {}
    upload = partial(tus.upload, file_name=TEST_FILE_NAME)

    async def on_upload_done(request, resource, file_path):
        data[resource.file_name] = file_path

    async with aiohttp_test_client(upload_url=TEST_UPLOAD_URL,
                                   on_upload_done=on_upload_done) as client:
        with open(TEST_FILE_PATH, "rb") as handler:
            await loop.run_in_executor(None, upload, handler,
                                       get_upload_url(client, TEST_UPLOAD_URL))

    assert TEST_FILE_NAME in data
Exemplo n.º 5
0
async def test_upload(
    aiohttp_test_client,
    loop,
    upload_url,
    canonical_upload_url,
    upload_suffix,
    tus_upload_url,
    match_info,
):
    upload = partial(tus.upload, file_name=TEST_FILE_NAME)

    async with aiohttp_test_client(upload_url=upload_url,
                                   upload_suffix=upload_suffix) as client:
        with open(TEST_FILE_PATH, "rb") as handler:
            await loop.run_in_executor(None, upload, handler,
                                       get_upload_url(client, tus_upload_url))

        config: Config = client.app[APP_TUS_CONFIG_KEY][canonical_upload_url]
        expected_upload_path = config.resolve_upload_path(
            match_info) / TEST_FILE_NAME
        assert expected_upload_path.exists()
        assert expected_upload_path.read_bytes() == TEST_FILE_PATH.read_bytes()
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()