-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api_live.py
More file actions
107 lines (83 loc) · 3.17 KB
/
test_api_live.py
File metadata and controls
107 lines (83 loc) · 3.17 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
#!/usr/bin/env python3
"""
Live API testing script for langchain-hreflang.
This script tests the actual hreflang.org API with your real API key.
Make sure you have HREFLANG_API_KEY set in your environment or .env file.
"""
import os
import sys
from dotenv import load_dotenv
# Load environment variables from .env file if it exists
load_dotenv()
def test_api_connection():
"""Test basic API connection and account status."""
try:
from langchain_hreflang import check_hreflang_account_status
print("🔍 Testing API connection...")
result = check_hreflang_account_status.run("")
print("✅ API Connection successful!")
print(result)
return True
except Exception as e:
print(f"❌ API Connection failed: {e}")
return False
def test_url_analysis():
"""Test URL analysis functionality."""
try:
from langchain_hreflang import test_hreflang_urls
print("\n🔍 Testing URL analysis...")
print("Testing with example.com (this may take a minute)...")
result = test_hreflang_urls.run("https://example.com/")
print("✅ URL Analysis successful!")
print(result)
return True
except Exception as e:
print(f"❌ URL Analysis failed: {e}")
return False
def test_sitemap_analysis():
"""Test sitemap analysis functionality."""
try:
from langchain_hreflang import test_hreflang_sitemap
print("\n🔍 Testing sitemap analysis...")
print("Testing with a small sitemap (this may take several minutes)...")
# Use a small sitemap for testing
result = test_hreflang_sitemap.run("https://example.com/sitemap.xml")
print("✅ Sitemap Analysis successful!")
print(result)
return True
except Exception as e:
print(f"❌ Sitemap Analysis failed: {e}")
return False
def main():
"""Run all live API tests."""
print("🚀 Starting live API tests for langchain-hreflang")
print("=" * 50)
# Check for API key
api_key = os.getenv("HREFLANG_API_KEY")
if not api_key or api_key == "your_api_key_here":
print("❌ No valid API key found!")
print("\nTo fix this:")
print("1. Get your API key from: https://app.hreflang.org/")
print("2. Set it in .env file: HREFLANG_API_KEY=your_actual_key")
print("3. Or export it: export HREFLANG_API_KEY=your_actual_key")
sys.exit(1)
print(f"✅ API key found (ends with: ...{api_key[-4:]})")
# Run tests
tests_passed = 0
total_tests = 3
if test_api_connection():
tests_passed += 1
if test_url_analysis():
tests_passed += 1
if test_sitemap_analysis():
tests_passed += 1
# Summary
print("\n" + "=" * 50)
print(f"🏆 Tests completed: {tests_passed}/{total_tests} passed")
if tests_passed == total_tests:
print("🎉 All tests passed! Your package is working perfectly!")
else:
print("⚠️ Some tests failed. Check your API key and network connection.")
sys.exit(1)
if __name__ == "__main__":
main()