From 59864f12fbb7fa5a8d0d8042312c789f766e1d04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Hansmann?= Date: Mon, 11 Nov 2024 12:06:43 +0100 Subject: [PATCH] PB-974: strip any non needed whitespaces from the payload --- chsdi/lib/opentransapi/opentransapi.py | 4 +++- tests/integration/test_opentransapi.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/chsdi/lib/opentransapi/opentransapi.py b/chsdi/lib/opentransapi/opentransapi.py index 4f1e73d41f..20029b833d 100644 --- a/chsdi/lib/opentransapi/opentransapi.py +++ b/chsdi/lib/opentransapi/opentransapi.py @@ -117,7 +117,9 @@ def create_ojp_payload(self, station_id, request_dt_time, number_results=5): """ - return payload + # strip any non needed whitespaces from the payload in order to keep the data traffic to + # the minimum necessary + return re.sub(r">\s+<", "><", payload.strip()) def send_post(self, station_id, request_dt_time, number_results=5): headers = { diff --git a/tests/integration/test_opentransapi.py b/tests/integration/test_opentransapi.py index 04191e56c5..1b66d33675 100644 --- a/tests/integration/test_opentransapi.py +++ b/tests/integration/test_opentransapi.py @@ -59,4 +59,4 @@ def test_time_utc_zurich(self, mock_get_departures): time_next_dep_zurich = datetime.strptime(results[0]['departureDate'], '%d/%m/%Y %H:%M') time_diff = abs(time_zurich_tomorrow_12 - time_next_dep_zurich).seconds - self.assertLess(time_diff, 900) # Assuming the next train in Zurich will depart within 15 minutes + self.assertLess(time_diff, 900) # assuming, that the next train in Zurich at 12am will depart within 15 min