Transport and parse failures propagate with nothing recorded 🟩

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Daniel Roth 2026-07-06 15:55:38 +00:00
parent ddfbbd0052
commit b847fa2f4c

View file

@ -5,11 +5,13 @@ from typing import List, Tuple
from unittest.mock import MagicMock, patch
import pytest
import requests
from hubspot.crm.deals import SimplePublicObjectInput # type: ignore[reportMissingTypeStubs]
from domain.abri.models import AbriRequestRejected, PlaceRef
from infrastructure.abri.abri_client import AbriClient
from infrastructure.abri.config import AbriConfig
from infrastructure.abri.errors import AbriResponseParseError, AbriTransportError
from infrastructure.hubspot.deal_properties_client import HubspotDealPropertiesClient
from orchestration.abri_log_job_orchestrator import (
AbriLogJobOrchestrator,
@ -174,3 +176,48 @@ def test_run_returns_the_openhousing_rejection_verbatim_and_records_nothing(
assert result.message.startswith("No property was found with UPRN/place_ref")
assert sdk_client.mock_calls == []
assert deal_database.recorded_job_nos == []
# --- ambiguous responses are retriable failures, never success or rejection ---
@pytest.mark.parametrize(
"body",
[
b"not xml at all <<<",
b"<Root></Root>", # no Jobs/Job_logged element
b"<Root><Jobs><Job_logged>AD0226519</Job_logged></Jobs></Root>", # no attrs
b"<unexpected />",
],
)
def test_run_raises_a_retriable_parse_error_on_an_unexpectedly_shaped_response(
orchestrator: AbriLogJobOrchestrator,
mock_session: MagicMock,
sdk_client: MagicMock,
deal_database: FakeDealDatabase,
body: bytes,
) -> None:
# Arrange
mock_session.post.return_value.content = body
# Act / Assert
with pytest.raises(AbriResponseParseError):
orchestrator.run(BOOKING)
assert sdk_client.mock_calls == []
assert deal_database.recorded_job_nos == []
def test_run_raises_a_transport_error_when_the_relay_is_unreachable(
orchestrator: AbriLogJobOrchestrator,
mock_session: MagicMock,
sdk_client: MagicMock,
deal_database: FakeDealDatabase,
) -> None:
# Arrange
mock_session.post.side_effect = requests.ConnectionError("connection refused")
# Act / Assert
with pytest.raises(AbriTransportError):
orchestrator.run(BOOKING)
assert sdk_client.mock_calls == []
assert deal_database.recorded_job_nos == []