fix(bib): discover_docket prefers the Proposed Rule document over a later-closing final rule (refs #615 #680)
This commit is contained in:
@@ -898,15 +898,28 @@ def upsert_comment_status(
|
|||||||
def discover_docket(client: Client, docket_id: str, *, rule_cms_id: str = "") -> Docket:
|
def discover_docket(client: Client, docket_id: str, *, rule_cms_id: str = "") -> Docket:
|
||||||
"""One ``/documents`` listing → the docket's commentable document.
|
"""One ``/documents`` listing → the docket's commentable document.
|
||||||
|
|
||||||
Picks the document that has an ``objectId`` and a ``commentEndDate``
|
Picks the Proposed Rule that has an ``objectId`` and a
|
||||||
(latest close date wins when several qualify). Called once per
|
``commentEndDate`` — latest close date wins among proposed rules;
|
||||||
docket; the result is persisted so later runs make no API call.
|
falls back to any commentable document. Called once per docket; the
|
||||||
|
result is persisted so later runs make no API call.
|
||||||
"""
|
"""
|
||||||
best: dict | None = None
|
qualifying: list[dict] = []
|
||||||
for fr_doc in client.find_documents_in_docket(docket_id):
|
for fr_doc in client.find_documents_in_docket(docket_id):
|
||||||
attrs = fr_doc.get("attributes") or {}
|
attrs = fr_doc.get("attributes") or {}
|
||||||
if not attrs.get("objectId") or not attrs.get("commentEndDate"):
|
if not attrs.get("objectId") or not attrs.get("commentEndDate"):
|
||||||
continue
|
continue
|
||||||
|
qualifying.append(fr_doc)
|
||||||
|
|
||||||
|
proposed_rules = [
|
||||||
|
fr_doc
|
||||||
|
for fr_doc in qualifying
|
||||||
|
if (fr_doc.get("attributes") or {}).get("documentType") == "Proposed Rule"
|
||||||
|
]
|
||||||
|
candidates = proposed_rules or qualifying
|
||||||
|
|
||||||
|
best: dict | None = None
|
||||||
|
for fr_doc in candidates:
|
||||||
|
attrs = fr_doc.get("attributes") or {}
|
||||||
if (
|
if (
|
||||||
best is None
|
best is None
|
||||||
or attrs["commentEndDate"]
|
or attrs["commentEndDate"]
|
||||||
|
|||||||
@@ -66,6 +66,44 @@ def test_discover_docket_picks_commentable_doc():
|
|||||||
api.find_documents_in_docket.assert_called_once_with(D)
|
api.find_documents_in_docket.assert_called_once_with(D)
|
||||||
|
|
||||||
|
|
||||||
|
def test_discover_docket_prefers_proposed_rule():
|
||||||
|
api = MagicMock()
|
||||||
|
api.find_documents_in_docket.return_value = [
|
||||||
|
{
|
||||||
|
"id": "CMS-2019-0111-41991",
|
||||||
|
"attributes": {
|
||||||
|
"objectId": "o-rule",
|
||||||
|
"commentEndDate": "2020-01-03T03:59:59Z",
|
||||||
|
"documentType": "Rule",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "CMS-2019-0111-0092",
|
||||||
|
"attributes": {
|
||||||
|
"objectId": "o-nprm",
|
||||||
|
"commentEndDate": "2019-09-28T03:59:59Z",
|
||||||
|
"documentType": "Proposed Rule",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "CMS-2019-0111-0001",
|
||||||
|
"attributes": {
|
||||||
|
"objectId": "o-display",
|
||||||
|
"commentEndDate": "2019-08-14T03:59:59Z",
|
||||||
|
"documentType": "Proposed Rule",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
d = discover_docket(api, "CMS-2019-0111", rule_cms_id="CMS-1738-P")
|
||||||
|
assert d == Docket(
|
||||||
|
id="CMS-2019-0111",
|
||||||
|
rule_cms_id="CMS-1738-P",
|
||||||
|
fr_document_id="CMS-2019-0111-0092",
|
||||||
|
fr_object_id="o-nprm",
|
||||||
|
comment_end_date="2019-09-28",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_walk_creates_counts_and_advances_watermark():
|
def test_walk_creates_counts_and_advances_watermark():
|
||||||
s = _store()
|
s = _store()
|
||||||
s.docket_upsert(_docket())
|
s.docket_upsert(_docket())
|
||||||
|
|||||||
Reference in New Issue
Block a user