| |
| """ |
| Test script to verify deep analysis integration with Housing.csv dataset |
| """ |
|
|
| import os |
| import sys |
| import requests |
| import json |
| from typing import Dict, Any |
|
|
| |
| BASE_URL = "http://localhost:8000" |
| TEST_SESSION_ID = "test-deep-analysis-session-housing" |
|
|
| def test_basic_functionality(): |
| """Test basic server functionality""" |
| print("Testing server health...") |
| try: |
| response = requests.get(f"{BASE_URL}/health") |
| if response.status_code == 200: |
| print("β
Server is running") |
| return True |
| else: |
| print(f"β Server health check failed: {response.status_code}") |
| return False |
| except Exception as e: |
| print(f"β Cannot connect to server: {e}") |
| print("Make sure the FastAPI server is running on localhost:8000") |
| return False |
|
|
|
|
|
|
| def test_agents_endpoint(): |
| """Test that agents endpoint includes deep analysis""" |
| print("\nTesting agents endpoint for deep analysis info...") |
| try: |
| response = requests.get(f"{BASE_URL}/agents") |
| if response.status_code == 200: |
| agents_info = response.json() |
| if "deep_analysis" in agents_info: |
| print("β
Deep analysis info found in agents endpoint") |
| print(f" Description: {agents_info['deep_analysis']['description']}") |
| print(f" Available agents: {len(agents_info['available_agents'])}") |
| print(f" Planner agents: {len(agents_info['planner_agents'])}") |
| return True |
| else: |
| print("β Deep analysis info not found in agents endpoint") |
| return False |
| else: |
| print(f"β Failed to get agents info: {response.status_code}") |
| return False |
| except Exception as e: |
| print(f"β Error testing agents endpoint: {e}") |
| return False |
|
|
| def test_deep_analysis_with_housing_data(): |
| """Test deep analysis with Housing.csv data""" |
| print("\nTesting deep analysis with Housing.csv dataset...") |
| |
| |
| print(" Resetting session to default dataset...") |
| try: |
| reset_response = requests.post( |
| f"{BASE_URL}/session/reset_to_default", |
| headers={"X-Session-ID": TEST_SESSION_ID} |
| ) |
| if reset_response.status_code == 200: |
| print(" β
Session reset to default dataset") |
| else: |
| print(f" β οΈ Session reset failed: {reset_response.status_code}") |
| |
| |
| print(" Verifying dataset is loaded...") |
| verify_response = requests.get( |
| f"{BASE_URL}/dataset/info", |
| headers={"X-Session-ID": TEST_SESSION_ID} |
| ) |
| |
| if verify_response.status_code == 200: |
| dataset_info = verify_response.json() |
| if dataset_info.get("loaded", False): |
| print(f" β
Dataset loaded: {dataset_info.get('rows', 0)} rows, {dataset_info.get('columns', 0)} columns") |
| else: |
| print(" β οΈ No dataset loaded - attempting to load default dataset") |
| |
| load_response = requests.post( |
| f"{BASE_URL}/dataset/load_default", |
| headers={"X-Session-ID": TEST_SESSION_ID} |
| ) |
| if load_response.status_code == 200: |
| print(" β
Default dataset loaded") |
| else: |
| print(f" β Failed to load default dataset: {load_response.status_code}") |
| return False |
| else: |
| print(f" β οΈ Could not verify dataset: {verify_response.status_code}") |
| except Exception as e: |
| print(f" β οΈ Error during dataset setup: {e}") |
| |
| |
| test_payload = { |
| "goal": "Analyze housing price patterns and identify key factors affecting prices" |
| } |
| |
| headers = { |
| "X-Session-ID": TEST_SESSION_ID, |
| "Content-Type": "application/json" |
| } |
| |
| try: |
| print(" Starting deep analysis...") |
| response = requests.post( |
| f"{BASE_URL}/deep_analysis_streaming", |
| json=test_payload, |
| headers=headers, |
| timeout=12000 |
| ) |
| |
| if response.status_code == 200: |
| print("β
Deep analysis completed successfully!") |
| result = response.json() |
| |
| |
| analysis = result.get("analysis", {}) |
| print(f" Goal: {analysis.get('goal', 'N/A')[:50]}...") |
| print(f" Questions generated: {'β
' if analysis.get('deep_questions') else 'β'}") |
| print(f" Plan created: {'β
' if analysis.get('deep_plan') else 'β'}") |
| print(f" Code generated: {'β
' if analysis.get('code') else 'β'}") |
| print(f" Visualizations: {len(analysis.get('plotly_figs', []))} figures") |
| print(f" Synthesis: {'β
' if analysis.get('synthesis') else 'β'}") |
| print(f" Conclusion: {'β
' if analysis.get('final_conclusion') else 'β'}") |
| print(f" Processing time: {result.get('processing_time_seconds', 'unknown')} seconds") |
| |
| return True |
| |
| elif response.status_code == 400: |
| error_detail = response.json().get('detail', 'Unknown error') |
| if "No dataset" in error_detail: |
| print("β Dataset not properly loaded") |
| print(f" Error: {error_detail}") |
| else: |
| print(f"β Client error: {error_detail}") |
| return False |
| |
| elif response.status_code == 500: |
| error_detail = response.json().get('detail', 'Unknown error') |
| print(f"β Server error during analysis: {error_detail}") |
| return False |
| |
| else: |
| print(f"β Unexpected response: {response.status_code}") |
| print(f" Response: {response.text[:200]}...") |
| return False |
| |
| except requests.Timeout: |
| print("β Analysis timed out (this may be normal for complex analysis)") |
| return False |
| except Exception as e: |
| print(f"β Error during deep analysis: {e}") |
| return False |
|
|
| def download_html_report(): |
| """Test downloading HTML report""" |
| print("\nTesting HTML report download...") |
| try: |
| response = requests.post( |
| f"{BASE_URL}/deep_analysis/download_report", |
| headers={"X-Session-ID": TEST_SESSION_ID} |
| ) |
| if response.status_code == 200: |
| print("β
HTML report downloaded successfully") |
| return True |
| else: |
| print(f"β Failed to download HTML report: {response.status_code}") |
| return False |
| except Exception as e: |
| print(f"β Error during HTML report download: {e}") |
| return False |
|
|
|
|
| def main(): |
| print("π§ͺ Testing Deep Analysis Integration with Housing Data") |
| print("=" * 60) |
| |
| |
| tests = [ |
| ("Server Health", test_basic_functionality), |
| ("Agents Endpoint", test_agents_endpoint), |
| ("Deep Analysis with Housing Data", test_deep_analysis_with_housing_data), |
| ("HTML Report Download", download_html_report) |
| ] |
| |
| results = [] |
| for test_name, test_func in tests: |
| print(f"\nπ Running: {test_name}") |
| result = test_func() |
| results.append((test_name, result)) |
| |
| if not result: |
| print(f"β οΈ Test failed: {test_name}") |
| break |
| |
| |
| print("\n" + "=" * 60) |
| print("π Test Results Summary:") |
| |
| passed = sum(1 for _, result in results if result) |
| total = len(results) |
| |
| for test_name, result in results: |
| status = "β
PASS" if result else "β FAIL" |
| print(f" {status}: {test_name}") |
| |
| print(f"\nOverall: {passed}/{total} tests passed") |
| |
| if passed == total: |
| print("π All tests passed! Deep analysis integration is working correctly.") |
| else: |
| print("β οΈ Some tests failed. Check the errors above for details.") |
| |
| return passed == total |
|
|
| if __name__ == "__main__": |
| success = main() |
| sys.exit(0 if success else 1) |