Files
Imago/tests/test_ai_extended.py
T
bruno 2f2a5e9b4a
CI / Lint & Format (push) Failing after 28s
CI / Tests (push) Has been skipped
CI / Security Scan (push) Failing after 8s
CI / Docker Build (push) Has been skipped
Add admin panel, WebSocket support, and API versioning
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.
2026-06-22 11:25:22 -04:00

58 lines
2.3 KiB
Python

import pytest
from httpx import AsyncClient
from unittest.mock import patch, MagicMock
@pytest.mark.asyncio
async def test_ai_summarize(async_client: AsyncClient, client_a, auth_headers_a):
mock_page = {
"title": "Example Title",
"description": "Example Description",
"text": "Example Text content for the page.",
}
mock_ai_result = {
"summary": "This is a summary.",
"tags": ["tag1", "tag2"],
"model": "gemini-1.5-flash"
}
with patch("app.routers.ai.fetch_page_content", return_value=mock_page), \
patch("app.routers.ai.summarize_url", return_value=mock_ai_result), \
patch("app.routers.ai.settings.AI_ENABLED", True):
payload = {"url": "https://example.com", "language": "français"}
response = await async_client.post("/api/v1/ai/summarize", json=payload, headers=auth_headers_a)
assert response.status_code == 200
data = response.json()
assert data["summary"] == "This is a summary."
assert "tag1" in data["tags"]
assert data["title"] == "Example Title"
@pytest.mark.asyncio
async def test_ai_draft_task(async_client: AsyncClient, client_a, auth_headers_a):
mock_task = {
"title": "Fix Bug",
"description": "Fix the bug in the code",
"steps": ["Step 1", "Step 2"],
"priority": "high",
"estimated_time": "1h"
}
with patch("app.routers.ai.draft_task", return_value=mock_task), \
patch("app.routers.ai.settings.AI_ENABLED", True):
payload = {"description": "Fix bug", "context": "Backend project"}
response = await async_client.post("/api/v1/ai/draft-task", json=payload, headers=auth_headers_a)
assert response.status_code == 200
data = response.json()
assert data["title"] == "Fix Bug"
assert data["priority"] == "high"
@pytest.mark.asyncio
async def test_ai_disabled(async_client: AsyncClient, client_a, auth_headers_a):
with patch("app.routers.ai.settings.AI_ENABLED", False):
response = await async_client.post("/api/v1/ai/draft-task", json={"description": "test"}, headers=auth_headers_a)
assert response.status_code == 503
assert response.json()["detail"] == "AI désactivée"