File size: 2,600 Bytes
2469150
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python3
"""
Test script for FRED ML app functionality
"""

import requests
import time
import sys

def test_app_health():
    """Test if the app is running and healthy"""
    try:
        response = requests.get("http://localhost:8501/_stcore/health", timeout=5)
        if response.status_code == 200:
            print("βœ… App health check: PASSED")
            return True
        else:
            print(f"❌ App health check: FAILED (status {response.status_code})")
            return False
    except Exception as e:
        print(f"❌ App health check: FAILED ({e})")
        return False

def test_app_loading():
    """Test if the app loads the main page"""
    try:
        response = requests.get("http://localhost:8501", timeout=10)
        if response.status_code == 200 and "Streamlit" in response.text:
            print("βœ… App main page: PASSED")
            return True
        else:
            print(f"❌ App main page: FAILED (status {response.status_code})")
            return False
    except Exception as e:
        print(f"❌ App main page: FAILED ({e})")
        return False

def test_fred_api():
    """Test FRED API functionality"""
    try:
        # Test FRED API key
        api_key = "acf8bbec7efe3b6dfa6ae083e7152314"
        test_url = f"https://api.stlouisfed.org/fred/series?series_id=GDP&api_key={api_key}&file_type=json"
        response = requests.get(test_url, timeout=10)
        if response.status_code == 200:
            print("βœ… FRED API test: PASSED")
            return True
        else:
            print(f"❌ FRED API test: FAILED (status {response.status_code})")
            return False
    except Exception as e:
        print(f"❌ FRED API test: FAILED ({e})")
        return False

def main():
    """Run all tests"""
    print("πŸ§ͺ Testing FRED ML App...")
    print("=" * 50)
    
    tests = [
        ("App Health", test_app_health),
        ("App Loading", test_app_loading),
        ("FRED API", test_fred_api),
    ]
    
    passed = 0
    total = len(tests)
    
    for test_name, test_func in tests:
        print(f"\nπŸ” Testing: {test_name}")
        if test_func():
            passed += 1
        time.sleep(1)  # Brief pause between tests
    
    print("\n" + "=" * 50)
    print(f"πŸ“Š Test Results: {passed}/{total} tests passed")
    
    if passed == total:
        print("πŸŽ‰ All tests passed! The app is working correctly.")
        return 0
    else:
        print("⚠️  Some tests failed. Check the logs for details.")
        return 1

if __name__ == "__main__":
    sys.exit(main())