Spaces:
Paused
Paused
| #!/usr/bin/env python3 | |
| """ | |
| Docker Test Script for Legal Dashboard OCR | |
| ========================================== | |
| This script tests the Docker container to ensure it's working correctly | |
| for Hugging Face Spaces deployment. | |
| """ | |
| import requests | |
| import time | |
| import subprocess | |
| import sys | |
| import os | |
| def test_docker_build(): | |
| """Test Docker build process""" | |
| print("π¨ Testing Docker build...") | |
| try: | |
| result = subprocess.run( | |
| ["docker", "build", "-t", "legal-dashboard-ocr", "."], | |
| capture_output=True, | |
| text=True, | |
| cwd="." | |
| ) | |
| if result.returncode == 0: | |
| print("β Docker build successful") | |
| return True | |
| else: | |
| print(f"β Docker build failed: {result.stderr}") | |
| return False | |
| except Exception as e: | |
| print(f"β Docker build error: {e}") | |
| return False | |
| def test_docker_run(): | |
| """Test Docker container startup""" | |
| print("π Testing Docker container startup...") | |
| try: | |
| # Start container in background | |
| container = subprocess.run( | |
| ["docker", "run", "-d", "-p", "7860:7860", "--name", | |
| "test-legal-dashboard", "legal-dashboard-ocr"], | |
| capture_output=True, | |
| text=True | |
| ) | |
| if container.returncode != 0: | |
| print(f"β Container startup failed: {container.stderr}") | |
| return False | |
| # Wait for container to start | |
| print("β³ Waiting for container to start...") | |
| time.sleep(30) | |
| # Test health endpoint | |
| try: | |
| response = requests.get("http://localhost:7860/health", timeout=10) | |
| if response.status_code == 200: | |
| print("β Container health check passed") | |
| return True | |
| else: | |
| print(f"β Health check failed: {response.status_code}") | |
| return False | |
| except requests.exceptions.RequestException as e: | |
| print(f"β Health check error: {e}") | |
| return False | |
| except Exception as e: | |
| print(f"β Container test error: {e}") | |
| return False | |
| finally: | |
| # Cleanup | |
| subprocess.run( | |
| ["docker", "stop", "test-legal-dashboard"], capture_output=True) | |
| subprocess.run(["docker", "rm", "test-legal-dashboard"], | |
| capture_output=True) | |
| def test_api_endpoints(): | |
| """Test API endpoints""" | |
| print("π Testing API endpoints...") | |
| endpoints = [ | |
| "/", | |
| "/health", | |
| "/docs", | |
| "/api/dashboard/summary" | |
| ] | |
| for endpoint in endpoints: | |
| try: | |
| response = requests.get( | |
| f"http://localhost:7860{endpoint}", timeout=10) | |
| # 404 is OK for some endpoints | |
| if response.status_code in [200, 404]: | |
| print(f"β {endpoint}: {response.status_code}") | |
| else: | |
| print(f"β {endpoint}: {response.status_code}") | |
| except requests.exceptions.RequestException as e: | |
| print(f"β {endpoint}: {e}") | |
| def main(): | |
| """Main test function""" | |
| print("π§ͺ Starting Docker tests for Legal Dashboard OCR...") | |
| # Test 1: Docker build | |
| if not test_docker_build(): | |
| print("β Docker build test failed") | |
| sys.exit(1) | |
| # Test 2: Docker run | |
| if not test_docker_run(): | |
| print("β Docker run test failed") | |
| sys.exit(1) | |
| # Test 3: API endpoints | |
| test_api_endpoints() | |
| print("β All Docker tests completed successfully!") | |
| print("π Ready for Hugging Face Spaces deployment!") | |
| if __name__ == "__main__": | |
| main() | |