#!/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)