85fd40acf8
- 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>
46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
import os
|
|
import pytest
|
|
import pytest_asyncio
|
|
import asyncio
|
|
import aiosqlite
|
|
import sys
|
|
|
|
# Ensure backend folder is in path for imports
|
|
backend_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
if backend_dir not in sys.path:
|
|
sys.path.insert(0, backend_dir)
|
|
|
|
import db
|
|
|
|
@pytest.fixture(scope="session")
|
|
def event_loop():
|
|
try:
|
|
loop = asyncio.get_running_loop()
|
|
except RuntimeError:
|
|
loop = asyncio.new_event_loop()
|
|
yield loop
|
|
loop.close()
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def mock_db_path(tmp_path, monkeypatch):
|
|
# Ensure all modules (db, fetcher, summarizer, main) point to the temp test db
|
|
test_db_file = os.path.join(tmp_path, "test_t_youtube.db")
|
|
monkeypatch.setattr(db, "DB_PATH", test_db_file)
|
|
|
|
# Also monkeypatch in other modules that import DB_PATH directly
|
|
import fetcher
|
|
import summarizer
|
|
monkeypatch.setattr(fetcher, "DB_PATH", test_db_file)
|
|
monkeypatch.setattr(summarizer, "DB_PATH", test_db_file)
|
|
|
|
return test_db_file
|
|
|
|
@pytest_asyncio.fixture
|
|
async def test_db(mock_db_path):
|
|
# Initialize the tables
|
|
await db.init_db()
|
|
|
|
async with aiosqlite.connect(mock_db_path) as conn:
|
|
conn.row_factory = aiosqlite.Row
|
|
yield conn
|