Download test_deployment.py from deploy199/README: direct link, hf CLI and curl.
- Browser
- Download file 2.43 kB
-
https://huggingface.co/spaces/deploy199/README/resolve/main/test_deployment.py
- Command line
-
hf download hf://spaces/deploy199/README/test_deployment.py
-
curl -L -o test_deployment.py https://huggingface.co/spaces/deploy199/README/resolve/main/test_deployment.py
2.43 kB
| #!/usr/bin/env python3 | |
| """ | |
| Test script to verify the FastAPI Telegram Bot deployment | |
| """ | |
| import httpx | |
| import sys | |
| def test_health_endpoint(): | |
| """Test the health check endpoint""" | |
| try: | |
| response = httpx.get('http://localhost:7860/health', timeout=10) | |
| if response.status_code == 200: | |
| data = response.json() | |
| print("β Health Check: PASSED") | |
| print(f" Status: {data.get('status')}") | |
| print(f" Message: {data.get('message')}") | |
| return True | |
| else: | |
| print(f"β Health Check: FAILED (Status: {response.status_code})") | |
| return False | |
| except Exception as e: | |
| print(f"β Health Check: FAILED (Error: {e})") | |
| return False | |
| def test_sendmessage_endpoint(): | |
| """Test the sendmessage endpoint (will fail with invalid chat ID, but shows it's working)""" | |
| try: | |
| response = httpx.get('http://localhost:7860/sendmessage?log=123456789&msg=Test', timeout=10) | |
| if response.status_code == 500 and "PEER_ID_INVALID" in response.text: | |
| print("β SendMessage Endpoint: WORKING (Expected error with invalid chat ID)") | |
| return True | |
| elif response.status_code == 200: | |
| print("β SendMessage Endpoint: WORKING (Message sent successfully)") | |
| return True | |
| else: | |
| print(f"β SendMessage Endpoint: UNEXPECTED RESPONSE (Status: {response.status_code})") | |
| print(f" Response: {response.text}") | |
| return False | |
| except Exception as e: | |
| print(f"β SendMessage Endpoint: FAILED (Error: {e})") | |
| return False | |
| def main(): | |
| print("π Testing FastAPI Telegram Bot Deployment") | |
| print("=" * 50) | |
| health_ok = test_health_endpoint() | |
| sendmsg_ok = test_sendmessage_endpoint() | |
| print("\n" + "=" * 50) | |
| if health_ok and sendmsg_ok: | |
| print("π DEPLOYMENT TEST: ALL PASSED") | |
| print("\nYour FastAPI Telegram Bot is ready for production!") | |
| print("\nNext steps:") | |
| print("1. Test your bot by sending /start to it on Telegram") | |
| print("2. Use the /sendmessage API with real chat IDs") | |
| print("3. Monitor logs with: docker-compose logs -f") | |
| sys.exit(0) | |
| else: | |
| print("β DEPLOYMENT TEST: SOME TESTS FAILED") | |
| sys.exit(1) | |
| if __name__ == "__main__": | |
| main() | |