70 lines
2.7 KiB
Python
70 lines
2.7 KiB
Python
import requests
|
|
import json
|
|
import os
|
|
import time
|
|
|
|
# Server configuration
|
|
base_url = 'http://localhost:3015'
|
|
pdf_file = 'inputs/__enqueued__/ocr.pdf'
|
|
|
|
print('🚀 Testing OCR PDF upload with authentication...')
|
|
print(f'📁 Using PDF: {pdf_file}')
|
|
|
|
if not os.path.exists(pdf_file):
|
|
print('❌ Test file not found')
|
|
else:
|
|
print('✅ Test file found')
|
|
|
|
# Login first to get token
|
|
print('🔐 Logging in...')
|
|
login_data = {
|
|
'username': 'jleu3482',
|
|
'password': 'jleu1212'
|
|
}
|
|
|
|
try:
|
|
# Login - using the correct endpoint from OpenAPI spec
|
|
login_response = requests.post(f'{base_url}/login', data=login_data)
|
|
if login_response.status_code == 200:
|
|
token = login_response.json().get('access_token')
|
|
headers = {'Authorization': f'Bearer {token}'}
|
|
print('✅ Login successful')
|
|
|
|
# Upload the PDF
|
|
print('📤 Uploading PDF...')
|
|
with open(pdf_file, 'rb') as file:
|
|
files = {'file': ('ocr.pdf', file, 'application/pdf')}
|
|
upload_response = requests.post(f'{base_url}/documents/upload', files=files, headers=headers)
|
|
|
|
print(f'Upload response: {upload_response.status_code}')
|
|
if upload_response.status_code == 200:
|
|
print('✅ Upload successful!')
|
|
result = upload_response.json()
|
|
print(f'Upload result: {json.dumps(result, indent=2)}')
|
|
|
|
# Wait for processing
|
|
print('⏳ Waiting for indexing...')
|
|
time.sleep(10)
|
|
|
|
# Test search with meaningful query
|
|
print('🔍 Testing search with meaningful content...')
|
|
search_data = {'query': 'test', 'top_k': 10}
|
|
search_response = requests.post(f'{base_url}/search', json=search_data, headers=headers)
|
|
|
|
if search_response.status_code == 200:
|
|
search_results = search_response.json()
|
|
print(f'✅ Search successful! Found {len(search_results)} results')
|
|
for i, result in enumerate(search_results):
|
|
content = result.get("content", "")
|
|
print(f'Result {i+1}: {content[:200]}...')
|
|
else:
|
|
print(f'❌ Search failed: {search_response.status_code} - {search_response.text}')
|
|
|
|
else:
|
|
print(f'❌ Upload failed: {upload_response.status_code} - {upload_response.text}')
|
|
|
|
else:
|
|
print(f'❌ Login failed: {login_response.status_code} - {login_response.text}')
|
|
|
|
except Exception as e:
|
|
print(f'❌ Error: {e}') |