f26d4d8f7f
- Multi-source content aggregation (Bilibili/YouTube/Zhihu) - Smart inbox management with AI quality scoring - Long video chunking analysis (30min+ auto-segmentation) - Topic-based organization - Git auto-sync to Obsidian - Template system with Jinja2 and fallback rendering - CLI commands: subscribe, inbox, process, skip, status, search - Comprehensive test suite with unit and integration tests - Documentation: README.md and SKILL.md Checkpoint 7-8 completed by Agent E
147 lines
4.2 KiB
Python
147 lines
4.2 KiB
Python
"""
|
|
Unit tests for storage module.
|
|
"""
|
|
import unittest
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
import sys
|
|
sys.path.insert(0, str(Path(__file__).parent.parent / 'src'))
|
|
|
|
from storage import Storage
|
|
from models import Content, ContentType, ContentStatus
|
|
|
|
|
|
class TestStorage(unittest.TestCase):
|
|
"""Test Storage class."""
|
|
|
|
def setUp(self):
|
|
"""Set up test fixtures."""
|
|
self.temp_dir = tempfile.mkdtemp()
|
|
self.storage = Storage(base_path=self.temp_dir)
|
|
|
|
def test_initialization(self):
|
|
"""Test storage initialization."""
|
|
self.assertTrue(Path(self.temp_dir).exists())
|
|
self.assertTrue(Path(self.temp_dir / "topics").exists())
|
|
|
|
def test_get_empty_inbox(self):
|
|
"""Test getting empty inbox."""
|
|
inbox = self.storage.get_inbox()
|
|
self.assertEqual(inbox, [])
|
|
|
|
def test_add_to_inbox(self):
|
|
"""Test adding content to inbox."""
|
|
content = Content(
|
|
id="test_001",
|
|
source="bilibili",
|
|
title="Test Video",
|
|
url="https://example.com"
|
|
)
|
|
|
|
self.storage.add_to_inbox(content)
|
|
inbox = self.storage.get_inbox()
|
|
|
|
self.assertEqual(len(inbox), 1)
|
|
self.assertEqual(inbox[0].id, "test_001")
|
|
|
|
def test_add_duplicate(self):
|
|
"""Test adding duplicate content."""
|
|
content = Content(
|
|
id="test_002",
|
|
source="bilibili",
|
|
title="Test",
|
|
url="https://example.com"
|
|
)
|
|
|
|
self.storage.add_to_inbox(content)
|
|
self.storage.add_to_inbox(content) # Duplicate
|
|
|
|
inbox = self.storage.get_inbox()
|
|
self.assertEqual(len(inbox), 1)
|
|
|
|
def test_update_inbox_item(self):
|
|
"""Test updating inbox item."""
|
|
content = Content(
|
|
id="test_003",
|
|
source="bilibili",
|
|
title="Original Title",
|
|
url="https://example.com"
|
|
)
|
|
|
|
self.storage.add_to_inbox(content)
|
|
|
|
# Update content
|
|
content.title = "Updated Title"
|
|
content.status = ContentStatus.COMPLETED
|
|
self.storage.update_inbox_item(content)
|
|
|
|
# Retrieve and verify
|
|
inbox = self.storage.get_inbox()
|
|
self.assertEqual(inbox[0].title, "Updated Title")
|
|
self.assertEqual(inbox[0].status, ContentStatus.COMPLETED)
|
|
|
|
def test_remove_from_inbox(self):
|
|
"""Test removing content from inbox."""
|
|
content = Content(
|
|
id="test_004",
|
|
source="bilibili",
|
|
title="To Remove",
|
|
url="https://example.com"
|
|
)
|
|
|
|
self.storage.add_to_inbox(content)
|
|
self.storage.remove_from_inbox("test_004")
|
|
|
|
inbox = self.storage.get_inbox()
|
|
self.assertEqual(len(inbox), 0)
|
|
|
|
def test_get_pending_items(self):
|
|
"""Test getting pending items."""
|
|
# Add new item
|
|
new_content = Content(
|
|
id="test_005",
|
|
source="bilibili",
|
|
title="New",
|
|
url="https://example.com",
|
|
status=ContentStatus.NEW
|
|
)
|
|
self.storage.add_to_inbox(new_content)
|
|
|
|
# Add completed item
|
|
completed_content = Content(
|
|
id="test_006",
|
|
source="bilibili",
|
|
title="Completed",
|
|
url="https://example.com",
|
|
status=ContentStatus.COMPLETED
|
|
)
|
|
self.storage.add_to_inbox(completed_content)
|
|
|
|
pending = self.storage.get_pending_items()
|
|
|
|
self.assertEqual(len(pending), 1)
|
|
self.assertEqual(pending[0].id, "test_005")
|
|
|
|
def test_get_item_by_id(self):
|
|
"""Test getting item by ID."""
|
|
content = Content(
|
|
id="test_007",
|
|
source="bilibili",
|
|
title="Find Me",
|
|
url="https://example.com"
|
|
)
|
|
|
|
self.storage.add_to_inbox(content)
|
|
|
|
found = self.storage.get_item_by_id("test_007")
|
|
not_found = self.storage.get_item_by_id("nonexistent")
|
|
|
|
self.assertIsNotNone(found)
|
|
self.assertEqual(found.title, "Find Me")
|
|
self.assertIsNone(not_found)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|