Release govoplan-campaign v0.1.28: stabilize saving, review and delivery recovery
Module Package Release / publish-packages (push) Successful in 12s
Module Package Release / publish-packages (push) Successful in 12s
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
from contextlib import contextmanager
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from govoplan_campaign.backend.integrations import ImapAppendError, MailCampaignIntegration
|
||||
|
||||
|
||||
def test_older_mail_capability_keeps_single_message_compatibility():
|
||||
integration = MailCampaignIntegration(SimpleNamespace())
|
||||
with integration.campaign_imap_batch(tenant_id="tenant", campaign_id="campaign") as state:
|
||||
assert state is None
|
||||
|
||||
|
||||
def test_optional_batch_forwards_scope_and_cleans_up_when_caller_fails():
|
||||
calls = []
|
||||
state = SimpleNamespace(connection_count=0, reconnect_count=0)
|
||||
|
||||
@contextmanager
|
||||
def batch(**kwargs):
|
||||
calls.append(kwargs)
|
||||
try:
|
||||
yield state
|
||||
finally:
|
||||
calls.append("closed")
|
||||
|
||||
integration = MailCampaignIntegration(SimpleNamespace(campaign_imap_batch=batch))
|
||||
with pytest.raises(ValueError, match="caller"):
|
||||
with integration.campaign_imap_batch(tenant_id="tenant", campaign_id="campaign") as actual:
|
||||
assert actual is state
|
||||
raise ValueError("caller failure")
|
||||
assert calls == [{"tenant_id": "tenant", "campaign_id": "campaign"}, "closed"]
|
||||
|
||||
|
||||
def test_optional_batch_translates_unknown_outcome_without_losing_flags():
|
||||
class ProviderAppendError(RuntimeError):
|
||||
temporary = False
|
||||
outcome_unknown = True
|
||||
|
||||
@contextmanager
|
||||
def batch(**kwargs):
|
||||
raise ProviderAppendError("inspect mailbox")
|
||||
yield None
|
||||
|
||||
integration = MailCampaignIntegration(SimpleNamespace(
|
||||
campaign_imap_batch=batch, ImapAppendError=ProviderAppendError,
|
||||
))
|
||||
with pytest.raises(ImapAppendError) as caught:
|
||||
with integration.campaign_imap_batch(tenant_id="tenant", campaign_id="campaign"):
|
||||
pass
|
||||
assert caught.value.outcome_unknown
|
||||
assert caught.value.temporary is False
|
||||
Reference in New Issue
Block a user