Fix Zotero table models for Zotero 9:
- Remove stale Annotations/Highlights/Transaction* models
- Add ItemAnnotations, RetractedItems, DeletedCollections,
DeletedSearches, DbDebug1
- Fix ItemAttachments, Libraries, Users column mismatches
New test files covering all major modules:
- cli/{bib,prisma,rec,zot,mail,run} deep exercising tests
- mail/{droplet,postmark,resend,cloudflare} lifecycle tests
- bib/{iom,oig,pincite,sync,regulations_gov,email_ingest,format,store}
- prisma/{vpn,fetch,export,llm,screen,eligibility,extract,project,ingest,flow}
- aco/lake/{unity,quality,deploy} + api/aco coverage gaps
- zot/{ops,db,extract,duck} + rec/{report,engine,base,pricers}
- pfs/{pipe,rules,eq,files}
Add pytest-xdist for parallel test execution.
Tracks #353
115 lines
3.9 KiB
Python
115 lines
3.9 KiB
Python
"""Deep tests for bib.regulations_gov — exercises iteration + backfill."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from bib.regulations_gov import (
|
|
Client,
|
|
)
|
|
|
|
|
|
class TestIterComments:
|
|
@patch.dict("os.environ", {"REGULATIONS_GOV_API_KEY": "test"})
|
|
@patch("bib.regulations_gov.time.sleep")
|
|
def test_yields_comments(self, mock_sleep):
|
|
mock_client = MagicMock()
|
|
resp = MagicMock()
|
|
resp.status_code = 200
|
|
resp.json.return_value = {
|
|
"data": [
|
|
{
|
|
"id": "C1",
|
|
"attributes": {
|
|
"title": "Comment 1",
|
|
"postedDate": "2023-01-01T00:00:00Z",
|
|
"receivedDate": "2023-01-01T00:00:00Z",
|
|
"docketId": "CMS-2023-0001",
|
|
"commentOnId": "obj1",
|
|
"comment": "text",
|
|
},
|
|
},
|
|
],
|
|
"meta": {"totalPages": 1},
|
|
}
|
|
resp.raise_for_status = MagicMock()
|
|
mock_client.get.return_value = resp
|
|
c = Client(sleep=0, client=mock_client)
|
|
comments = list(c.iter_comments("obj1"))
|
|
assert len(comments) == 1
|
|
assert comments[0].id == "C1"
|
|
|
|
|
|
class TestFindDocuments:
|
|
@patch.dict("os.environ", {"REGULATIONS_GOV_API_KEY": "test"})
|
|
@patch("bib.regulations_gov.time.sleep")
|
|
def test_returns_docs(self, mock_sleep):
|
|
mock_client = MagicMock()
|
|
resp = MagicMock()
|
|
resp.status_code = 200
|
|
resp.json.return_value = {
|
|
"data": [{"id": "D1", "attributes": {}}],
|
|
"meta": {"totalPages": 1},
|
|
}
|
|
resp.raise_for_status = MagicMock()
|
|
mock_client.get.return_value = resp
|
|
c = Client(sleep=0, client=mock_client)
|
|
docs = c.find_documents_in_docket("CMS-2023-0001")
|
|
assert len(docs) == 1
|
|
|
|
|
|
class TestAttachmentsFor:
|
|
@patch.dict("os.environ", {"REGULATIONS_GOV_API_KEY": "test"})
|
|
@patch("bib.regulations_gov.time.sleep")
|
|
def test_returns_attachments(self, mock_sleep):
|
|
mock_client = MagicMock()
|
|
resp = MagicMock()
|
|
resp.status_code = 200
|
|
resp.json.return_value = {
|
|
"data": {"attributes": {}},
|
|
"included": [
|
|
{
|
|
"type": "attachments",
|
|
"attributes": {
|
|
"fileFormats": [
|
|
{
|
|
"fileUrl": "https://x.com/att.pdf",
|
|
"format": "pdf",
|
|
"size": 1000,
|
|
}
|
|
]
|
|
},
|
|
}
|
|
],
|
|
}
|
|
resp.raise_for_status = MagicMock()
|
|
mock_client.get.return_value = resp
|
|
c = Client(sleep=0, client=mock_client)
|
|
atts = c.attachments_for("CMS-2023-0001-0001")
|
|
assert len(atts) == 1
|
|
assert atts[0].filename == "att.pdf"
|
|
|
|
|
|
class TestDownloadAttachment:
|
|
@patch.dict("os.environ", {"REGULATIONS_GOV_API_KEY": "test"})
|
|
@patch("bib.regulations_gov.time.sleep")
|
|
def test_downloads(self, mock_sleep, tmp_path):
|
|
mock_http = MagicMock()
|
|
stream_ctx = MagicMock()
|
|
stream_ctx.__enter__ = MagicMock(return_value=stream_ctx)
|
|
stream_ctx.__exit__ = MagicMock(return_value=False)
|
|
stream_ctx.status_code = 200
|
|
stream_ctx.iter_bytes.return_value = [b"PDF content here"]
|
|
mock_http.stream.return_value = stream_ctx
|
|
c = Client(sleep=0, client=mock_http)
|
|
result = c.download_attachment("https://x.com/att.pdf", tmp_path)
|
|
assert result is not None
|
|
assert result.name == "att.pdf"
|
|
|
|
|
|
class TestContextManager:
|
|
@patch.dict("os.environ", {"REGULATIONS_GOV_API_KEY": "test"})
|
|
def test_enter_exit(self):
|
|
with Client(sleep=0) as c:
|
|
assert c._key == "test"
|