Skip to content

Commit

Permalink
Use quote for all the param values of type text
Browse files Browse the repository at this point in the history
  • Loading branch information
kadhikari committed Oct 18, 2024
1 parent 1743dc3 commit 0ecef31
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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%3A05%3A00%2B0200&from_coord_lat=2.0&from_coord_lon=1.0&not_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&not_managed=N/A"
)
6 changes: 3 additions & 3 deletions source/jormungandr/jormungandr/scenarios/tests/utils_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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%3A05%3A00%2B0200&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
Expand All @@ -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%3A05%3A00%2B0200&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
Expand All @@ -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%3A05%3A00%2B0200&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"
)
9 changes: 3 additions & 6 deletions source/jormungandr/jormungandr/scenarios/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
from jormungandr.utils import timestamp_to_date_str
from jormungandr.timezone import get_timezone_or_paris
from six.moves.urllib.parse import quote
import requests as requests
import re
from collections import defaultdict
from string import Formatter
Expand Down Expand Up @@ -592,18 +591,16 @@ def update_booking_rule_url_in_section(section):
if p == "departure_datetime":
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)

0 comments on commit 0ecef31

Please sign in to comment.