diff --git a/source/jormungandr/jormungandr/scenarios/tests/helpers_tests.py b/source/jormungandr/jormungandr/scenarios/tests/helpers_tests.py index 03b9a3c058..1b43bec858 100644 --- a/source/jormungandr/jormungandr/scenarios/tests/helpers_tests.py +++ b/source/jormungandr/jormungandr/scenarios/tests/helpers_tests.py @@ -726,14 +726,14 @@ def get_odt_journey(booking_url): section.origin.embedded_type = type_pb2.STOP_POINT section.origin.stop_point.uri = 'stop_a' section.origin.stop_point.name = 'stop a name' - section.origin.stop_point.label = 'stop a name (city)' + section.origin.stop_point.label = "P+R d'Avon (city)" section.origin.stop_point.coord.lon = 1.0 section.origin.stop_point.coord.lat = 2.0 section.destination.uri = 'stop_b' section.destination.embedded_type = type_pb2.STOP_POINT section.destination.stop_point.uri = 'stop_b' section.destination.stop_point.name = 'stop_b_name' - section.destination.stop_point.label = 'stop_b_name (city)' + section.destination.stop_point.label = "gare de l'est (city)" section.destination.stop_point.coord.lon = 3.0 section.destination.stop_point.coord.lat = 4.0 booking_rule = section.booking_rule diff --git a/source/jormungandr/jormungandr/scenarios/tests/new_default_tests.py b/source/jormungandr/jormungandr/scenarios/tests/new_default_tests.py index 28e3337373..24382807c0 100644 --- a/source/jormungandr/jormungandr/scenarios/tests/new_default_tests.py +++ b/source/jormungandr/jormungandr/scenarios/tests/new_default_tests.py @@ -865,5 +865,5 @@ def journey_with_booking_rule_test(): odt_section = response_journey_with_odt.journeys[0].sections[1] assert ( odt_section.booking_rule.booking_url - == "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¬_managed=N/A" + == "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¬_managed=N/A" ) diff --git a/source/jormungandr/jormungandr/scenarios/tests/utils_tests.py b/source/jormungandr/jormungandr/scenarios/tests/utils_tests.py index 575432b5cc..b7296ba785 100644 --- a/source/jormungandr/jormungandr/scenarios/tests/utils_tests.py +++ b/source/jormungandr/jormungandr/scenarios/tests/utils_tests.py @@ -130,7 +130,7 @@ def journey_with_booking_url_in_booking_rule_test(): update_booking_rule_url_in_section(odt_section) assert ( booking_rule.booking_url - == "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" + == "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" ) # Use a booking_url with fewer placeholders @@ -143,7 +143,7 @@ def journey_with_booking_url_in_booking_rule_test(): update_booking_rule_url_in_section(odt_section) assert ( odt_section.booking_rule.booking_url - == "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" + == "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" ) # 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(): update_booking_rule_url_in_section(odt_section) assert ( odt_section.booking_rule.booking_url - == "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" + == "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" ) diff --git a/source/jormungandr/jormungandr/scenarios/utils.py b/source/jormungandr/jormungandr/scenarios/utils.py index 8ec60adc26..c954aefc20 100644 --- a/source/jormungandr/jormungandr/scenarios/utils.py +++ b/source/jormungandr/jormungandr/scenarios/utils.py @@ -35,7 +35,7 @@ from jormungandr.fallback_modes import FallbackModes from jormungandr.utils import timestamp_to_date_str from jormungandr.timezone import get_timezone_or_paris -import requests as requests +from six.moves.urllib.parse import quote import re from collections import defaultdict from string import Formatter @@ -585,23 +585,22 @@ def update_booking_rule_url_in_section(section): # Datetime formatting: "%Y-%m-%dT%H:%M:%S%z" -> 2024-09-24T09:25:45+0200 date_format = "%Y-%m-%dT%H:%M:%S%z" timezone = get_timezone_or_paris() + departure_datetime_str = timestamp_to_date_str(departure_datetime, timezone, _format=date_format) for p in placeholders: if p == "departure_datetime": - placeholder_dict[p] = timestamp_to_date_str(departure_datetime, timezone, _format=date_format) + placeholder_dict[p] = quote(departure_datetime_str) elif p == "from_name": - placeholder_dict[p] = from_name + placeholder_dict[p] = quote(from_name) elif p == "from_coord_lat": placeholder_dict[p] = from_coord_lat elif p == "from_coord_lon": placeholder_dict[p] = from_coord_lon elif p == "to_name": - placeholder_dict[p] = to_name + placeholder_dict[p] = quote(to_name) elif p == "to_coord_lat": placeholder_dict[p] = to_coord_lat elif p == "to_coord_lon": placeholder_dict[p] = to_coord_lon - section.booking_rule.booking_url = requests.utils.requote_uri( - fmtr.vformat(booking_url, (), placeholder_dict) - ) + section.booking_rule.booking_url = fmtr.vformat(booking_url, (), placeholder_dict)