Network-mocked test coverage for downloader.py and pcl.py#12
Open
johnzfitch wants to merge 2 commits into
Open
Network-mocked test coverage for downloader.py and pcl.py#12johnzfitch wants to merge 2 commits into
johnzfitch wants to merge 2 commits into
Conversation
Cover the PCL API client end-to-end with mocked requests.Session and a patched authenticate(): exception hierarchy, token property/auth, the _make_request branches (GET/POST/DELETE, 401 retry, 404/406/500, token refresh, network errors), immediate searches, pagination, and all batch job operations. https://claude.ai/code/session_01NNvhsYRVWhjfcdgaSmU5bt
Cover the CM/ECF docket/document downloaders with a mocked requests.Session and patched authenticate(): the pure helpers (extract_document_metadata, load_cached_documents, get_document_by_number, DownloadResult), DocketDownloader auth/helpers/_cso_login (including the MFA flow), download_docket_by_link (direct docket, report-config form, JS->CSO redirect, error/short/network paths), download_docket_by_case_number, and DocumentDownloader (auth gating, direct PDF, PDF-link/iframe/goDLS receipt/generic-form flows, HTML-instead-of-PDF and missing-magic-bytes warnings, login-redirect and network error paths). https://claude.ai/code/session_01NNvhsYRVWhjfcdgaSmU5bt
There was a problem hiding this comment.
Pull request overview
Adds extensive network-mocked pytest coverage for the two previously low-coverage, network-bound modules (pacer_cli/pcl.py and pacer_cli/downloader.py) without changing production code or adding dependencies. The new tests replace HTTP sessions with MagicMock(spec=requests.Session) and patch authentication and parsing points to keep runs deterministic and fully offline.
Changes:
- Introduces comprehensive unit tests for
PCLClientcovering auth/token handling,_make_requesterror branches, pagination helpers, and batch job APIs. - Adds broad test coverage for downloader helpers and the main
DocketDownloader/DocumentDownloaderflows (CSO login, report form submission, redirects, and content-type/HTML-vs-PDF cases). - Ensures all test scenarios are network-isolated via session mocking and targeted patching (
authenticate,parse_docket,time.sleep,generate_totp).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
tests/test_pcl.py |
Adds offline/mocked coverage for PCL client auth, request branching, pagination, and batch APIs. |
tests/test_downloader.py |
Adds offline/mocked coverage for docket/document downloading flows plus cache/metadata helper functions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The second deferred coverage item: the two network-bound modules that the coverage wiring flagged as the big gaps (
downloader.py~9%,pcl.py~25%). Test-only — no source changes, no new dependencies.Coverage
pcl.pydownloader.pyWhat's covered (100 new tests, network fully mocked)
pcl.py— the PCL exception hierarchy, token/auth, every_make_requestbranch (401 retry + token refresh, 404/406/500, network-error wrapping), immediate searches, pagination (last-page + max-pages), and all batch-job methods.downloader.py— the pure helpers (extract_document_metadataincl. parse-failure manifest + entry-skipping,load_cached_documentsincl. corrupt JSON,get_document_by_number,DownloadResult);DocketDownloaderauth/_cso_login(incl. the MFA AJAX/redirect flow),download_docket_by_link(direct, report-config form, JS→CSO redirect success/fail, 401, short-response, network error),download_docket_by_case_number; andDocumentDownloader(direct PDF, PDF-link/iframe/goDLS-receipt/generic-form flows, HTML-instead-of-PDF + missing-magic-bytes warnings, login-redirect + network-error paths).How it's mocked
A real
PacerConfig, each client'ssessionreplaced withMagicMock(spec=requests.Session),authenticatepatched to a successfulAuthResult, and cannedMagicMockresponses shaped frommodels.py(PCL JSON) and realistic CM/ECF HTML/PDF bytes. Deterministic; no real network, noresponses/requests_mock.Verification
pytest tests/→ 402 passed, 9 skippedruff checkclean,pyflakescleanThe remaining ~4 uncovered
downloader.pystatements are deep alternate-shape fall-throughs in the goDLS/iframe handling (the primary success + error path through each is covered) — left rather than over-fitting near-duplicate HTML fixtures, since 96% is well past target.https://claude.ai/code/session_01NNvhsYRVWhjfcdgaSmU5bt
Generated by Claude Code