Skip to content

Commit

Permalink
PB-974: strip any non needed whitespaces from the payload
Browse files Browse the repository at this point in the history
  • Loading branch information
hansmannj committed Nov 11, 2024
1 parent 7e78c61 commit 59864f1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion chsdi/lib/opentransapi/opentransapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ def create_ojp_payload(self, station_id, request_dt_time, number_results=5):
</OJPRequest>
</OJP>
"""
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 = {
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_opentransapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 59864f1

Please sign in to comment.