Skip to content

Latest commit

 

History

History
741 lines (550 loc) · 15.2 KB

File metadata and controls

741 lines (550 loc) · 15.2 KB

PDF Editor Testing Guide

This guide provides instructions for testing all features of the PDF Editor application.

Prerequisites

  1. Backend services running (PostgreSQL, Redis, Flask)
  2. Test PDF files
  3. cURL or Postman for API testing
  4. Optional: Python requests library for scripted tests

Setup Test Environment

# Start all services
docker-compose up -d

# Verify services are healthy
curl http://localhost:5000/health

# Expected response:
# {"status":"healthy","database":"connected","redis":"connected"}

Test Data Preparation

Create a test directory with sample PDFs:

mkdir test_files
# Add sample PDF files: test1.pdf, test2.pdf, test3.pdf

1. Authentication Tests

Test User Registration

curl -X POST http://localhost:5000/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "username": "testuser",
    "email": "test@example.com",
    "password": "testpass123"
  }'

Expected: 201 status, user object with access_token

Test User Login

curl -X POST http://localhost:5000/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "username": "testuser",
    "password": "testpass123"
  }'

Expected: 200 status, user object with access_token

Save the token for subsequent tests:

export TOKEN="your_access_token_here"

Test Get Current User

curl -X GET http://localhost:5000/api/auth/me \
  -H "Authorization: Bearer $TOKEN"

Expected: 200 status, user object


2. Document Upload Tests

Test PDF Upload

curl -X POST http://localhost:5000/api/upload \
  -H "Authorization: Bearer $TOKEN" \
  -F "file=@test_files/test1.pdf"

Expected: 201 status, document object with metadata

Save document ID:

export DOC1_ID="document_id_from_response"

Test Multiple Uploads

# Upload second document
curl -X POST http://localhost:5000/api/upload \
  -H "Authorization: Bearer $TOKEN" \
  -F "file=@test_files/test2.pdf"

export DOC2_ID="document_id_from_response"

# Upload third document
curl -X POST http://localhost:5000/api/upload \
  -H "Authorization: Bearer $TOKEN" \
  -F "file=@test_files/test3.pdf"

export DOC3_ID="document_id_from_response"

Test Invalid Upload (Non-PDF)

curl -X POST http://localhost:5000/api/upload \
  -H "Authorization: Bearer $TOKEN" \
  -F "file=@test_files/image.jpg"

Expected: 400 status, error message


3. Document Management Tests

Test List Documents

curl -X GET http://localhost:5000/api/documents \
  -H "Authorization: Bearer $TOKEN"

Expected: 200 status, array of documents

Test Search Documents

curl -X GET "http://localhost:5000/api/documents?search=test" \
  -H "Authorization: Bearer $TOKEN"

Expected: 200 status, filtered documents

Test Sort Documents

# Sort by size
curl -X GET "http://localhost:5000/api/documents?sort_by=size&sort_order=desc" \
  -H "Authorization: Bearer $TOKEN"

# Sort by name
curl -X GET "http://localhost:5000/api/documents?sort_by=name&sort_order=asc" \
  -H "Authorization: Bearer $TOKEN"

Test Get Document Details

curl -X GET http://localhost:5000/api/documents/$DOC1_ID \
  -H "Authorization: Bearer $TOKEN"

Expected: 200 status, document object

Test Update Document (Rename)

curl -X PUT http://localhost:5000/api/documents/$DOC1_ID \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "original_filename": "renamed_document.pdf",
    "metadata": {
      "title": "Test Document",
      "author": "Test Author"
    }
  }'

Expected: 200 status, updated document

Test Download Document

curl -X GET http://localhost:5000/api/documents/$DOC1_ID/download \
  -H "Authorization: Bearer $TOKEN" \
  -o downloaded.pdf

Expected: PDF file downloaded

Test Document Statistics

curl -X GET http://localhost:5000/api/documents/stats \
  -H "Authorization: Bearer $TOKEN"

Expected: 200 status, statistics object

Test Get Thumbnail

curl -X GET "http://localhost:5000/api/documents/$DOC1_ID/thumbnail?page=1" \
  -H "Authorization: Bearer $TOKEN" \
  -o thumbnail.png

Expected: PNG image file


4. Core PDF Operations Tests

Test Merge PDFs

curl -X POST http://localhost:5000/api/merge \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d "{
    \"document_ids\": [\"$DOC1_ID\", \"$DOC2_ID\"]
  }"

Expected: 201 status, merged document

Save merged document ID:

export MERGED_ID="merged_document_id"

Test Split PDF

curl -X POST http://localhost:5000/api/split \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d "{
    \"document_id\": \"$MERGED_ID\",
    \"pages\": [1, 2, 3]
  }"

Expected: 201 status, split document

Test Rotate PDF

