Skip to content

Commit 9ab243e

Browse files
authored
Merge pull request #4314 from hove-io/fix_datetime_format_in_booking_rule
[jormun]: Fix on datetime format for booking_rule
2 parents 167f0ea + 0ecef31 commit 9ab243e

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

source/jormungandr/jormungandr/scenarios/tests/helpers_tests.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -726,14 +726,14 @@ def get_odt_journey(booking_url):
726726
section.origin.embedded_type = type_pb2.STOP_POINT
727727
section.origin.stop_point.uri = 'stop_a'
728728
section.origin.stop_point.name = 'stop a name'
729-
section.origin.stop_point.label = 'stop a name (city)'
729+
section.origin.stop_point.label = "P+R d'Avon (city)"
730730
section.origin.stop_point.coord.lon = 1.0
731731
section.origin.stop_point.coord.lat = 2.0
732732
section.destination.uri = 'stop_b'
733733
section.destination.embedded_type = type_pb2.STOP_POINT
734734
section.destination.stop_point.uri = 'stop_b'
735735
section.destination.stop_point.name = 'stop_b_name'
736-
section.destination.stop_point.label = 'stop_b_name (city)'
736+
section.destination.stop_point.label = "gare de l'est (city)"
737737
section.destination.stop_point.coord.lon = 3.0
738738
section.destination.stop_point.coord.lat = 4.0
739739
booking_rule = section.booking_rule

source/jormungandr/jormungandr/scenarios/tests/new_default_tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -865,5 +865,5 @@ def journey_with_booking_rule_test():
865865
odt_section = response_journey_with_odt.journeys[0].sections[1]
866866
assert (
867867
odt_section.booking_rule.booking_url
868-
== "https://domaine/search?departure-address=stop%20a%20name%20(city)&destination-address=stop_b_name%20(city)&requested-departure-time=2024-08-06T08:05:00+0200&from_coord_lat=2.0&from_coord_lon=1.0&not_managed=N/A"
868+
== "https://domaine/search?departure-address=P%2BR%20d%27Avon%20%28city%29&destination-address=gare%20de%20l%27est%20%28city%29&requested-departure-time=2024-08-06T08%3A05%3A00%2B0200&from_coord_lat=2.0&from_coord_lon=1.0&not_managed=N/A"
869869
)

source/jormungandr/jormungandr/scenarios/tests/utils_tests.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def journey_with_booking_url_in_booking_rule_test():
130130
update_booking_rule_url_in_section(odt_section)
131131
assert (
132132
booking_rule.booking_url
133-
== "https://domaine/search?departure-address=stop%20a%20name%20(city)&destination-address=stop_b_name%20(city)&requested-departure-time=2024-08-06T08:05:00+0200&from_coord_lat=2.0&from_coord_lon=1.0&to_coord_lat=4.0&to_coord_lon=3.0"
133+
== "https://domaine/search?departure-address=P%2BR%20d%27Avon%20%28city%29&destination-address=gare%20de%20l%27est%20%28city%29&requested-departure-time=2024-08-06T08%3A05%3A00%2B0200&from_coord_lat=2.0&from_coord_lon=1.0&to_coord_lat=4.0&to_coord_lon=3.0"
134134
)
135135

136136
# Use a booking_url with fewer placeholders
@@ -143,7 +143,7 @@ def journey_with_booking_url_in_booking_rule_test():
143143
update_booking_rule_url_in_section(odt_section)
144144
assert (
145145
odt_section.booking_rule.booking_url
146-
== "https://domaine/search?departure-address=stop%20a%20name%20(city)&destination-address=stop_b_name%20(city)&requested-departure-time=2024-08-06T08:05:00+0200&from_coord_lat=2.0&from_coord_lon=1.0"
146+
== "https://domaine/search?departure-address=P%2BR%20d%27Avon%20%28city%29&destination-address=gare%20de%20l%27est%20%28city%29&requested-departure-time=2024-08-06T08%3A05%3A00%2B0200&from_coord_lat=2.0&from_coord_lon=1.0"
147147
)
148148

149149
# Add a placeholder which is not predefined in the function to update url
@@ -158,5 +158,5 @@ def journey_with_booking_url_in_booking_rule_test():
158158
update_booking_rule_url_in_section(odt_section)
159159
assert (
160160
odt_section.booking_rule.booking_url
161-
== "https://domaine/search?departure-address=stop%20a%20name%20(city)&destination-address=stop_b_name%20(city)&requested-departure-time=2024-08-06T08:05:00+0200&from_coord_lat=2.0&from_coord_lon=1.0&toto=N/A"
161+
== "https://domaine/search?departure-address=P%2BR%20d%27Avon%20%28city%29&destination-address=gare%20de%20l%27est%20%28city%29&requested-departure-time=2024-08-06T08%3A05%3A00%2B0200&from_coord_lat=2.0&from_coord_lon=1.0&toto=N/A"
162162
)

source/jormungandr/jormungandr/scenarios/utils.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from jormungandr.fallback_modes import FallbackModes
3636
from jormungandr.utils import timestamp_to_date_str
3737
from jormungandr.timezone import get_timezone_or_paris
38-
import requests as requests
38+
from six.moves.urllib.parse import quote
3939
import re
4040
from collections import defaultdict
4141
from string import Formatter
@@ -585,23 +585,22 @@ def update_booking_rule_url_in_section(section):
585585
# Datetime formatting: "%Y-%m-%dT%H:%M:%S%z" -> 2024-09-24T09:25:45+0200
586586
date_format = "%Y-%m-%dT%H:%M:%S%z"
587587
timezone = get_timezone_or_paris()
588+
departure_datetime_str = timestamp_to_date_str(departure_datetime, timezone, _format=date_format)
588589

589590
for p in placeholders:
590591
if p == "departure_datetime":
591-
placeholder_dict[p] = timestamp_to_date_str(departure_datetime, timezone, _format=date_format)
592+
placeholder_dict[p] = quote(departure_datetime_str)
592593
elif p == "from_name":
593-
placeholder_dict[p] = from_name
594+
placeholder_dict[p] = quote(from_name)
594595
elif p == "from_coord_lat":
595596
placeholder_dict[p] = from_coord_lat
596597
elif p == "from_coord_lon":
597598
placeholder_dict[p] = from_coord_lon
598599
elif p == "to_name":
599-
placeholder_dict[p] = to_name
600+
placeholder_dict[p] = quote(to_name)
600601
elif p == "to_coord_lat":
601602
placeholder_dict[p] = to_coord_lat
602603
elif p == "to_coord_lon":
603604
placeholder_dict[p] = to_coord_lon
604605

605-
section.booking_rule.booking_url = requests.utils.requote_uri(
606-
fmtr.vformat(booking_url, (), placeholder_dict)
607-
)
606+
section.booking_rule.booking_url = fmtr.vformat(booking_url, (), placeholder_dict)

0 commit comments

Comments
 (0)