Добавить основную функциональность загрузки YouTube Shorts с использованием файла сессии и обработкой ошибок
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from yt_shorts_downloader import api
|
||||
from yt_shorts_downloader.exceptions import InvalidSessionError, InvalidUrlError
|
||||
from yt_shorts_downloader.models import SessionValidation
|
||||
|
||||
|
||||
def test_download_returns_path_from_downloader(
|
||||
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
expected_path = tmp_path / "video.mp4"
|
||||
|
||||
monkeypatch.setattr(
|
||||
api,
|
||||
"validate_session_file",
|
||||
lambda path: SessionValidation(True, True, True, True, str(path)),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
api,
|
||||
"download_video",
|
||||
lambda *, url, output_dir, session_path: expected_path,
|
||||
)
|
||||
|
||||
downloaded_path = api.download(
|
||||
"https://youtube.com/shorts/example",
|
||||
session_path="cookies.txt",
|
||||
output_dir=tmp_path,
|
||||
)
|
||||
|
||||
assert downloaded_path == expected_path
|
||||
|
||||
|
||||
def test_download_rejects_invalid_url() -> None:
|
||||
with pytest.raises(InvalidUrlError):
|
||||
api.download("https://example.com/watch?v=1", session_path="cookies.txt")
|
||||
|
||||
|
||||
def test_download_rejects_invalid_session(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(
|
||||
api,
|
||||
"validate_session_file",
|
||||
lambda path: SessionValidation(False, False, False, False, "bad session"),
|
||||
)
|
||||
|
||||
with pytest.raises(InvalidSessionError, match="bad session"):
|
||||
api.download("https://youtube.com/shorts/example", session_path="cookies.txt")
|
||||
Reference in New Issue
Block a user