39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from yt_shorts_downloader.session import validate_session_file
|
|
|
|
|
|
def test_validate_session_file_accepts_valid_youtube_session(tmp_path: Path) -> None:
|
|
session_file = tmp_path / "cookies.txt"
|
|
session_file.write_text(
|
|
"\n".join(
|
|
[
|
|
"# Netscape HTTP Cookie File",
|
|
".youtube.com\tTRUE\t/\tFALSE\t9999999999\tSID\tvalue1",
|
|
".youtube.com\tTRUE\t/\tTRUE\t9999999999\tSAPISID\tvalue2",
|
|
".youtube.com\tTRUE\t/\tTRUE\t9999999999\tLOGIN_INFO\tvalue3",
|
|
]
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
validation = validate_session_file(session_file)
|
|
|
|
assert validation.exists is True
|
|
assert validation.structurally_valid is True
|
|
assert validation.fresh is True
|
|
assert validation.is_usable is True
|
|
|
|
|
|
def test_validate_session_file_rejects_invalid_format(tmp_path: Path) -> None:
|
|
session_file = tmp_path / "cookies.txt"
|
|
session_file.write_text("broken\trow", encoding="utf-8")
|
|
|
|
validation = validate_session_file(session_file)
|
|
|
|
assert validation.exists is True
|
|
assert validation.structurally_valid is False
|
|
assert validation.is_usable is False
|