refactor(session): rename LibroFmClient → LibroFmSession
Relocate API client from client.py to session.py with constructor injection. Transport is now passed once at construction time instead of per-method, eliminating 5 redundant httpx.Client creations per session lifecycle. - New session.py: LibroFmSession with shared _client, transport injected at construction, auth headers set once after authenticate() - Old client.py: deprecated re-export shim (LibroFmClient alias) - All endpoint signatures slimmed to ≤3 params (removed transport= from authenticate/fetch_library/fetch_m4b_url/ fetch_download_manifest/fetch_pdf_extra_url) - Updated all source imports (cli.py, downloader.py) and test files (test_client, test_downloader, test_cli, test_progress) - 17 new TDD tests in test_session.py Closes #27
This commit is contained in:
1 parent
fb219be248
commit
006a7561ce
11 files changed
+986
-413
No files matched your search
@@ -157,7 +157,7 @@ class TestFailureIsolationCLI:
|
||||
|
||||
with (
|
||||
patch("librofm_downloader.cli.load_config") as mock_config,
|
||||
patch("librofm_downloader.cli.LibroFmClient") as mock_client_cls,
|
||||
patch("librofm_downloader.cli.LibroFmSession") as mock_client_cls,
|
||||
patch("librofm_downloader.cli.DownloadHistory") as mock_history_cls,
|
||||
patch("librofm_downloader.cli.download_book") as mock_download,
|
||||
):
|
||||
@@ -218,11 +218,11 @@ class TestFatalVsBookLevel:
|
||||
def test_auth_failure_exits_one_before_downloads(self, capsys):
|
||||
"""Auth failure → exit 1, download_book never called."""
|
||||
from unittest.mock import patch
|
||||
from librofm_downloader.client import AuthError
|
||||
from librofm_downloader.session import AuthError
|
||||
|
||||
with (
|
||||
patch("librofm_downloader.cli.load_config") as mock_config,
|
||||
patch("librofm_downloader.cli.LibroFmClient") as mock_client_cls,
|
||||
patch("librofm_downloader.cli.LibroFmSession") as mock_client_cls,
|
||||
patch("librofm_downloader.cli.download_book") as mock_download,
|
||||
):
|
||||
mock_config.return_value.username = "alice"
|
||||
@@ -663,7 +663,7 @@ class TestProgressCallbackWiring:
|
||||
from pathlib import Path
|
||||
from librofm_downloader.book import Book
|
||||
from librofm_downloader.downloader import download_book
|
||||
from librofm_downloader.client import LibroFmClient
|
||||
from librofm_downloader.session import LibroFmSession
|
||||
from librofm_downloader.history import DownloadHistory
|
||||
|
||||
m4b_payload = b"callback-test-data" * 10 # 160 bytes
|
||||
@@ -681,8 +681,8 @@ class TestProgressCallbackWiring:
|
||||
return httpx.Response(404)
|
||||
|
||||
transport = httpx.MockTransport(handler)
|
||||
client = LibroFmClient(base_url="https://libro.fm", username="u", password="p")
|
||||
client.authenticate(transport=transport)
|
||||
client = LibroFmSession(base_url="https://libro.fm", username="u", password="p", transport=transport)
|
||||
client.authenticate()
|
||||
|
||||
book = Book(title="CB Test", authors=["A"], narrators=["N"], isbn="9781111111111")
|
||||
progress_calls: list[int] = []
|
||||
|
||||
Reference in new issue
Block a user