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
74 lines
2.4 KiB
Python
74 lines
2.4 KiB
Python
"""Deep tests for mail.postmark."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
from mail.postmark import (
|
|
_account_headers,
|
|
ensure_postmark_server,
|
|
publish_postmark_dns,
|
|
)
|
|
|
|
|
|
class TestAccountHeaders:
|
|
@patch.dict("os.environ", {"POSTMARK_ACCOUNT_TOKEN": "tok123"})
|
|
def test_returns_headers(self):
|
|
h = _account_headers()
|
|
assert h["X-Postmark-Account-Token"] == "tok123"
|
|
|
|
@patch.dict("os.environ", {"POSTMARK_ACCOUNT_TOKEN": "", "POSTMARK_API_KEY": ""})
|
|
def test_raises_without(self):
|
|
with pytest.raises(RuntimeError):
|
|
_account_headers()
|
|
|
|
|
|
class TestEnsureServer:
|
|
@patch.dict("os.environ", {"POSTMARK_ACCOUNT_TOKEN": "tok"})
|
|
@patch("mail.postmark.httpx.Client")
|
|
def test_creates_server(self, MockClient):
|
|
c = MockClient.return_value.__enter__.return_value
|
|
c.get.return_value = MagicMock(
|
|
status_code=200, json=MagicMock(return_value={"Servers": []})
|
|
)
|
|
c.get.return_value.raise_for_status = MagicMock()
|
|
create_resp = MagicMock(
|
|
status_code=200,
|
|
json=MagicMock(return_value={"ID": 1, "ApiTokens": ["srv-tok"]}),
|
|
)
|
|
create_resp.raise_for_status = MagicMock()
|
|
put_resp = MagicMock(
|
|
status_code=200, json=MagicMock(return_value={"SmtpApiActivated": True})
|
|
)
|
|
put_resp.raise_for_status = MagicMock()
|
|
c.post.return_value = create_resp
|
|
c.put.return_value = put_resp
|
|
with (
|
|
patch("mail.postmark._save_state"),
|
|
patch("mail.postmark._load_state", return_value={}),
|
|
):
|
|
token = ensure_postmark_server("test")
|
|
assert token == "srv-tok"
|
|
|
|
|
|
class TestPublishDns:
|
|
def test_publishes(self):
|
|
cf_client = MagicMock()
|
|
domain_info = {
|
|
"Name": "test.io",
|
|
"DKIMHost": "dk._domainkey.test.io",
|
|
"DKIMTextValue": "v=DKIM1;p=x",
|
|
"ReturnPathDomain": "pm-bounces.test.io",
|
|
"ReturnPathDomainCNAMEValue": "pm.mtasv.net",
|
|
}
|
|
with (
|
|
patch("mail.cloudflare._upsert_record"),
|
|
patch("mail.cloudflare._zone_id", return_value="z1"),
|
|
patch(
|
|
"mail.cloudflare._headers", return_value={"Authorization": "Bearer x"}
|
|
),
|
|
):
|
|
publish_postmark_dns(domain_info, cf_client)
|