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