This repository has been archived on 2026-02-15. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
openclaw-skills/skills/obsidian-kb/tests/test_models.py
T
OpenClaw Agent f26d4d8f7f feat: implement obsidian-kb skill with long video chunking
- 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
2026-02-06 18:15:30 +08:00

188 lines
6.2 KiB
Python

"""
Unit tests for models module.
"""
import unittest
import json
from datetime import datetime
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent / 'src'))
from models import Content, ContentType, ContentStatus, ContentAnalysis
from content_chunker import Chunk
class TestContentType(unittest.TestCase):
"""Test ContentType enum."""
def test_content_type_values(self):
self.assertEqual(ContentType.VIDEO.value, 'video')
self.assertEqual(ContentType.ARTICLE.value, 'article')
self.assertEqual(ContentType.AUDIO.value, 'audio')
class TestContentStatus(unittest.TestCase):
"""Test ContentStatus enum."""
def test_content_status_values(self):
self.assertEqual(ContentStatus.NEW.value, 'new')
self.assertEqual(ContentStatus.SCANNING.value, 'scanning')
self.assertEqual(ContentStatus.SCANNED.value, 'scanned')
self.assertEqual(ContentStatus.ANALYZING.value, 'analyzing')
self.assertEqual(ContentStatus.GENERATED.value, 'completed')
self.assertEqual(ContentStatus.FAILED.value, 'failed')
self.assertEqual(ContentStatus.SKIPPED.value, 'skipped')
class TestContent(unittest.TestCase):
"""Test Content model."""
def test_content_creation(self):
"""Test basic content creation."""
content = Content(
id="test_001",
source="bilibili",
title="Test Video",
url="https://bilibili.com/video/test"
)
self.assertEqual(content.id, "test_001")
self.assertEqual(content.source, "bilibili")
self.assertEqual(content.title, "Test Video")
self.assertEqual(content.url, "https://bilibili.com/video/test")
self.assertEqual(content.content_type, ContentType.VIDEO)
self.assertEqual(content.status, ContentStatus.NEW)
def test_content_with_all_fields(self):
"""Test content creation with all fields."""
analysis = ContentAnalysis(
one_liner="Test summary",
summary="Detailed summary",
key_points=["Point 1", "Point 2"],
tags=["test", "video"],
quality_score=85
)
content = Content(
id="test_002",
source="youtube",
title="Full Test Video",
url="https://youtube.com/watch?v=test",
author="Test Author",
duration=3600,
content_type=ContentType.VIDEO,
status=ContentStatus.GENERATED,
tags=["python", "tutorial"],
transcript="Test transcript",
analysis=analysis
)
self.assertEqual(content.author, "Test Author")
self.assertEqual(content.duration, 3600)
self.assertEqual(content.tags, ["python", "tutorial"])
self.assertEqual(content.analysis.quality_score, 85)
self.assertEqual(content.analysis.key_points, ["Point 1", "Point 2"])
def test_content_to_dict(self):
"""Test serialization to dictionary."""
content = Content(
id="test_003",
source="zhihu",
title="Test Article",
url="https://zhihu.com/question/test"
)
data = content.to_dict()
self.assertEqual(data['id'], "test_003")
self.assertEqual(data['source'], "zhihu")
self.assertEqual(data['content_type'], 'video')
self.assertEqual(data['status'], 'new')
def test_content_from_dict(self):
"""Test deserialization from dictionary."""
data = {
'id': 'test_004',
'source': 'bilibili',
'title': 'From Dict',
'url': 'https://example.com',
'content_type': 'article',
'status': 'scanned',
'tags': ['test', 'article'],
'duration': 600
}
content = Content.from_dict(data)
self.assertEqual(content.id, 'test_004')
self.assertEqual(content.content_type, ContentType.ARTICLE)
self.assertEqual(content.status, ContentStatus.SCANNED)
self.assertEqual(content.duration, 600)
def test_content_json_roundtrip(self):
"""Test JSON serialization roundtrip."""
original = Content(
id="test_005",
source="bilibili",
title="JSON Test",
url="https://example.com",
tags=["test", "json"]
)
json_str = original.to_json()
restored = Content.from_json(json_str)
self.assertEqual(restored.id, original.id)
self.assertEqual(restored.title, original.title)
self.assertEqual(restored.tags, original.tags)
self.assertEqual(restored.content_type, original.content_type)
class TestChunk(unittest.TestCase):
"""Test Chunk model."""
def test_chunk_creation(self):
chunk = Chunk(
index=0,
start_time=0.0,
end_time=300.0,
text="Test transcript"
)
self.assertEqual(chunk.index, 0)
self.assertEqual(chunk.start_time, 0.0)
self.assertEqual(chunk.end_time, 300.0)
class TestContentAnalysis(unittest.TestCase):
"""Test ContentAnalysis model."""
def test_analysis_defaults(self):
analysis = ContentAnalysis()
self.assertEqual(analysis.one_liner, "")
self.assertEqual(analysis.quality_score, 0)
self.assertEqual(analysis.key_points, [])
self.assertEqual(analysis.tags, [])
def test_analysis_full(self):
analysis = ContentAnalysis(
one_liner="Quick summary",
summary="Full summary",
key_points=["Point A", "Point B", "Point C"],
tags=["python", "tutorial", "advanced"],
quality_score=90,
prerequisites=["Basic Python"],
outline=[{"title": "Part 1", "summary": "Intro"}],
pitfalls=["Don't forget X"],
practice_advice=["Try Y first"]
)
self.assertEqual(analysis.quality_score, 90)
self.assertEqual(len(analysis.key_points), 3)
self.assertEqual(len(analysis.outline), 1)
if __name__ == '__main__':
unittest.main()