Spaces:
Running
Running
| #!/usr/bin/env python3 | |
| """ | |
| Test the corrected English articles collection. | |
| """ | |
| import os | |
| import sys | |
| # Add the parent directory to Python path | |
| current_dir = os.path.dirname(os.path.abspath(__file__)) | |
| sys.path.insert(0, current_dir) | |
| def test_english_articles(): | |
| """Test the corrected English articles collection.""" | |
| print("π― Testing Corrected English Articles Collection") | |
| print("=" * 60) | |
| try: | |
| from cve_factchecker.firebase_loader import FirebaseNewsLoader | |
| loader = FirebaseNewsLoader() | |
| print(f"π‘ Project ID: {loader.project_id}") | |
| print(f"π English Collection: {loader.config.ENGLISH_ARTICLES_COLLECTION}") | |
| # Test fetching English articles | |
| print(f"\nπ Fetching English articles...") | |
| english_articles = loader.fetch_english_articles(limit=10) | |
| print(f"β Successfully fetched {len(english_articles)} English articles") | |
| if english_articles: | |
| print(f"\nπ Sample articles:") | |
| for i, article in enumerate(english_articles[:3], 1): | |
| print(f" {i}. {article.title[:80]}...") | |
| print(f" π Content: {len(article.content)} chars") | |
| if hasattr(article, 'language') and article.language: | |
| print(f" π Language: {article.language}") | |
| if hasattr(article, 'url') and article.url: | |
| print(f" π URL: {article.url}") | |
| print() | |
| # Test larger fetch | |
| print(f"π Testing larger fetch (100 articles)...") | |
| large_batch = loader.fetch_english_articles(limit=100) | |
| print(f"β Large batch: {len(large_batch)} articles") | |
| # Test unlimited fetch | |
| print(f"π Testing unlimited fetch...") | |
| all_articles = loader.fetch_english_articles(limit=None) | |
| print(f"β All articles: {len(all_articles)} articles") | |
| return len(all_articles) | |
| else: | |
| print("β No English articles found") | |
| return 0 | |
| except Exception as e: | |
| print(f"β Test failed: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| return 0 | |
| def test_integration_with_system(): | |
| """Test integration with the rest of the system.""" | |
| print(f"\nπ§ Testing System Integration") | |
| print("=" * 60) | |
| try: | |
| from cve_factchecker.orchestrator import FactCheckSystem | |
| system = FactCheckSystem() | |
| print(f"π Testing English articles ingestion...") | |
| result = system.ingest_firebase( | |
| collection="english_articles", # Use English collection | |
| limit=20, # Small test batch | |
| language="English" | |
| ) | |
| print(f"β Ingestion result: {result}") | |
| if result.get("success"): | |
| synced_count = result.get("synced", 0) | |
| print(f"π Articles synced: {synced_count}") | |
| # Check if vector database has chunks now | |
| try: | |
| # Try a test search to see if chunks were stored | |
| test_results = system.retriever.semantic_search("test", k=1) | |
| chunks_count = len(test_results) | |
| print(f"π§© Searchable chunks: {chunks_count}") | |
| if synced_count > 0: | |
| print(f"β System integration successful!") | |
| return True | |
| else: | |
| print(f"β οΈ No articles were synced") | |
| return False | |
| except Exception as e: | |
| print(f"β οΈ Could not test vector search: {e}") | |
| # Still consider success if articles were synced | |
| return synced_count > 0 | |
| else: | |
| error = result.get("error", "Unknown error") | |
| print(f"β Ingestion failed: {error}") | |
| return False | |
| except Exception as e: | |
| print(f"β Integration test failed: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| return False | |
| def main(): | |
| """Main test function.""" | |
| print("π§ͺ CVE Fact Checker - English Articles Collection Test") | |
| print("=" * 80) | |
| # Test English articles collection | |
| article_count = test_english_articles() | |
| # Test system integration if we have articles | |
| if article_count > 0: | |
| integration_success = test_integration_with_system() | |
| else: | |
| integration_success = False | |
| print(f"\nπ Test Summary:") | |
| print(f" English articles found: {article_count}") | |
| print(f" System integration: {'β OK' if integration_success else 'β Failed'}") | |
| if article_count > 0 and integration_success: | |
| print(f"\nπ Success! English articles collection is working correctly.") | |
| print(f"π‘ You can now use the system to fetch English articles from Firebase.") | |
| elif article_count > 0: | |
| print(f"\nβ οΈ Articles found but integration needs work.") | |
| else: | |
| print(f"\nβ No English articles found. Check Firebase collection.") | |
| return article_count > 0 | |
| if __name__ == "__main__": | |
| success = main() | |
| sys.exit(0 if success else 1) |