# Rotate all pages
curl -X POST http://localhost:5000/api/rotate \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d "{
    \"document_id\": \"$DOC1_ID\",
    \"rotation\": 90,
    \"pages\": \"all\"
  }"

# Rotate specific pages
curl -X POST http://localhost:5000/api/rotate \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d "{
    \"document_id\": \"$DOC2_ID\",
    \"rotation\": 180,
    \"pages\": [1, 3]
  }"

Expected: 201 status, rotated document

Test Reorder Pages

curl -X POST http://localhost:5000/api/reorder \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d "{
    \"document_id\": \"$MERGED_ID\",
    \"page_order\": [3, 1, 2, 5, 4]
  }"

Expected: 201 status, reordered document


5. Advanced Operations Tests

Test Add Watermark

# Center watermark
curl -X POST http://localhost:5000/api/watermark \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d "{
    \"document_id\": \"$DOC1_ID\",
    \"text\": \"CONFIDENTIAL\",
    \"opacity\": 0.3,
    \"position\": \"center\"
  }"

# Diagonal watermark
curl -X POST http://localhost:5000/api/watermark \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d "{
    \"document_id\": \"$DOC2_ID\",
    \"text\": \"DRAFT\",
    \"opacity\": 0.5,
    \"position\": \"diagonal\"
  }"

Expected: 201 status, watermarked document

Test Encrypt PDF

curl -X POST http://localhost:5000/api/encrypt \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d "{
    \"document_id\": \"$DOC1_ID\",
    \"password\": \"secret123\"
  }"

Expected: 201 status, encrypted document

Save encrypted document ID:

export ENCRYPTED_ID="encrypted_document_id"

Test Decrypt PDF

curl -X POST http://localhost:5000/api/decrypt \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d "{
    \"document_id\": \"$ENCRYPTED_ID\",
    \"password\": \"secret123\"
  }"

Expected: 201 status, decrypted document

Test Compress PDF

# Low quality (high compression)
curl -X POST http://localhost:5000/api/compress \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d "{
    \"document_id\": \"$DOC1_ID\",
    \"quality\": \"low\"
  }"

# Medium quality
curl -X POST http://localhost:5000/api/compress \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d "{
    \"document_id\": \"$DOC2_ID\",
    \"quality\": \"medium\"
  }"

# High quality (low compression)
curl -X POST http://localhost:5000/api/compress \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d "{
    \"document_id\": \"$DOC3_ID\",
    \"quality\": \"high\"
  }"

Expected: 201 status, compressed document with compression_ratio

Test PDF to Images

curl -X POST http://localhost:5000/api/pdf-to-images \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d "{
    \"document_id\": \"$DOC1_ID\",
    \"dpi\": 200,
    \"format\": \"png\"
  }"

Expected: 201 status, array of image paths

Test Images to PDF

curl -X POST http://localhost:5000/api/images-to-pdf \
  -H "Authorization: Bearer $TOKEN" \
  -F "files=@test_files/image1.jpg" \
  -F "files=@test_files/image2.jpg" \
  -F "files=@test_files/image3.png"

Expected: 201 status, created PDF document

Test OCR Text Extraction

curl -X POST http://localhost:5000/api/ocr \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d "{
    \"document_id\": \"$DOC1_ID\"
  }"

Expected: 200 status, extracted text array

Note: This may take longer for large documents


6. Operations Management Tests

Test List Operations

curl -X GET http://localhost:5000/api/operations \
  -H "Authorization: Bearer $TOKEN"

Expected: 200 status, array of operations

Test Get Operation Status

export OPERATION_ID="operation_id_from_previous_test"

curl -X GET http://localhost:5000/api/operations/$OPERATION_ID \
  -H "Authorization: Bearer $TOKEN"

Expected: 200 status, operation object


7. Delete Document Test

Test Delete Document

curl -X DELETE http://localhost:5000/api/documents/$DOC3_ID \
  -H "Authorization: Bearer $TOKEN"

Expected: 200 status, success message

Verify Deletion

curl -X GET http://localhost:5000/api/documents/$DOC3_ID \
  -H "Authorization: Bearer $TOKEN"

Expected: 404 status, not found error


8. Error Handling Tests

Test Invalid Document ID

curl -X GET http://localhost:5000/api/documents/invalid-uuid \
  -H "Authorization: Bearer $TOKEN"

Expected: 404 status

Test Missing Required Fields

curl -X POST http://localhost:5000/api/merge \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{}'

Expected: 400 status, error message

Test Invalid Rotation Value

curl -X POST http://localhost:5000/api/rotate \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d "{
    \"document_id\": \"$DOC1_ID\",
    \"rotation\": 45
  }"

Expected: 400 status, error message

Test Unauthorized Access

curl -X GET http://localhost:5000/api/auth/me

Expected: 401 status, unauthorized error


9. Performance Tests

