Introduce an admin portal (React + Nginx), WebSocket routing, and API versioning middleware with `/api/v1/` prefix deprecation. Add master API key authentication, new Prometheus metrics for AI token consumption and active WebSockets, and extend S3 config with a public endpoint URL. Update test paths and fixtures to align with the new routing structure.
77 lines
2.1 KiB
Python
77 lines
2.1 KiB
Python
import pytest
|
|
import respx
|
|
from httpx import Response
|
|
|
|
from imago_client import HubClient, HubImage
|
|
|
|
@pytest.fixture
|
|
def base_url():
|
|
return "http://testserver"
|
|
|
|
@pytest.fixture
|
|
def api_key():
|
|
return "sk-test-key"
|
|
|
|
@pytest.mark.asyncio
|
|
@respx.mock
|
|
async def test_get_image(base_url, api_key):
|
|
mock_data = {
|
|
"id": 1,
|
|
"uuid": "fake-uuid",
|
|
"original_name": "test.jpg",
|
|
"processing_status": "done"
|
|
}
|
|
respx.get(f"{base_url}/api/v1/images/1").mock(return_value=Response(200, json=mock_data))
|
|
|
|
async with HubClient(base_url, api_key=api_key) as client:
|
|
img = await client.images.get(1)
|
|
|
|
assert isinstance(img, HubImage)
|
|
assert img.id == 1
|
|
assert img.uuid == "fake-uuid"
|
|
assert img.processing_status == "done"
|
|
assert img.original_name == "test.jpg"
|
|
|
|
@pytest.mark.asyncio
|
|
@respx.mock
|
|
async def test_upload_image(base_url, api_key):
|
|
mock_data = {
|
|
"id": 2,
|
|
"uuid": "new-uuid",
|
|
"original_name": "upload.jpg",
|
|
"processing_status": "pending"
|
|
}
|
|
respx.post(f"{base_url}/api/v1/images/upload").mock(return_value=Response(200, json=mock_data))
|
|
|
|
async with HubClient(base_url, api_key=api_key) as client:
|
|
img = await client.images.upload(b"fakebytes", "upload.jpg", "image/jpeg")
|
|
|
|
assert isinstance(img, HubImage)
|
|
assert img.id == 2
|
|
assert img.processing_status == "pending"
|
|
|
|
@pytest.mark.asyncio
|
|
@respx.mock
|
|
async def test_list_images(base_url, api_key):
|
|
mock_response = {
|
|
"total": 1,
|
|
"page": 1,
|
|
"size": 50,
|
|
"items": [
|
|
{
|
|
"id": 1,
|
|
"uuid": "fake-uuid",
|
|
"original_name": "test.jpg",
|
|
"processing_status": "done"
|
|
}
|
|
]
|
|
}
|
|
respx.get(f"{base_url}/api/v1/images?page=1&size=50").mock(return_value=Response(200, json=mock_response))
|
|
|
|
async with HubClient(base_url, api_key=api_key) as client:
|
|
result = await client.images.list()
|
|
|
|
assert result["total"] == 1
|
|
assert len(result["items"]) == 1
|
|
assert result["items"][0]["id"] == 1
|