#!/usr/bin/env python3 """ Test Data Generator for RSSuper Integration Tests Generates sample feeds and test data for cross-platform testing. """ import json import random from datetime import datetime, timedelta from pathlib import Path def generate_random_feed_items(count: int = 10) -> list[dict]: """Generate random feed items for testing.""" categories = ["technology", "news", "sports", "entertainment", "science"] titles = [ "Understanding Modern Web Development", "The Future of AI in Software Engineering", "Best Practices for Database Design", "Introduction to Functional Programming", "Building Scalable Microservices", "Deep Dive into React Hooks", "Performance Optimization Techniques", "Security Best Practices for APIs", "Cloud Native Application Architecture", "Introduction to GraphQL" ] items = [] base_date = datetime.now() for i in range(count): item = { "id": f"test-item-{i:03d}", "title": titles[i % len(titles)], "link": f"https://example.com/article{i}", "description": f"This is test article number {i + 1}", "author": f"author{i}@example.com", "published": (base_date - timedelta(hours=i)).isoformat(), "categories": [categories[i % len(categories)]], "read": random.random() > 0.7, "subscription_id": f"subscription-{i // 3}", "subscription_title": f"Subscription {i // 3 + 1}" } items.append(item) return items def generate_subscription() -> dict: """Generate a test subscription.""" return { "id": "test-subscription-1", "url": "https://example.com/feed.xml", "title": "Test Subscription", "category": "technology", "enabled": True, "fetch_interval": 3600, "created_at": datetime.now().isoformat(), "updated_at": datetime.now().isoformat(), "last_fetched_at": None, "error": None } def generate_test_data() -> dict: """Generate complete test data package.""" return { "subscriptions": [generate_subscription()], "feed_items": generate_random_feed_items(10), "bookmarks": [ { "id": "bookmark-1", "feed_item_id": "test-item-000", "created_at": datetime.now().isoformat(), "tags": ["important", "read-later"] } ], "search_history": [ { "id": "search-1", "query": "test query", "timestamp": datetime.now().isoformat() } ] } def save_test_data(output_path: str = "tests/fixtures/test-data.json"): """Save generated test data to file.""" data = generate_test_data() output = Path(output_path) output.parent.mkdir(parents=True, exist_ok=True) with open(output, "w") as f: json.dump(data, f, indent=2) print(f"Test data saved to {output}") return data if __name__ == "__main__": import sys output_file = sys.argv[1] if len(sys.argv) > 1 else "tests/fixtures/test-data.json" save_test_data(output_file)