mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-12 13:29:04 +00:00
Abri log_job sends the spec's recorded LogJob envelope to the relay endpoint 🟩
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
4803ae40e1
commit
79ce9dc4b1
3 changed files with 48 additions and 3 deletions
|
|
@ -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:
|
||||
|
|
|
|||
23
infrastructure/abri/envelope.py
Normal file
23
infrastructure/abri/envelope.py
Normal file
|
|
@ -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)
|
||||
|
|
@ -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
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue