Repository navigation
Expand file tree
/
Copy pathtest_api.py
More file actions
executable file
·100 lines (83 loc) · 3.19 KB
/
Copy pathtest_api.py
File metadata and controls
executable file
·100 lines (83 loc) · 3.19 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
#!/usr/bin/env python3
"""
Test script for the Flask GitHub API
"""
import requests
import json
import os
from typing import Dict, Any
def test_health_endpoint(base_url: str) -> bool:
"""Test the health check endpoint"""
try:
response = requests.get(f"{base_url}/health")
if response.status_code == 200:
data = response.json()
print(f"✅ Health check passed: {data}")
return True
else:
print(f"❌ Health check failed: {response.status_code}")
return False
except Exception as e:
print(f"❌ Health check error: {e}")
return False
def test_repositories_endpoint(base_url: str, token: str, username: str = None) -> bool:
"""Test the repositories endpoint"""
try:
params = {
'token': token,
'per_page': 5 # Limit to 5 repos for testing
}
if username:
params['username'] = username
response = requests.get(f"{base_url}/api/repositories", params=params)
if response.status_code == 200:
data = response.json()
print(f"✅ Repositories endpoint passed")
print(f" Found {len(data.get('repositories', []))} repositories")
# Show first few repositories
for i, repo in enumerate(data.get('repositories', [])[:3]):
print(f" {i+1}. {repo.get('full_name')} ({repo.get('language', 'No language')})")
return True
else:
print(f"❌ Repositories endpoint failed: {response.status_code}")
try:
error_data = response.json()
print(f" Error: {error_data}")
except:
print(f" Response: {response.text}")
return False
except Exception as e:
print(f"❌ Repositories endpoint error: {e}")
return False
def main():
"""Main test function"""
base_url = "http://localhost:5000"
print("🧪 Testing Flask GitHub API")
print("=" * 50)
# Test health endpoint
print("\n1. Testing health endpoint...")
health_ok = test_health_endpoint(base_url)
if not health_ok:
print("\n❌ Health check failed. Make sure the Flask server is running:")
print(" python app.py")
return
# Test repositories endpoint
print("\n2. Testing repositories endpoint...")
# Get token from environment or prompt user
token = os.getenv('GITHUB_TOKEN')
if not token:
print("❌ GITHUB_TOKEN environment variable not set.")
print(" Please set it with: export GITHUB_TOKEN=your_token_here")
print(" Or run: GITHUB_TOKEN=your_token python test_api.py")
return
# Test with current user's repositories
repos_ok = test_repositories_endpoint(base_url, token)
if repos_ok:
print("\n✅ All tests passed! The API is working correctly.")
print("\n🚀 You can now start the frontend:")
print(" cd frontend")
print(" npm run dev")
else:
print("\n❌ Repository test failed. Check your GitHub token and try again.")
if __name__ == "__main__":
main()