-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cleaned_main.py
More file actions
151 lines (120 loc) Β· 4.29 KB
/
test_cleaned_main.py
File metadata and controls
151 lines (120 loc) Β· 4.29 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env python3
"""
Test script for the cleaned main.py API endpoints.
Tests the 3 essential endpoints: GET /api/videos, POST /api/videos, and POST /api/search
"""
import requests
import json
import time
# Configuration
API_BASE_URL = "http://localhost:8000"
def test_root_endpoint():
"""Test the root endpoint."""
print("π§ͺ Testing Root Endpoint")
try:
response = requests.get(f"{API_BASE_URL}/")
response.raise_for_status()
data = response.json()
print(f"β
Root endpoint: {data['message']}")
return True
except Exception as e:
print(f"β Root endpoint failed: {e}")
return False
def test_get_videos():
"""Test GET /api/videos endpoint."""
print("\nπ§ͺ Testing GET /api/videos")
try:
response = requests.get(f"{API_BASE_URL}/api/videos")
response.raise_for_status()
data = response.json()
print(f"β
GET /api/videos successful")
print(f" π Total videos: {data.get('total_count', 0)}")
if data.get("videos"):
sample_video = data["videos"][0]
print(f" πΉ Sample video: {sample_video.get('title', 'Unknown')}")
return True
except Exception as e:
print(f"β GET /api/videos failed: {e}")
return False
def test_vector_search():
"""Test POST /api/search endpoint."""
print("\nπ§ͺ Testing POST /api/search")
# Test semantic search
try:
search_request = {
"query": "artificial intelligence",
"search_type": "semantic",
"limit": 5,
"min_similarity": 0.3,
}
response = requests.post(
f"{API_BASE_URL}/api/search",
json=search_request,
headers={"Content-Type": "application/json"},
)
response.raise_for_status()
data = response.json()
print(f"β
Semantic search successful")
print(f" π Results found: {data.get('total_results', 0)}")
print(f" π Query: '{data.get('query', '')}'")
print(f" π§ Search type: {data.get('search_type', '')}")
# Test hybrid search
search_request["search_type"] = "hybrid"
response = requests.post(
f"{API_BASE_URL}/api/search",
json=search_request,
headers={"Content-Type": "application/json"},
)
response.raise_for_status()
data = response.json()
print(f"β
Hybrid search successful")
print(f" π Results found: {data.get('total_results', 0)}")
return True
except Exception as e:
print(f"β Vector search failed: {e}")
return False
def test_post_videos():
"""Test POST /api/videos endpoint (optional - requires valid YouTube URL)."""
print("\nπ§ͺ Testing POST /api/videos (Optional)")
# This test is optional since it requires API keys and processes a real video
print(
"βοΈ Skipping POST /api/videos test (requires API keys and processes real video)"
)
print(" To test manually:")
print(" curl -X POST 'http://localhost:8000/api/videos' \\")
print(" -H 'Content-Type: application/json' \\")
print(' -d \'{"youtube_url": "https://www.youtube.com/watch?v=VIDEO_ID"}\'')
return True
def main():
"""Run all API tests."""
print("π Testing Cleaned Main.py API")
print("=" * 50)
# Check if server is running
try:
response = requests.get(f"{API_BASE_URL}/", timeout=5)
except requests.exceptions.RequestException:
print("β API server is not running!")
print(" Start the server with: cd api && python main.py")
return False
tests = [
test_root_endpoint,
test_get_videos,
test_vector_search,
test_post_videos,
]
passed = 0
total = len(tests)
for test in tests:
if test():
passed += 1
time.sleep(0.5) # Brief pause between tests
print(f"\nπ Test Results: {passed}/{total} tests passed")
if passed == total:
print("π All tests passed! The cleaned API is working correctly.")
return True
else:
print("β οΈ Some tests failed. Check the output above for details.")
return False
if __name__ == "__main__":
success = main()
exit(0 if success else 1)