Files
stack/tests/bib/test_sync_full.py
kert 641f366b03
Some checks failed
CI / skinny-install (aco) (push) Successful in 1m17s
CI / skinny-install (api) (push) Successful in 40s
CI / skinny-install (bcda) (push) Successful in 42s
CI / skinny-install (conf) (push) Successful in 35s
CI / skinny-install (perf) (push) Successful in 45s
CI / skinny-install (pfs) (push) Successful in 39s
CI / skinny-install (bib) (push) Successful in 33s
CI / skinny-install (bls) (push) Successful in 33s
CI / skinny-install (ccw) (push) Successful in 38s
CI / skinny-install (cli) (push) Successful in 40s
CI / skinny-install (cms) (push) Successful in 38s
CI / skinny-install (opps) (push) Successful in 44s
CI / skinny-install (rex) (push) Successful in 40s
CI / lint-test (push) Failing after 11m38s
Deploy / build-scan-report (push) Failing after 5m44s
test: deep exercising tests for iom, oig, sync, flow, llm, droplet +
purge stale host-zotero.sqlite

62 new tests that actually exercise module logic with mocked deps.
Deleted host-zotero.sqlite (stale schema causing false drift errors).
All HOST_DB refs now point at the live zotero.sqlite. Tracks #353.
2026-04-17 11:51:13 -04:00

133 lines
4.2 KiB
Python

"""Deeper coverage tests for bib.sync — push bib items into Zotero."""
from __future__ import annotations
from bib.item import Manual, Rule, Source
from bib.sync import (
_item_to_zotero_fields,
_parse_authors_from_extra,
_parse_extra_to_journal_fields,
_zotero_collection_path,
)
class TestParseAuthors:
def test_basic(self):
authors, cleaned = _parse_authors_from_extra(
"Authors: Smith John; Doe Jane\nOther line"
)
assert len(authors) == 2
assert authors[0] == ("John", "Smith")
assert "Other line" in cleaned
def test_no_authors(self):
authors, cleaned = _parse_authors_from_extra("Just some text")
assert authors == []
assert "Just some text" in cleaned
def test_single_name(self):
authors, _ = _parse_authors_from_extra("Authors: Lastname")
assert len(authors) == 1
assert authors[0] == ("", "Lastname")
def test_with_plus(self):
authors, _ = _parse_authors_from_extra("Authors: Smith J; (+3 more)")
assert len(authors) == 1
class TestParseExtraToJournal:
def test_extracts_doi(self):
fields = _parse_extra_to_journal_fields(
"DOI: 10.1234/test\nJournal: JAMA\nPMID: 12345"
)
assert fields["DOI"] == "10.1234/test"
assert fields["publicationTitle"] == "JAMA"
assert "PMID" in fields["extra"]
def test_empty(self):
fields = _parse_extra_to_journal_fields("")
assert fields["extra"] == ""
class TestItemToZoteroFields:
def test_rule(self):
item = Rule(
title="PFS Rule",
date_published="2023-01-01",
fr_volume="88",
fr_page="1234",
cms_id="CMS-1676-P",
rule_type="Proposed Rule",
effective_date="2023-07-01",
document_number="2023-12345",
)
fields = _item_to_zotero_fields(item)
assert fields["nameOfAct"] == "PFS Rule"
assert fields["code"] == "FR"
assert fields["codeNumber"] == "88"
def test_manual(self):
item = Manual(
title="IOM Chapter 1",
institution="CMS",
manual_name="Claims Processing",
pub_number="100-04",
chapter="1",
transmittal="R100",
)
fields = _item_to_zotero_fields(item)
assert fields["title"] == "IOM Chapter 1"
assert fields["reportType"] == "Internet-Only Manual"
assert "Transmittal" in fields["extra"]
def test_source_generic(self):
item = Source(
title="Test Doc",
institution="CMS",
date_published="2023-01-01",
url="https://x.com",
)
item.doc_type = "Public Comment"
fields = _item_to_zotero_fields(item)
assert fields["title"] == "Test Doc"
assert "Public Comment" in fields["extra"]
def test_journal_article(self):
item = Source(title="A Study", institution="JAMA")
item.doc_type = "journal-article"
item.extra = "DOI: 10.1234/test\nJournal: JAMA\nAuthors: Smith John"
fields = _item_to_zotero_fields(item)
assert fields["DOI"] == "10.1234/test"
class TestZoteroCollectionPath:
def test_manual(self):
item = Manual(title="Ch1", manual_name="Claims Processing")
path = _zotero_collection_path(item)
assert path == ["Healthcare Data Platform", "Manuals", "Claims Processing"]
def test_regulations_gov(self):
item = Source(title="Comment")
item.add_tag("source:regulations-gov")
path = _zotero_collection_path(item)
assert path == ["Rules", "Comments"]
def test_email(self):
item = Source(title="CMS Alert")
item.add_tag("source:email")
item.add_tag("mailbox:cmsupdates")
path = _zotero_collection_path(item)
assert path == ["Inbox", "Cmsupdates"]
def test_oig(self):
item = Source(title="OIG CPG")
item.add_tag("agency:oig")
item.add_tag("sector:hospitals")
path = _zotero_collection_path(item)
assert "OIG Guidance" in path[1]
def test_generic(self):
item = Source(title="Random")
path = _zotero_collection_path(item)
assert path == []