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:
@@ -32,7 +32,7 @@ Transcript:
|
|||||||
|
|
||||||
def download_transcript(video_id: str) -> str:
|
def download_transcript(video_id: str) -> str:
|
||||||
try:
|
try:
|
||||||
transcript_list = YouTubeTranscriptApi.list_transcripts(video_id)
|
transcript_list = YouTubeTranscriptApi().list(video_id)
|
||||||
|
|
||||||
# Try to find manual transcripts in preferred languages
|
# Try to find manual transcripts in preferred languages
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import pytest
|
import pytest
|
||||||
|
import pytest_asyncio
|
||||||
import asyncio
|
import asyncio
|
||||||
import aiosqlite
|
import aiosqlite
|
||||||
import sys
|
import sys
|
||||||
@@ -34,7 +35,7 @@ def mock_db_path(tmp_path, monkeypatch):
|
|||||||
|
|
||||||
return test_db_file
|
return test_db_file
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest_asyncio.fixture
|
||||||
async def test_db(mock_db_path):
|
async def test_db(mock_db_path):
|
||||||
# Initialize the tables
|
# Initialize the tables
|
||||||
await db.init_db()
|
await db.init_db()
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ async def test_download_transcript_success():
|
|||||||
mock_trans = MockTranscript()
|
mock_trans = MockTranscript()
|
||||||
mock_list = MockTranscriptList(mock_trans)
|
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")
|
text = summarizer.download_transcript("test_vid")
|
||||||
assert text == "Welcome to this video tutorial. Today we are learning about Svelte 5 and runes."
|
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
|
# 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:
|
patch("httpx.AsyncClient.post", new_callable=AsyncMock, return_value=mock_response) as mock_post:
|
||||||
|
|
||||||
summary = await summarizer.summarize_video("summarize_vid")
|
summary = await summarizer.summarize_video("summarize_vid")
|
||||||
@@ -66,7 +66,7 @@ async def test_summarize_video_success(test_db):
|
|||||||
# Verify API request details
|
# Verify API request details
|
||||||
mock_post.assert_called_once()
|
mock_post.assert_called_once()
|
||||||
url = mock_post.call_args[0][0]
|
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"]
|
headers = mock_post.call_args[1]["headers"]
|
||||||
assert "x-api-key" in headers
|
assert "x-api-key" in headers
|
||||||
@@ -105,7 +105,7 @@ async def test_summarize_all_pending(test_db):
|
|||||||
"content": [{"text": "Fresh summary"}]
|
"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:
|
patch("httpx.AsyncClient.post", new_callable=AsyncMock, return_value=mock_response) as mock_post:
|
||||||
|
|
||||||
await summarizer.summarize_all_pending()
|
await summarizer.summarize_all_pending()
|
||||||
|
|||||||
Reference in New Issue
Block a user