Spaces:
Runtime error
Runtime error
| #!/usr/bin/env python3 | |
| """ | |
| QA Test Suite for Customer Agent API | |
| """ | |
| import requests | |
| import json | |
| import time | |
| BASE_URL = "http://localhost:8000" | |
| def test_health_endpoint(): | |
| """Test health check endpoint""" | |
| print("π Testing health endpoint...") | |
| try: | |
| response = requests.get(f"{BASE_URL}/health") | |
| assert response.status_code == 200 | |
| data = response.json() | |
| assert "status" in data | |
| print("β Health endpoint working") | |
| return True | |
| except Exception as e: | |
| print(f"β Health endpoint failed: {e}") | |
| return False | |
| def test_user_registration(): | |
| """Test user registration""" | |
| print("π Testing user registration...") | |
| try: | |
| test_user = { | |
| "email": f"test_{int(time.time())}@example.com", | |
| "password": "testpassword123", | |
| "name": "Test User" | |
| } | |
| response = requests.post(f"{BASE_URL}/api/auth/register", json=test_user) | |
| assert response.status_code == 200 | |
| data = response.json() | |
| assert "access_token" in data | |
| print("β User registration working") | |
| return test_user, data["access_token"] | |
| except Exception as e: | |
| print(f"β User registration failed: {e}") | |
| return None, None | |
| def test_website_creation(token): | |
| """Test website creation""" | |
| print("π Testing website creation...") | |
| try: | |
| headers = {"Authorization": f"Bearer {token}"} | |
| website_data = { | |
| "url": "https://example.com", | |
| "name": "Test Website", | |
| "industry": "technology", | |
| "tone": "friendly" | |
| } | |
| response = requests.post(f"{BASE_URL}/api/websites/", json=website_data, headers=headers) | |
| assert response.status_code == 200 | |
| data = response.json() | |
| assert "id" in data | |
| print("β Website creation working") | |
| return data["id"] | |
| except Exception as e: | |
| print(f"β Website creation failed: {e}") | |
| return None | |
| def test_chat_functionality(website_id): | |
| """Test chat functionality""" | |
| print("π Testing chat functionality...") | |
| try: | |
| chat_data = { | |
| "message": "Hello, what services do you offer?", | |
| "website_id": website_id, | |
| "session_id": f"test_session_{int(time.time())}" | |
| } | |
| response = requests.post(f"{BASE_URL}/api/chat", json=chat_data) | |
| assert response.status_code == 200 | |
| data = response.json() | |
| assert "response" in data | |
| assert len(data["response"]) > 0 | |
| print("β Chat functionality working") | |
| return True | |
| except Exception as e: | |
| print(f"β Chat functionality failed: {e}") | |
| return False | |
| def test_widget_endpoint(website_id): | |
| """Test widget greeting endpoint""" | |
| print("π Testing widget greeting...") | |
| try: | |
| response = requests.get(f"{BASE_URL}/api/websites/{website_id}/greeting") | |
| assert response.status_code == 200 | |
| data = response.json() | |
| assert "greeting" in data | |
| print("β Widget greeting working") | |
| return True | |
| except Exception as e: | |
| print(f"β Widget greeting failed: {e}") | |
| return False | |
| def run_qa_tests(): | |
| """Run all QA tests""" | |
| print("π Starting QA Test Suite...") | |
| print("=" * 50) | |
| # Test 1: Health check | |
| if not test_health_endpoint(): | |
| print("β Critical: Health endpoint failed") | |
| return False | |
| # Test 2: User registration | |
| user_data, token = test_user_registration() | |
| if not token: | |
| print("β Critical: User registration failed") | |
| return False | |
| # Test 3: Website creation | |
| website_id = test_website_creation(token) | |
| if not website_id: | |
| print("β Critical: Website creation failed") | |
| return False | |
| # Test 4: Chat functionality | |
| if not test_chat_functionality(website_id): | |
| print("β Critical: Chat functionality failed") | |
| return False | |
| # Test 5: Widget greeting | |
| if not test_widget_endpoint(website_id): | |
| print("β Widget greeting failed") | |
| print("=" * 50) | |
| print("β QA Tests Completed Successfully!") | |
| return True | |
| if __name__ == "__main__": | |
| run_qa_tests() |