74 lines
2.1 KiB
Python
74 lines
2.1 KiB
Python
"""Test the complete DS Task AI News system"""
|
|
import sys
|
|
import os
|
|
sys.path.append('backend')
|
|
|
|
def test_imports():
|
|
"""Test if all modules can be imported"""
|
|
try:
|
|
from config import settings
|
|
print("✅ Config imported successfully")
|
|
|
|
from news_fetcher import NewsFetcher
|
|
print("✅ NewsFetcher imported successfully")
|
|
|
|
# Test basic functionality
|
|
fetcher = NewsFetcher()
|
|
print(f"✅ NewsFetcher initialized - Raw news dir: {fetcher.raw_news_dir}")
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"❌ Import error: {e}")
|
|
return False
|
|
|
|
def test_rss_fetching():
|
|
"""Test RSS fetching functionality"""
|
|
try:
|
|
sys.path.append('backend')
|
|
from news_fetcher import NewsFetcher
|
|
|
|
fetcher = NewsFetcher()
|
|
|
|
# Test with one feed
|
|
articles = fetcher.fetch_rss_feed("https://feeds.bbci.co.uk/news/rss.xml")
|
|
|
|
if articles:
|
|
print(f"✅ RSS fetching works - Got {len(articles)} articles")
|
|
print(f" Sample article: {articles[0]['title'][:50]}...")
|
|
return True
|
|
else:
|
|
print("❌ No articles fetched")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"❌ RSS fetching error: {e}")
|
|
return False
|
|
|
|
def main():
|
|
"""Run all tests"""
|
|
print("🚀 Testing DS Task AI News System")
|
|
print("=" * 50)
|
|
|
|
# Test 1: Imports
|
|
print("\n1. Testing imports...")
|
|
import_success = test_imports()
|
|
|
|
# Test 2: RSS Fetching
|
|
print("\n2. Testing RSS fetching...")
|
|
rss_success = test_rss_fetching()
|
|
|
|
# Summary
|
|
print("\n" + "=" * 50)
|
|
print("📊 Test Summary:")
|
|
print(f" Imports: {'✅ PASS' if import_success else '❌ FAIL'}")
|
|
print(f" RSS Fetching: {'✅ PASS' if rss_success else '❌ FAIL'}")
|
|
|
|
if import_success and rss_success:
|
|
print("\n🎉 System is ready for demo!")
|
|
else:
|
|
print("\n⚠️ Some components need attention")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|