Spaces:
Sleeping
Sleeping
File size: 4,756 Bytes
e06a21d | 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 | #!/usr/bin/env python3
"""
Test script for the updated CVE Fact Checker with language filtering.
"""
import os
import sys
import time
def test_language_filtering():
"""Test the language filtering functionality."""
print("π§ͺ Testing Language Filtering")
print("=" * 50)
try:
# Set environment variables
os.environ['OPENROUTER_API_KEY'] = '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'
os.environ['LANGUAGE_FILTER'] = 'English'
# Test Firebase loader
from cve_factchecker.firebase_loader import FirebaseNewsLoader
print("β
Importing Firebase loader...")
loader = FirebaseNewsLoader()
print(f"π Project: {loader.project_id}")
# Test fetching English articles only
print("π Fetching 5 English articles...")
start_time = time.time()
articles = loader.fetch_articles(limit=5, language="English")
fetch_time = time.time() - start_time
print(f"β
Fetched {len(articles)} articles in {fetch_time:.2f}s")
if articles:
print("\nπ Sample Articles:")
for i, article in enumerate(articles[:3], 1):
print(f" {i}. {article.title[:60]}...")
print(f" Source: {article.source}")
print(f" URL: {article.url[:50]}...")
print()
# Test orchestrator
print("π§ Testing Orchestrator...")
from cve_factchecker.orchestrator import FactCheckSystem
system = FactCheckSystem()
print("β
System initialized")
# Test fact checking (if we have articles)
if articles:
print("π Testing fact check...")
test_claim = "This is a test claim about cybersecurity."
result = system.fact_check(test_claim)
print(f"π Fact check result:")
print(f" Verdict: {result.get('verdict')}")
print(f" Confidence: {result.get('confidence')}")
print(f" Sources used: {result.get('sources_used')}")
return True
except Exception as e:
print(f"β Test failed: {e}")
import traceback
traceback.print_exc()
return False
def test_app_endpoints():
"""Test the Flask app endpoints."""
print("\nπ Testing Flask App")
print("=" * 50)
try:
from cve_factchecker.app import app
with app.test_client() as client:
# Test health endpoint
print("π₯ Testing /health endpoint...")
response = client.get('/health')
print(f" Status: {response.status_code}")
if response.status_code == 200:
data = response.get_json()
print(f" Uptime: {data.get('uptime_sec')}s")
# Test root endpoint
print("π Testing / endpoint...")
response = client.get('/')
print(f" Status: {response.status_code}")
if response.status_code == 200:
data = response.get_json()
print(f" API Name: {data.get('name')}")
status = data.get('status', {})
print(f" Ingestion finished: {status.get('ingestion_finished')}")
print(f" Synced articles: {status.get('synced_articles')}")
return True
except Exception as e:
print(f"β App test failed: {e}")
return False
def main():
"""Run all tests."""
print("π CVE Fact Checker - Language Filtering Test")
print("=" * 60)
print(f"β° Started at: {time.strftime('%Y-%m-%d %H:%M:%S')}")
print()
success1 = test_language_filtering()
success2 = test_app_endpoints()
print("\nπ Test Summary")
print("=" * 50)
print(f"Language Filtering: {'β
PASS' if success1 else 'β FAIL'}")
print(f"Flask App: {'β
PASS' if success2 else 'β FAIL'}")
if success1 and success2:
print("\nπ All tests passed! The language filtering is working correctly.")
print("\nπ Key Features:")
print(" β
Firebase language filtering (English articles only)")
print(" β
Structured query support")
print(" β
Rate limiting protection")
print(" β
Vector database integration")
print(" β
Flask API endpoints")
print("\nπ Ready for deployment!")
else:
print("\nβ οΈ Some tests failed. Check the output above.")
return success1 and success2
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)
|