2025-02-04 19:18:58 -03:00
|
|
|
from io import BytesIO
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
from urllib3.util import parse_url
|
|
|
|
|
|
|
|
|
|
from benchmarks.codex.client.async_client import AsyncCodexClientImpl
|
|
|
|
|
from benchmarks.core.utils.random import random_data
|
|
|
|
|
from benchmarks.core.utils.units import megabytes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.codex_integration
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
|
async def test_should_upload_file(codex_node_1_url: str):
|
|
|
|
|
client = AsyncCodexClientImpl(parse_url(codex_node_1_url))
|
|
|
|
|
|
|
|
|
|
data = BytesIO()
|
|
|
|
|
random_data(megabytes(1), data)
|
|
|
|
|
|
2025-04-16 12:56:34 -03:00
|
|
|
cid = client.upload(
|
|
|
|
|
"test.txt", "application/octet-stream", BytesIO(data.getvalue())
|
|
|
|
|
)
|
2025-02-04 19:18:58 -03:00
|
|
|
assert cid is not None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.codex_integration
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
|
async def test_should_download_file(codex_node_1_url: str):
|
|
|
|
|
client = AsyncCodexClientImpl(parse_url(codex_node_1_url))
|
|
|
|
|
|
2025-04-16 12:56:34 -03:00
|
|
|
data = BytesIO()
|
|
|
|
|
random_data(megabytes(1), data)
|
2025-02-04 19:18:58 -03:00
|
|
|
|
2025-04-16 12:56:34 -03:00
|
|
|
cid = await client.upload(
|
|
|
|
|
"test.txt", "application/octet-stream", BytesIO(data.getvalue())
|
|
|
|
|
)
|
2025-02-04 19:18:58 -03:00
|
|
|
assert cid is not None
|
|
|
|
|
|
|
|
|
|
async with client.download(cid) as content:
|
|
|
|
|
downloaded = await content.readexactly(megabytes(1))
|
|
|
|
|
|
2025-04-16 12:56:34 -03:00
|
|
|
assert downloaded == data.getvalue()
|