الميزات: إضافة أدوات جديدة لمعالجة ملفات PDF، تشمل التلخيص والترجمة واستخراج الجداول.
- تفعيل مكون SummarizePdf لإنشاء ملخصات PDF باستخدام الذكاء الاصطناعي. - تفعيل مكون TranslatePdf لترجمة محتوى PDF إلى لغات متعددة. - تفعيل مكون TableExtractor لاستخراج الجداول من ملفات PDF. - تحديث الصفحة الرئيسية والتوجيه ليشمل الأدوات الجديدة. - إضافة ترجمات للأدوات الجديدة باللغات الإنجليزية والعربية والفرنسية. - توسيع أنواع واجهة برمجة التطبيقات (API) لدعم الميزات الجديدة المتعلقة بمعالجة ملفات PDF. --feat: Initialize frontend with React, Vite, and Tailwind CSS - Set up main entry point for React application. - Create About, Home, NotFound, Privacy, and Terms pages with SEO support. - Implement API service for file uploads and task management. - Add global styles using Tailwind CSS. - Create utility functions for SEO and text processing. - Configure Vite for development and production builds. - Set up Nginx configuration for serving frontend and backend. - Add scripts for cleanup of expired files and sitemap generation. - Implement deployment script for production environment.
This commit is contained in:
78
backend/tests/test_compress_image.py
Normal file
78
backend/tests/test_compress_image.py
Normal file
@@ -0,0 +1,78 @@
|
||||
"""Tests for Compress Image endpoint — POST /api/image/compress."""
|
||||
import io
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
|
||||
class TestCompressImage:
|
||||
def test_no_file(self, client):
|
||||
"""Should return 400 when no file provided."""
|
||||
response = client.post('/api/image/compress')
|
||||
assert response.status_code == 400
|
||||
|
||||
def test_success(self, client, monkeypatch):
|
||||
"""Should return 202 with task_id on valid image upload."""
|
||||
mock_task = MagicMock()
|
||||
mock_task.id = 'compress-img-task-id'
|
||||
monkeypatch.setattr(
|
||||
'app.routes.compress_image.validate_actor_file',
|
||||
lambda f, allowed_types, actor: ('test.png', 'png'),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.routes.compress_image.generate_safe_path',
|
||||
lambda ext, folder_type: ('compress-img-task-id', '/tmp/mock.png'),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.routes.compress_image.compress_image_task.delay',
|
||||
MagicMock(return_value=mock_task),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'werkzeug.datastructures.file_storage.FileStorage.save',
|
||||
lambda self, dst, buffer_size=16384: None,
|
||||
)
|
||||
|
||||
from tests.conftest import make_png_bytes
|
||||
data = {
|
||||
'file': (io.BytesIO(make_png_bytes()), 'test.png'),
|
||||
'quality': '75',
|
||||
}
|
||||
response = client.post(
|
||||
'/api/image/compress',
|
||||
data=data,
|
||||
content_type='multipart/form-data',
|
||||
)
|
||||
assert response.status_code == 202
|
||||
json_data = response.get_json()
|
||||
assert 'task_id' in json_data
|
||||
|
||||
def test_invalid_quality(self, client, monkeypatch):
|
||||
"""Should clamp quality and still work."""
|
||||
mock_task = MagicMock()
|
||||
mock_task.id = 'compress-q-task-id'
|
||||
monkeypatch.setattr(
|
||||
'app.routes.compress_image.validate_actor_file',
|
||||
lambda f, allowed_types, actor: ('test.jpg', 'jpg'),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.routes.compress_image.generate_safe_path',
|
||||
lambda ext, folder_type: ('compress-q-task-id', '/tmp/mock.jpg'),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.routes.compress_image.compress_image_task.delay',
|
||||
MagicMock(return_value=mock_task),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'werkzeug.datastructures.file_storage.FileStorage.save',
|
||||
lambda self, dst, buffer_size=16384: None,
|
||||
)
|
||||
|
||||
from tests.conftest import make_jpeg_bytes
|
||||
data = {
|
||||
'file': (io.BytesIO(make_jpeg_bytes()), 'test.jpg'),
|
||||
'quality': '200', # should be clamped
|
||||
}
|
||||
response = client.post(
|
||||
'/api/image/compress',
|
||||
data=data,
|
||||
content_type='multipart/form-data',
|
||||
)
|
||||
assert response.status_code == 202
|
||||
Reference in New Issue
Block a user