#!/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.")