Fix youtube-transcript-api call structure and make test assertions environment-robust
- Instantiate YouTubeTranscriptApi class and call list() as required by v1.2.4 - Decorate async database fixture with pytest_asyncio.fixture - Replace hardcoded base URL string assertion in test_summarizer.py with dynamized summarizer.BASE_URL value to support proxy profiles Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
import asyncio
|
||||
import aiosqlite
|
||||
import sys
|
||||
@@ -34,7 +35,7 @@ def mock_db_path(tmp_path, monkeypatch):
|
||||
|
||||
return test_db_file
|
||||
|
||||
@pytest.fixture
|
||||
@pytest_asyncio.fixture
|
||||
async def test_db(mock_db_path):
|
||||
# Initialize the tables
|
||||
await db.init_db()
|
||||
|
||||
@@ -30,7 +30,7 @@ async def test_download_transcript_success():
|
||||
mock_trans = MockTranscript()
|
||||
mock_list = MockTranscriptList(mock_trans)
|
||||
|
||||
with patch("youtube_transcript_api.YouTubeTranscriptApi.list_transcripts", return_value=mock_list):
|
||||
with patch("youtube_transcript_api.YouTubeTranscriptApi.list", return_value=mock_list):
|
||||
text = summarizer.download_transcript("test_vid")
|
||||
assert text == "Welcome to this video tutorial. Today we are learning about Svelte 5 and runes."
|
||||
|
||||
@@ -58,7 +58,7 @@ async def test_summarize_video_success(test_db):
|
||||
}
|
||||
|
||||
# Patch both transcript api and httpx AsyncClient post call
|
||||
with patch("youtube_transcript_api.YouTubeTranscriptApi.list_transcripts", return_value=mock_list), \
|
||||
with patch("youtube_transcript_api.YouTubeTranscriptApi.list", return_value=mock_list), \
|
||||
patch("httpx.AsyncClient.post", new_callable=AsyncMock, return_value=mock_response) as mock_post:
|
||||
|
||||
summary = await summarizer.summarize_video("summarize_vid")
|
||||
@@ -66,7 +66,7 @@ async def test_summarize_video_success(test_db):
|
||||
# Verify API request details
|
||||
mock_post.assert_called_once()
|
||||
url = mock_post.call_args[0][0]
|
||||
assert "bytecatcode.org" in url
|
||||
assert summarizer.BASE_URL in url
|
||||
|
||||
headers = mock_post.call_args[1]["headers"]
|
||||
assert "x-api-key" in headers
|
||||
@@ -105,7 +105,7 @@ async def test_summarize_all_pending(test_db):
|
||||
"content": [{"text": "Fresh summary"}]
|
||||
}
|
||||
|
||||
with patch("youtube_transcript_api.YouTubeTranscriptApi.list_transcripts", return_value=mock_list), \
|
||||
with patch("youtube_transcript_api.YouTubeTranscriptApi.list", return_value=mock_list), \
|
||||
patch("httpx.AsyncClient.post", new_callable=AsyncMock, return_value=mock_response) as mock_post:
|
||||
|
||||
await summarizer.summarize_all_pending()
|
||||
|
||||
Reference in New Issue
Block a user