Skip to content

Network-mocked test coverage for downloader.py and pcl.py#12

Open
johnzfitch wants to merge 2 commits into
masterfrom
claude/coverage-network
Open

Network-mocked test coverage for downloader.py and pcl.py#12
johnzfitch wants to merge 2 commits into
masterfrom
claude/coverage-network

Conversation

@johnzfitch

Copy link
Copy Markdown
Owner

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

Module Before After
pcl.py ~25% 100%
downloader.py ~9% 96%

What's covered (100 new tests, network fully mocked)

  • pcl.py — the PCL exception hierarchy, token/auth, every _make_request branch (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_metadata incl. parse-failure manifest + entry-skipping, load_cached_documents incl. corrupt JSON, get_document_by_number, DownloadResult); DocketDownloader auth/_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; and DocumentDownloader (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's session replaced with MagicMock(spec=requests.Session), authenticate patched to a successful AuthResult, and canned MagicMock responses shaped from models.py (PCL JSON) and realistic CM/ECF HTML/PDF bytes. Deterministic; no real network, no responses/requests_mock.

Verification

  • pytest tests/402 passed, 9 skipped
  • new test files: ruff check clean, pyflakes clean

The remaining ~4 uncovered downloader.py statements 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

claude added 2 commits June 10, 2026 04:18
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
Copilot AI review requested due to automatic review settings June 10, 2026 04:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 PCLClient covering auth/token handling, _make_request error branches, pagination helpers, and batch job APIs.
  • Adds broad test coverage for downloader helpers and the main DocketDownloader / DocumentDownloader flows (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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants