35 lines
1.5 KiB
Python
35 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test the upload and job processing flow
|
|
"""
|
|
import sys
|
|
import os
|
|
sys.path.append(os.path.dirname(__file__))
|
|
|
|
from pdf_renamer import app, job_queue
|
|
import tempfile
|
|
import uuid
|
|
from werkzeug.datastructures import FileStorage
|
|
import io
|
|
|
|
# Create a simple PDF-like content (not a real PDF, but enough for testing)
|
|
pdf_content = b"%PDF-1.4\n1 0 obj\n<<\n/Type /Catalog\n/Pages 2 0 R\n>>\nendobj\n2 0 obj\n<<\n/Type /Pages\n/Kids [3 0 R]\n/Count 1\n>>\nendobj\n3 0 obj\n<<\n/Type /Page\n/Parent 2 0 R\n/MediaBox [0 0 612 792]\n/Contents 4 0 R\n>>\nendobj\n4 0 obj\n<<\n/Length 44\n>>\nstream\nBT\n/F1 12 Tf\n100 700 Td\n(Test PDF) Tj\nET\nendstream\nendobj\nxref\n0 5\n0000000000 65535 f\n0000000009 00000 n\n0000000058 00000 n\n0000000115 00000 n\n0000000200 00000 n\ntrailer\n<<\n/Size 5\n/Root 1 0 R\n>>\nstartxref\n284\n%%EOF"
|
|
|
|
with app.test_client() as client:
|
|
with app.app_context():
|
|
# Create a test file
|
|
file_data = io.BytesIO(pdf_content)
|
|
file_data.filename = 'test.pdf'
|
|
|
|
# Simulate file upload
|
|
response = client.post('/', data={
|
|
'files': (file_data, 'test.pdf')
|
|
}, content_type='multipart/form-data')
|
|
|
|
print(f"Upload response status: {response.status_code}")
|
|
print(f"Response data: {response.get_data(as_text=True)}")
|
|
|
|
# Check if any jobs were created
|
|
print(f"Current jobs: {list(job_queue.keys())}")
|
|
for job_id, job in job_queue.items():
|
|
print(f"Job {job_id}: status={job.get('status')}, files={len(job.get('files', []))}") |