diff --git a/tests/orchestration/test_abri_log_job_orchestrator.py b/tests/orchestration/test_abri_log_job_orchestrator.py index 6bab8181a..689dc99d9 100644 --- a/tests/orchestration/test_abri_log_job_orchestrator.py +++ b/tests/orchestration/test_abri_log_job_orchestrator.py @@ -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"", # no Jobs/Job_logged element + b"AD0226519", # no attrs + b"", + ], +) +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 == []