الميزات: إضافة أدوات جديدة لمعالجة ملفات 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
|
||||
43
backend/tests/test_html_to_pdf.py
Normal file
43
backend/tests/test_html_to_pdf.py
Normal file
@@ -0,0 +1,43 @@
|
||||
"""Tests for HTML to PDF endpoint — POST /api/convert/html-to-pdf."""
|
||||
import io
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
|
||||
class TestHtmlToPdf:
|
||||
def test_no_file(self, client):
|
||||
"""Should return 400 when no file provided."""
|
||||
response = client.post('/api/convert/html-to-pdf')
|
||||
assert response.status_code == 400
|
||||
|
||||
def test_success(self, client, monkeypatch):
|
||||
"""Should return 202 with task_id on valid HTML upload."""
|
||||
mock_task = MagicMock()
|
||||
mock_task.id = 'html-pdf-task-id'
|
||||
monkeypatch.setattr(
|
||||
'app.routes.html_to_pdf.validate_actor_file',
|
||||
lambda f, allowed_types, actor: ('test.html', 'html'),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.routes.html_to_pdf.generate_safe_path',
|
||||
lambda ext, folder_type: ('html-pdf-task-id', '/tmp/mock.html'),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.routes.html_to_pdf.html_to_pdf_task.delay',
|
||||
MagicMock(return_value=mock_task),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'werkzeug.datastructures.file_storage.FileStorage.save',
|
||||
lambda self, dst, buffer_size=16384: None,
|
||||
)
|
||||
|
||||
data = {
|
||||
'file': (io.BytesIO(b'<html><body>Hello</body></html>'), 'test.html'),
|
||||
}
|
||||
response = client.post(
|
||||
'/api/convert/html-to-pdf',
|
||||
data=data,
|
||||
content_type='multipart/form-data',
|
||||
)
|
||||
assert response.status_code == 202
|
||||
json_data = response.get_json()
|
||||
assert 'task_id' in json_data
|
||||
134
backend/tests/test_pdf_ai.py
Normal file
134
backend/tests/test_pdf_ai.py
Normal file
@@ -0,0 +1,134 @@
|
||||
"""Tests for PDF AI endpoints — Chat, Summarize, Translate, Extract Tables."""
|
||||
import io
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
|
||||
def _mock_pdf_ai(monkeypatch, task_name):
|
||||
"""Helper to mock validate, path gen, and celery task for pdf_ai routes."""
|
||||
mock_task = MagicMock()
|
||||
mock_task.id = f'{task_name}-task-id'
|
||||
monkeypatch.setattr(
|
||||
'app.routes.pdf_ai.validate_actor_file',
|
||||
lambda f, allowed_types, actor: ('test.pdf', 'pdf'),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.routes.pdf_ai.generate_safe_path',
|
||||
lambda ext, folder_type: (f'{task_name}-task-id', '/tmp/mock.pdf'),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
f'app.routes.pdf_ai.{task_name}.delay',
|
||||
MagicMock(return_value=mock_task),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'werkzeug.datastructures.file_storage.FileStorage.save',
|
||||
lambda self, dst, buffer_size=16384: None,
|
||||
)
|
||||
return mock_task
|
||||
|
||||
|
||||
class TestChatPdf:
|
||||
def test_no_file(self, client):
|
||||
"""Should return 400 when no file provided."""
|
||||
response = client.post('/api/pdf-ai/chat')
|
||||
assert response.status_code == 400
|
||||
|
||||
def test_no_question(self, client, monkeypatch):
|
||||
"""Should return 400 when no question provided."""
|
||||
monkeypatch.setattr(
|
||||
'app.routes.pdf_ai.validate_actor_file',
|
||||
lambda f, allowed_types, actor: ('test.pdf', 'pdf'),
|
||||
)
|
||||
from tests.conftest import make_pdf_bytes
|
||||
data = {'file': (io.BytesIO(make_pdf_bytes()), 'test.pdf')}
|
||||
response = client.post(
|
||||
'/api/pdf-ai/chat',
|
||||
data=data,
|
||||
content_type='multipart/form-data',
|
||||
)
|
||||
assert response.status_code == 400
|
||||
|
||||
def test_success(self, client, monkeypatch):
|
||||
"""Should return 202 with task_id on valid request."""
|
||||
_mock_pdf_ai(monkeypatch, 'chat_with_pdf_task')
|
||||
|
||||
from tests.conftest import make_pdf_bytes
|
||||
data = {
|
||||
'file': (io.BytesIO(make_pdf_bytes()), 'test.pdf'),
|
||||
'question': 'What is this about?',
|
||||
}
|
||||
response = client.post(
|
||||
'/api/pdf-ai/chat',
|
||||
data=data,
|
||||
content_type='multipart/form-data',
|
||||
)
|
||||
assert response.status_code == 202
|
||||
assert 'task_id' in response.get_json()
|
||||
|
||||
|
||||
class TestSummarizePdf:
|
||||
def test_no_file(self, client):
|
||||
"""Should return 400 when no file provided."""
|
||||
response = client.post('/api/pdf-ai/summarize')
|
||||
assert response.status_code == 400
|
||||
|
||||
def test_success(self, client, monkeypatch):
|
||||
"""Should return 202 with task_id on valid request."""
|
||||
_mock_pdf_ai(monkeypatch, 'summarize_pdf_task')
|
||||
|
||||
from tests.conftest import make_pdf_bytes
|
||||
data = {
|
||||
'file': (io.BytesIO(make_pdf_bytes()), 'test.pdf'),
|
||||
'length': 'short',
|
||||
}
|
||||
response = client.post(
|
||||
'/api/pdf-ai/summarize',
|
||||
data=data,
|
||||
content_type='multipart/form-data',
|
||||
)
|
||||
assert response.status_code == 202
|
||||
assert 'task_id' in response.get_json()
|
||||
|
||||
|
||||
class TestTranslatePdf:
|
||||
def test_no_file(self, client):
|
||||
"""Should return 400 when no file provided."""
|
||||
response = client.post('/api/pdf-ai/translate')
|
||||
assert response.status_code == 400
|
||||
|
||||
def test_success(self, client, monkeypatch):
|
||||
"""Should return 202 with task_id on valid request."""
|
||||
_mock_pdf_ai(monkeypatch, 'translate_pdf_task')
|
||||
|
||||
from tests.conftest import make_pdf_bytes
|
||||
data = {
|
||||
'file': (io.BytesIO(make_pdf_bytes()), 'test.pdf'),
|
||||
'target_language': 'fr',
|
||||
}
|
||||
response = client.post(
|
||||
'/api/pdf-ai/translate',
|
||||
data=data,
|
||||
content_type='multipart/form-data',
|
||||
)
|
||||
assert response.status_code == 202
|
||||
assert 'task_id' in response.get_json()
|
||||
|
||||
|
||||
class TestExtractTables:
|
||||
def test_no_file(self, client):
|
||||
"""Should return 400 when no file provided."""
|
||||
response = client.post('/api/pdf-ai/extract-tables')
|
||||
assert response.status_code == 400
|
||||
|
||||
def test_success(self, client, monkeypatch):
|
||||
"""Should return 202 with task_id on valid request."""
|
||||
_mock_pdf_ai(monkeypatch, 'extract_tables_task')
|
||||
|
||||
from tests.conftest import make_pdf_bytes
|
||||
data = {'file': (io.BytesIO(make_pdf_bytes()), 'test.pdf')}
|
||||
response = client.post(
|
||||
'/api/pdf-ai/extract-tables',
|
||||
data=data,
|
||||
content_type='multipart/form-data',
|
||||
)
|
||||
assert response.status_code == 202
|
||||
assert 'task_id' in response.get_json()
|
||||
42
backend/tests/test_pdf_to_excel.py
Normal file
42
backend/tests/test_pdf_to_excel.py
Normal file
@@ -0,0 +1,42 @@
|
||||
"""Tests for PDF to Excel endpoint — POST /api/convert/pdf-to-excel."""
|
||||
import io
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
|
||||
class TestPdfToExcel:
|
||||
def test_no_file(self, client):
|
||||
"""Should return 400 when no file provided."""
|
||||
response = client.post('/api/convert/pdf-to-excel')
|
||||
assert response.status_code == 400
|
||||
|
||||
def test_success(self, client, monkeypatch):
|
||||
"""Should return 202 with task_id on valid PDF upload."""
|
||||
mock_task = MagicMock()
|
||||
mock_task.id = 'pdf-excel-task-id'
|
||||
monkeypatch.setattr(
|
||||
'app.routes.pdf_to_excel.validate_actor_file',
|
||||
lambda f, allowed_types, actor: ('test.pdf', 'pdf'),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.routes.pdf_to_excel.generate_safe_path',
|
||||
lambda ext, folder_type: ('pdf-excel-task-id', '/tmp/mock.pdf'),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.routes.pdf_to_excel.pdf_to_excel_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_pdf_bytes
|
||||
data = {'file': (io.BytesIO(make_pdf_bytes()), 'test.pdf')}
|
||||
response = client.post(
|
||||
'/api/convert/pdf-to-excel',
|
||||
data=data,
|
||||
content_type='multipart/form-data',
|
||||
)
|
||||
assert response.status_code == 202
|
||||
json_data = response.get_json()
|
||||
assert 'task_id' in json_data
|
||||
@@ -528,4 +528,107 @@ class TestUnlockPdf:
|
||||
data=data,
|
||||
content_type='multipart/form-data',
|
||||
)
|
||||
assert response.status_code == 202
|
||||
|
||||
|
||||
# =========================================================================
|
||||
# 9. Remove Watermark — POST /api/pdf-tools/remove-watermark
|
||||
# =========================================================================
|
||||
class TestRemoveWatermark:
|
||||
def test_no_file(self, client):
|
||||
"""Should return 400 when no file provided."""
|
||||
response = client.post('/api/pdf-tools/remove-watermark')
|
||||
assert response.status_code == 400
|
||||
|
||||
def test_success(self, client, monkeypatch):
|
||||
"""Should return 202 with task_id on valid PDF."""
|
||||
_mock_validate_and_task(
|
||||
monkeypatch, 'app.routes.pdf_tools', 'remove_watermark_task'
|
||||
)
|
||||
data = {'file': (io.BytesIO(b'%PDF-1.4'), 'test.pdf')}
|
||||
response = client.post(
|
||||
'/api/pdf-tools/remove-watermark',
|
||||
data=data,
|
||||
content_type='multipart/form-data',
|
||||
)
|
||||
assert response.status_code == 202
|
||||
|
||||
|
||||
# =========================================================================
|
||||
# 10. Reorder PDF — POST /api/pdf-tools/reorder
|
||||
# =========================================================================
|
||||
class TestReorderPdf:
|
||||
def test_no_file(self, client):
|
||||
"""Should return 400 when no file provided."""
|
||||
response = client.post('/api/pdf-tools/reorder')
|
||||
assert response.status_code == 400
|
||||
|
||||
def test_no_page_order(self, client, monkeypatch):
|
||||
"""Should return 400 when no page_order provided."""
|
||||
monkeypatch.setattr(
|
||||
'app.routes.pdf_tools.validate_actor_file',
|
||||
lambda f, allowed_types, actor: ('test.pdf', 'pdf'),
|
||||
)
|
||||
data = {'file': (io.BytesIO(b'%PDF-1.4'), 'test.pdf')}
|
||||
response = client.post(
|
||||
'/api/pdf-tools/reorder',
|
||||
data=data,
|
||||
content_type='multipart/form-data',
|
||||
)
|
||||
assert response.status_code == 400
|
||||
|
||||
def test_success(self, client, monkeypatch):
|
||||
"""Should return 202 with task_id on valid request."""
|
||||
_mock_validate_and_task(
|
||||
monkeypatch, 'app.routes.pdf_tools', 'reorder_pdf_task'
|
||||
)
|
||||
data = {
|
||||
'file': (io.BytesIO(b'%PDF-1.4'), 'test.pdf'),
|
||||
'page_order': '3,1,2',
|
||||
}
|
||||
response = client.post(
|
||||
'/api/pdf-tools/reorder',
|
||||
data=data,
|
||||
content_type='multipart/form-data',
|
||||
)
|
||||
assert response.status_code == 202
|
||||
|
||||
|
||||
# =========================================================================
|
||||
# 11. Extract Pages — POST /api/pdf-tools/extract-pages
|
||||
# =========================================================================
|
||||
class TestExtractPages:
|
||||
def test_no_file(self, client):
|
||||
"""Should return 400 when no file provided."""
|
||||
response = client.post('/api/pdf-tools/extract-pages')
|
||||
assert response.status_code == 400
|
||||
|
||||
def test_no_pages(self, client, monkeypatch):
|
||||
"""Should return 400 when no pages param provided."""
|
||||
monkeypatch.setattr(
|
||||
'app.routes.pdf_tools.validate_actor_file',
|
||||
lambda f, allowed_types, actor: ('test.pdf', 'pdf'),
|
||||
)
|
||||
data = {'file': (io.BytesIO(b'%PDF-1.4'), 'test.pdf')}
|
||||
response = client.post(
|
||||
'/api/pdf-tools/extract-pages',
|
||||
data=data,
|
||||
content_type='multipart/form-data',
|
||||
)
|
||||
assert response.status_code == 400
|
||||
|
||||
def test_success(self, client, monkeypatch):
|
||||
"""Should return 202 with task_id on valid request."""
|
||||
_mock_validate_and_task(
|
||||
monkeypatch, 'app.routes.pdf_tools', 'extract_pages_task'
|
||||
)
|
||||
data = {
|
||||
'file': (io.BytesIO(b'%PDF-1.4'), 'test.pdf'),
|
||||
'pages': '1,3,5-8',
|
||||
}
|
||||
response = client.post(
|
||||
'/api/pdf-tools/extract-pages',
|
||||
data=data,
|
||||
content_type='multipart/form-data',
|
||||
)
|
||||
assert response.status_code == 202
|
||||
57
backend/tests/test_qrcode.py
Normal file
57
backend/tests/test_qrcode.py
Normal file
@@ -0,0 +1,57 @@
|
||||
"""Tests for QR Code Generator endpoint — POST /api/qrcode/generate."""
|
||||
import json
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
|
||||
class TestQrCodeGenerator:
|
||||
def test_no_data(self, client):
|
||||
"""Should return 400 when no data provided."""
|
||||
response = client.post(
|
||||
'/api/qrcode/generate',
|
||||
data=json.dumps({}),
|
||||
content_type='application/json',
|
||||
)
|
||||
assert response.status_code == 400
|
||||
|
||||
def test_success_json(self, client, monkeypatch):
|
||||
"""Should return 202 with task_id on valid JSON request."""
|
||||
mock_task = MagicMock()
|
||||
mock_task.id = 'qr-task-id'
|
||||
monkeypatch.setattr(
|
||||
'app.routes.qrcode.generate_qr_task',
|
||||
MagicMock(delay=MagicMock(return_value=mock_task)),
|
||||
)
|
||||
|
||||
response = client.post(
|
||||
'/api/qrcode/generate',
|
||||
data=json.dumps({'data': 'https://example.com', 'size': 300}),
|
||||
content_type='application/json',
|
||||
)
|
||||
assert response.status_code == 202
|
||||
json_data = response.get_json()
|
||||
assert 'task_id' in json_data
|
||||
|
||||
def test_success_form_data(self, client, monkeypatch):
|
||||
"""Should return 202 with task_id on valid form-data request."""
|
||||
mock_task = MagicMock()
|
||||
mock_task.id = 'qr-form-task-id'
|
||||
monkeypatch.setattr(
|
||||
'app.routes.qrcode.generate_qr_task',
|
||||
MagicMock(delay=MagicMock(return_value=mock_task)),
|
||||
)
|
||||
|
||||
response = client.post(
|
||||
'/api/qrcode/generate',
|
||||
data={'data': 'Hello World'},
|
||||
content_type='multipart/form-data',
|
||||
)
|
||||
assert response.status_code == 202
|
||||
|
||||
def test_empty_data(self, client):
|
||||
"""Should return 400 when data field is empty string."""
|
||||
response = client.post(
|
||||
'/api/qrcode/generate',
|
||||
data=json.dumps({'data': ''}),
|
||||
content_type='application/json',
|
||||
)
|
||||
assert response.status_code == 400
|
||||
Reference in New Issue
Block a user