diff --git a/tests/test_platforms/test_bilibili.py b/tests/test_platforms/test_bilibili.py index c5f8d50..0614fd8 100644 --- a/tests/test_platforms/test_bilibili.py +++ b/tests/test_platforms/test_bilibili.py @@ -179,3 +179,73 @@ class TestBilibiliAdapterArticleMetadata: await adapter.fetch_metadata("test123", "unknown") assert "Unsupported content type" in str(exc_info.value) + + +class TestBilibiliAdapterArticleContent: + """Test article content extraction (Task 3)""" + + @pytest.mark.asyncio + async def test_fetch_article_content_returns_markdown(self, mock_article_metadata, mock_article_content, mock_state_manager): + """Test 2: fetch_content("cvxxx", "article") returns Markdown format content""" + adapter = BilibiliAdapter(state_manager=mock_state_manager) + + with patch.object(adapter, '_extractor') as mock_extractor: + mock_extractor.extract_article_metadata.return_value = mock_article_metadata + + # Mock the internal _fetch_article_content method + with patch.object(adapter, '_fetch_article_content', return_value=mock_article_content): + result = await adapter.fetch_content("cv12345678", "article") + + # Should return a non-empty string + assert result is not None + assert len(result) > 0 + # Should contain the content + assert "Test Article Title" in result or "article" in result.lower() + + @pytest.mark.asyncio + async def test_fetch_article_content_has_yaml_frontmatter(self, mock_article_metadata, mock_article_content, mock_state_manager): + """Test 3: Markdown includes YAML Frontmatter with required fields""" + adapter = BilibiliAdapter(state_manager=mock_state_manager) + + with patch.object(adapter, '_extractor') as mock_extractor: + mock_extractor.extract_article_metadata.return_value = mock_article_metadata + + with patch.object(adapter, '_fetch_article_content', return_value=mock_article_content): + result = await adapter.fetch_content("cv12345678", "article") + + # Check YAML frontmatter structure + assert result.startswith("---\n"), "Content should start with YAML frontmatter" + + # Check required fields in frontmatter + assert "title:" in result + assert "author:" in result + assert "source_url:" in result + assert "platform:" in result + assert "content_type:" in result + assert "fetched_at:" in result + + # Check specific values + assert "Test Article Title" in result + assert "Test Author" in result + assert "bilibili" in result + assert "https://www.bilibili.com/read/cv12345678" in result + + @pytest.mark.asyncio + async def test_fetch_video_content_returns_empty(self, mock_state_manager): + """Test that fetch_content for video returns empty string (handled by ASR)""" + adapter = BilibiliAdapter(state_manager=mock_state_manager) + + result = await adapter.fetch_content("BV1test12345", "video") + + # Video content should return empty string (handled by ASR in Phase 3) + assert result == "" + + @pytest.mark.asyncio + async def test_fetch_content_unsupported_type_raises_error(self, mock_state_manager): + """Test that fetch_content with unsupported type raises ValueError""" + adapter = BilibiliAdapter(state_manager=mock_state_manager) + + with pytest.raises(ValueError) as exc_info: + await adapter.fetch_content("test123", "unknown") + + assert "Unsupported content type" in str(exc_info.value)