Test Large File Upload

# Create or use a large PDF (>10MB)
curl -X POST http://localhost:5000/api/upload \
  -H "Authorization: Bearer $TOKEN" \
  -F "file=@test_files/large_document.pdf"

Monitor: Response time, memory usage

Test Concurrent Operations

# Run multiple operations simultaneously
for i in {1..5}; do
  curl -X POST http://localhost:5000/api/compress \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -d "{\"document_id\": \"$DOC1_ID\", \"quality\": \"medium\"}" &
done
wait

Monitor: Server load, response times


10. Integration Tests

Complete Workflow Test

#!/bin/bash

# 1. Register and login
TOKEN=$(curl -s -X POST http://localhost:5000/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{"username":"workflow_test","email":"workflow@test.com","password":"pass123"}' \
  | jq -r '.access_token')

# 2. Upload documents
DOC1=$(curl -s -X POST http://localhost:5000/api/upload \
  -H "Authorization: Bearer $TOKEN" \
  -F "file=@test1.pdf" | jq -r '.document.id')

DOC2=$(curl -s -X POST http://localhost:5000/api/upload \
  -H "Authorization: Bearer $TOKEN" \
  -F "file=@test2.pdf" | jq -r '.document.id')

# 3. Merge documents
MERGED=$(curl -s -X POST http://localhost:5000/api/merge \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d "{\"document_ids\":[\"$DOC1\",\"$DOC2\"]}" \
  | jq -r '.document.id')

# 4. Add watermark
WATERMARKED=$(curl -s -X POST http://localhost:5000/api/watermark \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d "{\"document_id\":\"$MERGED\",\"text\":\"FINAL\",\"opacity\":0.3}" \
  | jq -r '.document.id')

# 5. Compress
COMPRESSED=$(curl -s -X POST http://localhost:5000/api/compress \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d "{\"document_id\":\"$WATERMARKED\",\"quality\":\"medium\"}" \
  | jq -r '.document.id')

# 6. Download final document
curl -X GET http://localhost:5000/api/documents/$COMPRESSED/download \
  -H "Authorization: Bearer $TOKEN" \
  -o final_document.pdf

echo "Workflow complete! Final document: final_document.pdf"

Test Checklist

  • User registration works
  • User login works
  • JWT authentication works
  • PDF upload works
  • Document listing with filters works
  • Document search works
  • Document sorting works
  • Document details retrieval works
  • Document rename works
  • Document download works
  • Document deletion works
  • Document statistics works
  • Thumbnail generation works
  • PDF merge works
  • PDF split works
  • PDF rotate works
  • Page reordering works
  • Watermark addition works
  • PDF encryption works
  • PDF decryption works
  • PDF compression works
  • PDF to images conversion works
  • Images to PDF conversion works
  • OCR text extraction works
  • Operations listing works
  • Operation status retrieval works
  • Error handling works correctly
  • Large file handling works
  • Concurrent operations work

Troubleshooting

Service Not Responding

# Check service status
docker-compose ps

# Check logs
docker-compose logs backend
docker-compose logs db
docker-compose logs redis

Database Connection Issues

# Restart database
docker-compose restart db

# Check database
docker exec -it pdf_editor_db psql -U postgres -d pdfeditor -c "SELECT COUNT(*) FROM pdf_documents;"

Redis Connection Issues

# Test Redis
docker exec -it pdf_editor_redis redis-cli ping

# Clear Redis cache
docker exec -it pdf_editor_redis redis-cli FLUSHALL

OCR Not Working

Ensure Tesseract is installed in the Docker container:

docker exec -it pdf_editor_backend tesseract --version

PDF Conversion Issues

Ensure Poppler is installed:

docker exec -it pdf_editor_backend pdftoppm -v

Automated Testing Script

Save as run_tests.sh:

#!/bin/bash

BASE_URL="http://localhost:5000"
TEST_DIR="test_files"

echo "Starting PDF Editor API Tests..."

# Test health
echo "Testing health endpoint..."
curl -s $BASE_URL/health | jq

# Register user
echo "Registering test user..."
TOKEN=$(curl -s -X POST $BASE_URL/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{"username":"autotest","email":"auto@test.com","password":"test123"}' \
  | jq -r '.access_token')

if [ "$TOKEN" = "null" ]; then
  echo "Registration failed!"
  exit 1
fi

echo "Token obtained: ${TOKEN:0:20}..."

# Upload test
echo "Testing upload..."
DOC_ID=$(curl -s -X POST $BASE_URL/api/upload \
  -H "Authorization: Bearer $TOKEN" \
  -F "file=@$TEST_DIR/test1.pdf" \
  | jq -r '.document.id')

echo "Document uploaded: $DOC_ID"

# More tests...
echo "All tests completed!"

Run with:

chmod +x run_tests.sh
./run_tests.sh