"""Shared fixtures for platform adapter tests""" import pytest from pathlib import Path import tempfile from unittest.mock import MagicMock from kb_workflow.pipeline.state import WorkflowStateManager from kb_workflow.pipeline.schemas import WorkflowState @pytest.fixture def tmp_content_dir(): """Create a temporary directory for content files""" with tempfile.TemporaryDirectory() as tmpdir: yield Path(tmpdir) @pytest.fixture def state_manager(tmp_content_dir): """Create a WorkflowStateManager with a temporary directory""" return WorkflowStateManager(tmp_content_dir) @pytest.fixture def mock_state_manager(): """Create a mock WorkflowStateManager for testing Note: WorkflowStateManager doesn't have mark_step_failed directly, but we mock it here for testing the adapter's state recording behavior. In real usage, the adapter would need to work with WorkflowState objects. """ mock = MagicMock() mock.mark_step_failed = MagicMock() return mock @pytest.fixture def mock_video_metadata(): """Mock video metadata response from BilibiliExtractor""" return { 'metadata': { 'title': 'Test Video Title', 'author': 'Test Author', 'bvid': 'BV1test12345', 'aid': 12345678, 'mid': 9876543, 'pubtime': '2024-01-15 10:30:00', 'duration': '10:25', 'url': 'https://www.bilibili.com/video/BV1test12345', 'tags': 'test, video, bilibili', }, 'stats': { 'view': 100000, 'danmaku': 500, 'reply': 200, 'favorite': 1000, 'coin': 800, 'share': 300, 'like': 5000, }, 'subtitle': '', 'description': 'This is a test video description.' } @pytest.fixture def mock_article_metadata(): """Mock article metadata response from BilibiliExtractor""" return { 'cvid': 'cv12345678', 'title': 'Test Article Title', 'author': 'Test Author', 'mid': '9876543', 'publish_time': '2024-01-15 10:30:00', 'view_count': 50000, 'like_count': 2000, 'coin_count': 500, 'share_count': 100, 'reply_count': 150, 'url': 'https://www.bilibili.com/read/cv12345678', 'summary': 'This is a test article summary.', 'word_count': 3000, } @pytest.fixture def mock_article_content(): """Mock article content HTML/Markdown""" return """# Test Article Title This is the first paragraph of the test article. ## Section 1 Content for section 1. ## Section 2 Content for section 2. """ @pytest.fixture def mock_zhihu_extractor(): """Mock ZhihuPlaywrightExtractor for testing.""" from unittest.mock import MagicMock extractor = MagicMock() extractor.extract = MagicMock() return extractor @pytest.fixture def mock_zhihu_answer_result(): """Sample Zhihu answer extraction result.""" return { "type": "answer", "title": "Test Question Title", "author": "Test Author", "content": "This is the answer content with enough text to pass the login page detection threshold.", "content_markdown": "# Answer\n\nThis is the answer content with enough text to pass the login page detection threshold.", "publish_time": "2024-01-15T10:30:00", "url": "https://www.zhihu.com/question/123456/answer/789012", "question_id": "123456", "answer_id": "789012", } @pytest.fixture def mock_zhihu_zhuanlan_result(): """Sample Zhihu zhuanlan extraction result.""" return { "type": "zhuanlan", "title": "Test Article Title", "author": "Test Author", "content": "This is the article content with enough text to pass the login page detection threshold.", "content_markdown": "# Article\n\nThis is the article content with enough text to pass the login page detection threshold.", "publish_time": "2024-01-15T10:30:00", "url": "https://zhuanlan.zhihu.com/p/123456", "article_id": "123456", }