From 79ce9dc4b1a70958e66162ac42320174419b8edf Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Fri, 3 Jul 2026 14:24:57 +0000 Subject: [PATCH] =?UTF-8?q?Abri=20log=5Fjob=20sends=20the=20spec's=20recor?= =?UTF-8?q?ded=20LogJob=20envelope=20to=20the=20relay=20endpoint=20?= =?UTF-8?q?=F0=9F=9F=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Fable 5 --- infrastructure/abri/abri_client.py | 24 ++++++++++++++++++- infrastructure/abri/envelope.py | 23 ++++++++++++++++++ tests/infrastructure/abri/test_abri_client.py | 4 ++-- 3 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 infrastructure/abri/envelope.py diff --git a/infrastructure/abri/abri_client.py b/infrastructure/abri/abri_client.py index a5c9ffaef..712ab49de 100644 --- a/infrastructure/abri/abri_client.py +++ b/infrastructure/abri/abri_client.py @@ -4,6 +4,11 @@ import requests from domain.abri.models import JobLogged, LogJobRequest, LogJobResult from infrastructure.abri.config import AbriConfig +from infrastructure.abri.envelope import serialise_relay_request + +STD_JOB_CODE = "SCSEXT" +CLIENT_CODE = "HSG" +RESOURCE_GROUP = "Surveyors" class AbriClient: @@ -12,7 +17,24 @@ class AbriClient: self._session = requests.Session() def log_job(self, request: LogJobRequest) -> LogJobResult: - response = self._session.post(self._config.endpoint_url, data=b"") + body = serialise_relay_request( + request_type="logjob", + parameters=[ + ("place_ref", request.place_ref), + ("std_job_code", STD_JOB_CODE), + ("client", CLIENT_CODE), + ("short_description", request.short_description), + ("long_description", request.long_description), + ("client_ref", request.client_ref), + ("appointment_date", request.appointment_date.strftime("%d/%m/%Y")), + ("appointment_time", request.appointment_time), + ("resource", self._config.default_resource), + ("resource_group", RESOURCE_GROUP), + ], + username=self._config.username, + password=self._config.password, + ) + response = self._session.post(self._config.endpoint_url, data=body) root = ET.fromstring(response.content) job_logged = root.find("Jobs/Job_logged") if job_logged is None: diff --git a/infrastructure/abri/envelope.py b/infrastructure/abri/envelope.py new file mode 100644 index 000000000..b7eeb89cd --- /dev/null +++ b/infrastructure/abri/envelope.py @@ -0,0 +1,23 @@ +import xml.etree.ElementTree as ET +from typing import Sequence, Tuple + + +def serialise_relay_request( + request_type: str, + parameters: Sequence[Tuple[str, str]], + username: str, + password: str, +) -> bytes: + message = ET.Element("message") + header = ET.SubElement(message, "Header") + ET.SubElement(header, "Security", username=username, password=password) + body = ET.SubElement(message, "Body") + request = ET.SubElement(body, "Request", request_type=request_type) + for attribute, attribute_value in parameters: + ET.SubElement( + request, + "Parameters", + attribute=attribute, + attribute_value=attribute_value, + ) + return ET.tostring(message, encoding="utf-8", xml_declaration=True) diff --git a/tests/infrastructure/abri/test_abri_client.py b/tests/infrastructure/abri/test_abri_client.py index ef91dee1d..0e0f8abb8 100644 --- a/tests/infrastructure/abri/test_abri_client.py +++ b/tests/infrastructure/abri/test_abri_client.py @@ -96,6 +96,6 @@ def test_log_job_sends_the_recorded_logjob_envelope_to_the_relay_endpoint( sent_body: bytes = mock_session.post.call_args.kwargs["data"] expected_body = _load_fixture("abri_relay_logjob_request_example.xml") assert url == ENDPOINT_URL - assert ET.canonicalize(xml_data=sent_body) == ET.canonicalize( - xml_data=expected_body + assert ET.canonicalize(xml_data=sent_body, strip_text=True) == ET.canonicalize( + xml_data=expected_body, strip_text=True )