test(bib): move fetch-loop coverage to walk_docket; drop obsolete cli coverage class (refs #615)

This commit is contained in:
kert
2026-09-08 14:40:18 -04:00
parent d7fd23f83a
commit 3df7a3ff0e
2 changed files with 26 additions and 87 deletions

View File

@@ -134,3 +134,29 @@ def test_auto_seal_after_quiet_empty_pull():
assert r.sealed is True assert r.sealed is True
d = s.docket_get(D) d = s.docket_get(D)
assert d.sealed and d.seal_reason == "auto" assert d.sealed and d.seal_reason == "auto"
def test_progress_echo_and_commit_every_50():
s = _store()
s.docket_upsert(_docket())
api = MagicMock()
api.iter_comments.return_value = [_c(i, "2026-09-01T00:00:00Z") for i in range(101)]
echoed: list[str] = []
r = walk_docket(s, api, s.docket_get(D), echo=echoed.append, today=date(2026, 9, 8))
assert r.created == 101
assert " 50 comments" in echoed
assert " 100 comments" in echoed
def test_limit_stops_early_and_leaves_watermark_unadvanced():
s = _store()
s.docket_upsert(_docket())
api = MagicMock()
api.iter_comments.return_value = [
_c(1, "2026-09-01T00:00:00Z"),
_c(2, "2026-09-02T00:00:00Z"),
]
r = walk_docket(s, api, s.docket_get(D), limit=1, today=date(2026, 9, 8))
assert r.created == 1
assert r.clean is False
assert s.docket_get(D).pull_watermark == ""

View File

@@ -53,93 +53,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 TestCliBibFetchDocketComments:
"""Lines 175, 184, 185: early return on limit, progress echo, commit."""
def test_fetch_docket_comments_with_limit(self):
from typer.testing import CliRunner
from cli.bib import app
runner = CliRunner()
fake_comment = MagicMock()
fake_comment.id = "C-001"
fake_comment.attachment_count = 0
fake_fr_doc = {
"id": "FR-001",
"attributes": {
"objectId": "obj1",
"commentEndDate": "2024-12-31",
},
}
mock_api = MagicMock()
mock_api.__enter__ = lambda s: s
mock_api.__exit__ = lambda s, *a: None
mock_api.find_documents_in_docket.return_value = [fake_fr_doc]
# Return 2 comments to hit limit=1 → line 175 (return)
mock_api.iter_comments.return_value = iter([fake_comment, fake_comment])
mock_store = MagicMock()
with (
patch("bib.connect", return_value=mock_store),
patch("bib.regulations_gov.Client", return_value=mock_api),
patch("bib.regulations_gov.upsert_comment", return_value="key1"),
):
result = runner.invoke(
app,
["fetch-docket-comments", "CMS-1234-P", "--limit", "1"],
)
assert result.exit_code == 0 # line 175 hit
def test_fetch_docket_comments_progress_and_commit(self):
"""Lines 184, 185: progress echo at 50-comment intervals and commit."""
from typer.testing import CliRunner
from cli.bib import app
runner = CliRunner()
fake_comment = MagicMock()
fake_comment.id = "C-001"
fake_comment.attachment_count = 0
fake_fr_doc = {
"id": "FR-001",
"attributes": {
"objectId": "obj1",
"commentEndDate": "2024-12-31",
},
}
mock_api = MagicMock()
mock_api.__enter__ = lambda s: s
mock_api.__exit__ = lambda s, *a: None
mock_api.find_documents_in_docket.return_value = [fake_fr_doc]
# Return exactly 50 comments to trigger progress print
mock_api.iter_comments.return_value = iter([fake_comment] * 50)
mock_store = MagicMock()
mock_con = MagicMock()
mock_store._con.return_value = mock_con
with (
patch("bib.connect", return_value=mock_store),
patch("bib.regulations_gov.Client", return_value=mock_api),
patch("bib.regulations_gov.upsert_comment", return_value="key1"),
):
result = runner.invoke(
app,
["fetch-docket-comments", "CMS-1234-P"],
)
assert result.exit_code == 0
assert "processed 50" in result.output # line 184
mock_con.commit.assert_called() # line 185
class TestCliBibFetchPfsComments: class TestCliBibFetchPfsComments:
"""Lines 263, 265, 268, 276, 277, 281, 282, 285, 286.""" """Lines 263, 265, 268, 276, 277, 281, 282, 285, 286."""