Add comprehensive test suite for image processing and related services
- Implement tests for database generator to ensure proper session handling. - Create tests for EXIF extraction and conversion functions. - Add tests for image-related endpoints, ensuring proper data retrieval and isolation between clients. - Develop tests for OCR functionality, including language detection and text extraction. - Introduce tests for the image processing pipeline, covering success and failure scenarios. - Validate rate limiting functionality and ensure independent counters for different clients. - Implement scraper tests to verify HTML content fetching and error handling. - Add unit tests for various services, including storage and filename generation. - Establish worker entry point for ARQ to handle background image processing tasks.
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
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("/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("/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("/ai/draft-task", json={"description": "test"}, headers=auth_headers_a)
|
||||
assert response.status_code == 503
|
||||
assert response.json()["detail"] == "AI désactivée"
|
||||
Reference in New Issue
Block a user