test: drop dead TestCliBibFetchPfsComments coverage class (refs #615)
The class drove `fetch-pfs-comments` against a MagicMock store to cover
line numbers that no longer exist — the same defect as the class removed
in 3df7a3f. A mock store asserts nothing about the fetch loop, which now
lives in walk_docket and is covered by tests/bib/test_walk_docket.py and
tests/cli/test_bib_fetch_sealed.py.
This commit is contained in:
@@ -13,9 +13,11 @@ from unittest.mock import MagicMock, patch
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
# ═══════════════════════════════════════════════════════════════════
|
# ═══════════════════════════════════════════════════════════════════
|
||||||
# Priority 1: cli/bib.py (14 lines)
|
# Priority 1: cli/bib.py
|
||||||
# Lines: 113, 175, 184, 185, 263, 265, 268, 276, 277, 281, 282,
|
# Lines: 113, 175, 184, 185, 325
|
||||||
# 285, 286, 325
|
# (the fetch-pfs-comments block moved to tests/bib/test_walk_docket.py
|
||||||
|
# and tests/cli/test_bib_fetch_sealed.py when that loop moved into
|
||||||
|
# walk_docket — MagicMock-store coverage of deleted lines proved nothing)
|
||||||
# ═══════════════════════════════════════════════════════════════════
|
# ═══════════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
|
|
||||||
@@ -53,157 +55,6 @@ class TestCliBibDiscoverPfsRulesTranslateError:
|
|||||||
assert "skipped" in result.output # line 113 hit via exception branch
|
assert "skipped" in result.output # line 113 hit via exception branch
|
||||||
|
|
||||||
|
|
||||||
class TestCliBibFetchPfsComments:
|
|
||||||
"""Lines 263, 265, 268, 276, 277, 281, 282, 285, 286."""
|
|
||||||
|
|
||||||
def test_fetch_pfs_comments_full_flow(self):
|
|
||||||
from typer.testing import CliRunner
|
|
||||||
|
|
||||||
from cli.bib import app
|
|
||||||
|
|
||||||
runner = CliRunner()
|
|
||||||
|
|
||||||
fake_doc = MagicMock()
|
|
||||||
fake_doc.type = "Proposed Rule"
|
|
||||||
fake_doc.publication_date = "2024-01-01"
|
|
||||||
fake_doc.document_number = "2024-00001"
|
|
||||||
fake_doc.dockets = ["CMS-1234-P"]
|
|
||||||
fake_doc.html_url = "https://example.com/doc"
|
|
||||||
|
|
||||||
fake_rule = MagicMock()
|
|
||||||
|
|
||||||
fake_comment = MagicMock()
|
|
||||||
fake_comment.id = "C-001"
|
|
||||||
fake_comment.attachment_count = 1
|
|
||||||
|
|
||||||
fake_att = MagicMock()
|
|
||||||
fake_att.url = "https://example.com/att.pdf"
|
|
||||||
fake_att.filename = "att.pdf"
|
|
||||||
|
|
||||||
# fr_doc with no objectId → line 263 (continue)
|
|
||||||
fr_doc_no_obj = {
|
|
||||||
"id": "FR-A",
|
|
||||||
"attributes": {"commentEndDate": "2024-12-31"},
|
|
||||||
}
|
|
||||||
# fr_doc with no commentEndDate → line 265 (continue)
|
|
||||||
fr_doc_no_end = {
|
|
||||||
"id": "FR-B",
|
|
||||||
"attributes": {"objectId": "obj2"},
|
|
||||||
}
|
|
||||||
# fr_doc that works normally
|
|
||||||
fr_doc_ok = {
|
|
||||||
"id": "FR-C",
|
|
||||||
"attributes": {
|
|
||||||
"objectId": "obj3",
|
|
||||||
"commentEndDate": "2024-12-31",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
mock_api = MagicMock()
|
|
||||||
mock_api.__enter__ = lambda s: s
|
|
||||||
mock_api.__exit__ = lambda s, *a: None
|
|
||||||
mock_api.resolve_docket.return_value = "REG-DOCKET-1"
|
|
||||||
mock_api.find_documents_in_docket.return_value = [
|
|
||||||
fr_doc_no_obj,
|
|
||||||
fr_doc_no_end,
|
|
||||||
fr_doc_ok,
|
|
||||||
]
|
|
||||||
# Return 50 comments to hit lines 285-286 (progress + commit)
|
|
||||||
mock_api.iter_comments.return_value = iter([fake_comment] * 50)
|
|
||||||
mock_api.attachments_for.return_value = [fake_att]
|
|
||||||
mock_api.download_attachment.return_value = Path("/fake/att.pdf")
|
|
||||||
|
|
||||||
mock_store = MagicMock()
|
|
||||||
mock_con = MagicMock()
|
|
||||||
mock_store._con.return_value = mock_con
|
|
||||||
|
|
||||||
with (
|
|
||||||
patch("bib.connect", return_value=mock_store),
|
|
||||||
patch("bib.federalregister.pfs_rules", return_value=[fake_doc]),
|
|
||||||
patch("bib.federalregister.split_docket_ids", return_value=["CMS-1234-P"]),
|
|
||||||
patch("bib.regulations_gov.Client", return_value=mock_api),
|
|
||||||
patch("bib.regulations_gov.upsert_comment", return_value="key1"),
|
|
||||||
patch("bib.translate.federal_register", return_value=fake_rule),
|
|
||||||
):
|
|
||||||
result = runner.invoke(
|
|
||||||
app,
|
|
||||||
[
|
|
||||||
"fetch-pfs-comments",
|
|
||||||
"--attachments",
|
|
||||||
"--per-docket-limit",
|
|
||||||
"50",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
assert result.exit_code == 0
|
|
||||||
# line 263: fr_doc_no_obj skipped
|
|
||||||
# line 265: fr_doc_no_end skipped
|
|
||||||
# line 268: per_docket_limit break
|
|
||||||
# lines 276-277: attachment download
|
|
||||||
# lines 281-282: attach_file called
|
|
||||||
# lines 285-286: progress + commit at 50
|
|
||||||
|
|
||||||
def test_fetch_pfs_comments_attachment_path_none(self):
|
|
||||||
"""Line 281: download_attachment returns None → skip attach_file."""
|
|
||||||
from typer.testing import CliRunner
|
|
||||||
|
|
||||||
from cli.bib import app
|
|
||||||
|
|
||||||
runner = CliRunner()
|
|
||||||
|
|
||||||
fake_doc = MagicMock()
|
|
||||||
fake_doc.type = "Proposed Rule"
|
|
||||||
fake_doc.publication_date = "2024-01-01"
|
|
||||||
fake_doc.document_number = "2024-00001"
|
|
||||||
fake_doc.dockets = ["CMS-5678-P"]
|
|
||||||
fake_doc.html_url = "https://example.com/doc"
|
|
||||||
|
|
||||||
fake_rule = MagicMock()
|
|
||||||
|
|
||||||
fake_comment = MagicMock()
|
|
||||||
fake_comment.id = "C-002"
|
|
||||||
fake_comment.attachment_count = 1
|
|
||||||
|
|
||||||
fake_att = MagicMock()
|
|
||||||
fake_att.url = "https://example.com/att.pdf"
|
|
||||||
fake_att.filename = "att.pdf"
|
|
||||||
|
|
||||||
fr_doc_ok = {
|
|
||||||
"id": "FR-D",
|
|
||||||
"attributes": {
|
|
||||||
"objectId": "obj4",
|
|
||||||
"commentEndDate": "2024-12-31",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
mock_api = MagicMock()
|
|
||||||
mock_api.__enter__ = lambda s: s
|
|
||||||
mock_api.__exit__ = lambda s, *a: None
|
|
||||||
mock_api.resolve_docket.return_value = "REG-DOCKET-2"
|
|
||||||
mock_api.find_documents_in_docket.return_value = [fr_doc_ok]
|
|
||||||
mock_api.iter_comments.return_value = iter([fake_comment])
|
|
||||||
mock_api.attachments_for.return_value = [fake_att]
|
|
||||||
mock_api.download_attachment.return_value = None # failed download
|
|
||||||
|
|
||||||
mock_store = MagicMock()
|
|
||||||
mock_con = MagicMock()
|
|
||||||
mock_store._con.return_value = mock_con
|
|
||||||
|
|
||||||
with (
|
|
||||||
patch("bib.connect", return_value=mock_store),
|
|
||||||
patch("bib.federalregister.pfs_rules", return_value=[fake_doc]),
|
|
||||||
patch("bib.federalregister.split_docket_ids", return_value=["CMS-5678-P"]),
|
|
||||||
patch("bib.regulations_gov.Client", return_value=mock_api),
|
|
||||||
patch("bib.regulations_gov.upsert_comment", return_value="key2"),
|
|
||||||
patch("bib.translate.federal_register", return_value=fake_rule),
|
|
||||||
):
|
|
||||||
result = runner.invoke(
|
|
||||||
app,
|
|
||||||
["fetch-pfs-comments", "--attachments", "--per-docket-limit", "1"],
|
|
||||||
)
|
|
||||||
assert result.exit_code == 0
|
|
||||||
mock_store.attach_file.assert_not_called() # line 281 path=None
|
|
||||||
|
|
||||||
|
|
||||||
class TestCliBibIngestMailMissingPassword:
|
class TestCliBibIngestMailMissingPassword:
|
||||||
"""Line 325: no cached password for user."""
|
"""Line 325: no cached password for user."""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user