File size: 2,492 Bytes
86fce4f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
#!/usr/bin/env python3
"""
Test script for the FastAPI DOCX to PDF converter
"""
import requests
import time
import os
def test_health_endpoint():
"""Test the health endpoint"""
print("Testing health endpoint...")
try:
response = requests.get("http://localhost:8000/health")
if response.status_code == 200:
data = response.json()
print(f"✅ Health check passed: {data}")
return True
else:
print(f"❌ Health check failed with status {response.status_code}")
return False
except Exception as e:
print(f"❌ Health check failed with exception: {e}")
return False
def test_docs_endpoint():
"""Test the docs endpoint"""
print("Testing docs endpoint...")
try:
response = requests.get("http://localhost:8000/docs")
if response.status_code == 200:
print("✅ Docs endpoint accessible")
return True
else:
print(f"❌ Docs endpoint failed with status {response.status_code}")
return False
except Exception as e:
print(f"❌ Docs endpoint failed with exception: {e}")
return False
def test_root_endpoint():
"""Test the root endpoint"""
print("Testing root endpoint...")
try:
response = requests.get("http://localhost:8000/")
if response.status_code == 200:
print("✅ Root endpoint accessible")
return True
else:
print(f"❌ Root endpoint failed with status {response.status_code}")
return False
except Exception as e:
print(f"❌ Root endpoint failed with exception: {e}")
return False
if __name__ == "__main__":
print("🧪 Testing FastAPI DOCX to PDF Converter")
print("=" * 50)
# Wait a moment for the server to start
print("Waiting for server to start...")
time.sleep(2)
# Run tests
tests = [
test_health_endpoint,
test_docs_endpoint,
test_root_endpoint
]
passed = 0
total = len(tests)
for test in tests:
if test():
passed += 1
print()
print("=" * 50)
print(f"Test Results: {passed}/{total} tests passed")
if passed == total:
print("🎉 All tests passed!")
else:
print("❌ Some tests failed. Please check the application.") |