hvac-kia-content/test_cumulative_fix.py
Ben Reed 299eb35910 fix: Add missing update_cumulative_file method to CumulativeMarkdownManager
The method was being called by multiple scripts but didn't exist, causing Instagram
capture to fail at post 1200. Added a compatibility method that uses a basic
formatter to handle any source type with standard fields like ID, title, views,
likes, images, etc.

Tested successfully with test script.
2025-08-19 15:02:36 -03:00

67 lines
No EOL
1.9 KiB
Python

#!/usr/bin/env python3
"""
Test the CumulativeMarkdownManager fix.
"""
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent))
from src.cumulative_markdown_manager import CumulativeMarkdownManager
from src.base_scraper import ScraperConfig
def test_cumulative_manager():
"""Test that the update_cumulative_file method works."""
print("Testing CumulativeMarkdownManager fix...")
# Create test config
config = ScraperConfig(
source_name='TestSource',
brand_name='hkia',
data_dir=Path('test_data'),
logs_dir=Path('test_logs'),
timezone='America/Halifax'
)
# Create manager
manager = CumulativeMarkdownManager(config)
# Test data
test_items = [
{
'id': 'test123',
'title': 'Test Post',
'type': 'test',
'link': 'https://example.com/test123',
'author': 'test_user',
'publish_date': '2025-08-19',
'views': 1000,
'likes': 50,
'comments': 10,
'local_images': ['test_data/media/test_image.jpg'],
'description': 'This is a test post'
}
]
try:
# This should work now
output_file = manager.update_cumulative_file(test_items, 'TestSource')
print(f"✅ Success! Created file: {output_file}")
# Check that the file exists and has content
if output_file.exists():
content = output_file.read_text()
print(f"✅ File has {len(content)} characters")
print(f"✅ Contains ID section: {'# ID: test123' in content}")
return True
else:
print("❌ File was not created")
return False
except Exception as e:
print(f"❌ Error: {e}")
return False
if __name__ == "__main__":
success = test_cumulative_manager()
sys.exit(0 if success else 1)