Skip to content

Commit

Permalink
Merge pull request #4314 from hove-io/fix_datetime_format_in_booking_…
Browse files Browse the repository at this point in the history
…rule

[jormun]: Fix on datetime format for booking_rule
  • Loading branch information
kadhikari authored Oct 18, 2024
2 parents 167f0ea + 0ecef31 commit 9ab243e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 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:05:00+0200&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: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
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: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
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: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"
)
13 changes: 6 additions & 7 deletions source/jormungandr/jormungandr/scenarios/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 9ab243e

Please sign in to comment.