Skip to content

Commit

Permalink
[jormun]: Fix on datetime format for booking_rule
Browse files Browse the repository at this point in the history
  • Loading branch information
kadhikari committed Oct 18, 2024
1 parent 6b42cbe commit 1743dc3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
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=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"
)
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=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"
)

# 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=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"
)

# 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=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"
)
4 changes: 3 additions & 1 deletion source/jormungandr/jormungandr/scenarios/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from jormungandr.fallback_modes import FallbackModes
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
Expand Down Expand Up @@ -585,10 +586,11 @@ 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
elif p == "from_coord_lat":
Expand Down

0 comments on commit 1743dc3

Please sign in to comment.