You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
170 lines
5.5 KiB
Python
170 lines
5.5 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
빠른 기능 테스트 - 핵심 기능만 빠르게 검증
|
|
"""
|
|
|
|
import requests
|
|
import time
|
|
from datetime import datetime
|
|
|
|
API_URL = "http://localhost:18001/api/v1"
|
|
|
|
def test_api_health():
|
|
"""API 서버 상태 확인"""
|
|
print("🏥 API 서버 상태 확인...")
|
|
try:
|
|
# Try docs endpoint instead of health
|
|
response = requests.get(f"{API_URL.replace('/api/v1', '')}/docs", timeout=5)
|
|
if response.status_code == 200:
|
|
print("✅ API 서버 정상")
|
|
return True
|
|
else:
|
|
print(f"❌ API 서버 응답 오류: {response.status_code}")
|
|
return False
|
|
except Exception as e:
|
|
print(f"❌ API 서버 연결 실패: {e}")
|
|
return False
|
|
|
|
def test_financial_data_basic():
|
|
"""기본 재무 데이터 테스트"""
|
|
print("💰 기본 재무 데이터 테스트...")
|
|
try:
|
|
response = requests.post(
|
|
f"{API_URL}/financial/data",
|
|
json={
|
|
"ticker": "AAPL",
|
|
"start_date": "2024-01-01",
|
|
"end_date": "2024-12-31",
|
|
"period_type": "quarterly",
|
|
"include_metrics": True,
|
|
"force_refresh": False
|
|
},
|
|
timeout=30
|
|
)
|
|
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
financial_data = data.get('financial_data', [])
|
|
|
|
if len(financial_data) > 0:
|
|
real_data_count = sum(1 for fd in financial_data if not fd.get('is_estimated', True))
|
|
print(f"✅ 재무 데이터 정상 ({len(financial_data)}개 분기, {real_data_count}개 실제 데이터)")
|
|
|
|
# 최신 데이터 확인
|
|
latest = financial_data[-1] if financial_data else {}
|
|
revenue = latest.get('revenue', 0)
|
|
pe_ratio = latest.get('pe_ratio', 0)
|
|
|
|
print(f" 📊 최신 분기: {latest.get('period_date', 'N/A')}")
|
|
print(f" 💵 매출: ${revenue:,.0f}")
|
|
print(f" 📈 P/E 비율: {pe_ratio:.2f}")
|
|
print(f" 🔍 데이터 소스: {latest.get('data_source', 'Unknown')}")
|
|
|
|
return True
|
|
else:
|
|
print("❌ 재무 데이터가 없습니다")
|
|
return False
|
|
else:
|
|
print(f"❌ API 호출 실패: {response.status_code}")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"❌ 재무 데이터 테스트 실패: {e}")
|
|
return False
|
|
|
|
def test_price_data_basic():
|
|
"""기본 주가 데이터 테스트"""
|
|
print("📈 기본 주가 데이터 테스트...")
|
|
try:
|
|
response = requests.post(
|
|
f"{API_URL}/price/data",
|
|
json={
|
|
"ticker": "AAPL",
|
|
"start_date": "2024-12-01",
|
|
"end_date": "2024-12-31",
|
|
"interval": "1d"
|
|
},
|
|
timeout=30
|
|
)
|
|
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
price_data = data.get('price_data', [])
|
|
|
|
if len(price_data) > 0:
|
|
print(f"✅ 주가 데이터 정상 ({len(price_data)}일)")
|
|
|
|
# 최신 가격 확인
|
|
latest = price_data[-1] if price_data else {}
|
|
close_price = latest.get('close', 0)
|
|
volume = latest.get('volume', 0)
|
|
|
|
print(f" 📅 최신 날짜: {latest.get('date', 'N/A')}")
|
|
print(f" 💲 종가: ${close_price:.2f}")
|
|
print(f" 📊 거래량: {volume:,.0f}")
|
|
|
|
return True
|
|
else:
|
|
print("❌ 주가 데이터가 없습니다")
|
|
return False
|
|
else:
|
|
print(f"❌ API 호출 실패: {response.status_code}")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"❌ 주가 데이터 테스트 실패: {e}")
|
|
return False
|
|
|
|
def main():
|
|
"""빠른 테스트 실행"""
|
|
print("⚡ Stock Oracle 빠른 기능 테스트")
|
|
print("=" * 50)
|
|
print(f"테스트 시간: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
|
print()
|
|
|
|
start_time = time.time()
|
|
|
|
# 테스트 실행
|
|
tests = [
|
|
("서버 상태", test_api_health),
|
|
("재무 데이터", test_financial_data_basic),
|
|
("주가 데이터", test_price_data_basic)
|
|
]
|
|
|
|
results = []
|
|
for test_name, test_func in tests:
|
|
print(f"🔍 {test_name} 테스트...")
|
|
result = test_func()
|
|
results.append((test_name, result))
|
|
print()
|
|
|
|
# 결과 요약
|
|
end_time = time.time()
|
|
duration = end_time - start_time
|
|
|
|
print("=" * 50)
|
|
print("📊 빠른 테스트 결과")
|
|
print("=" * 50)
|
|
|
|
passed = sum(1 for _, result in results if result)
|
|
total = len(results)
|
|
|
|
print(f"총 테스트: {total}")
|
|
print(f"성공: {passed} ✅")
|
|
print(f"실패: {total - passed} ❌")
|
|
print(f"실행 시간: {duration:.1f}초")
|
|
print()
|
|
|
|
for test_name, result in results:
|
|
status = "✅" if result else "❌"
|
|
print(f"{status} {test_name}")
|
|
|
|
if passed == total:
|
|
print("\n🎉 모든 기본 기능이 정상 작동합니다!")
|
|
return 0
|
|
else:
|
|
print(f"\n❌ {total - passed}개의 테스트가 실패했습니다.")
|
|
return 1
|
|
|
|
if __name__ == "__main__":
|
|
exit(main()) |