Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: replace odt_information by booking_rule #4303

Merged
merged 3 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker/debian8/Dockerfile-tyr-worker
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM navitia/master

# Install some binaries from tartare-tools
ENV TARTARE_TOOLS_VERSION="v0.45.0"
ENV TARTARE_TOOLS_VERSION="v0.46.0"
ARG GITHUB_TOKEN
RUN git config --global url."https://x-access-token:${GITHUB_TOKEN}@github.com/hove-io/".insteadOf "ssh://[email protected]/hove-io/"
RUN git clone -b ${TARTARE_TOOLS_VERSION} --depth 1 https://x-access-token:${GITHUB_TOKEN}@github.com/hove-io/tartare-tools
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
SectionType,
CyclePathType,
BoardingPosition,
OdtInformation,
BookingRule,
)
import navitiacommon.response_pb2
from navitiacommon.type_pb2 import RTLevel
Expand Down Expand Up @@ -332,13 +332,13 @@ class RidesharingInformationSerializer(PbNestedSerializer):
seats = SeatsDescriptionSerializer(display_none=False)


class OdtInformationSerializer(PbNestedSerializer):
class BookingRuleSerializer(PbNestedSerializer):
name = jsonschema.Field(schema_type=str, display_none=True)
url = jsonschema.Field(schema_type=str, display_none=True)
condition = jsonschema.Field(schema_type=str, display_none=True)
phone = jsonschema.Field(schema_type=str, display_none=True)
deeplink = jsonschema.Field(schema_type=str, display_none=True)
applies_on = EnumListField(attr='applies_on', pb_type=OdtInformation.AppliesOn)
info_url = jsonschema.Field(schema_type=str, display_none=True)
message = jsonschema.Field(schema_type=str, display_none=True)
phone_number = jsonschema.Field(schema_type=str, display_none=True)
booking_url = jsonschema.Field(schema_type=str, display_none=True)
applies_on = EnumListField(attr='applies_on', pb_type=BookingRule.AppliesOn)


class SectionSerializer(PbNestedSerializer):
Expand Down Expand Up @@ -431,7 +431,7 @@ def get_ridesharing_journeys(self, obj):
street_informations = StreetInformationSerializer(
attr="street_network.street_information", many=True, display_none=False
)
odt_information = OdtInformationSerializer(display_none=False)
booking_rule = BookingRuleSerializer(display_none=False)


class JourneySerializer(PbNestedSerializer):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ def sort_key(self, obj):

@get_serializer(serpy=api.JourneysSerializer)
def abcd():
deeplink = "https://toto.com?from=from_value&to=to_value"
return helpers_tests.get_odt_journey(deeplink=deeplink)
booking_url = "https://toto.com?from=from_value&to=to_value"
return helpers_tests.get_odt_journey(booking_url=booking_url)


def odt_information_serialization_test():
def booking_rule_serialization_test():
with app.app_context():
with app.test_request_context():
g.timezone = pytz.utc
Expand All @@ -71,11 +71,11 @@ def odt_information_serialization_test():
journey = resp["journeys"][0]
assert len(journey.get("sections", 0)) == 3
section = journey["sections"][1]
odt_information = section.get("odt_information", None)
assert odt_information is not None
assert odt_information["url"] == "odt_url_value"
assert odt_information["name"] == "odt_name_value"
assert odt_information["phone"] == "odt_phone_value"
assert odt_information["condition"] == "odt_conditions_value"
assert odt_information["deeplink"] == "https://toto.com?from=from_value&to=to_value"
assert odt_information["applies_on"] == ["from"]
booking_rule = section.get("booking_rule", None)
assert booking_rule is not None
assert booking_rule["info_url"] == "odt_url_value"
assert booking_rule["name"] == "odt_name_value"
assert booking_rule["phone_number"] == "odt_phone_value"
assert booking_rule["message"] == "odt_conditions_value"
assert booking_rule["booking_url"] == "https://toto.com?from=from_value&to=to_value"
assert booking_rule["applies_on"] == ["from"]
12 changes: 6 additions & 6 deletions source/jormungandr/jormungandr/scenarios/new_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
get_disruptions_on_poi,
add_disruptions,
get_impact_uris_for_poi,
update_odt_information_deeplink_in_section,
update_booking_rule_url_in_section,
)
from navitiacommon import type_pb2, response_pb2, request_pb2
from jormungandr.scenarios.qualifier import (
Expand Down Expand Up @@ -540,9 +540,9 @@ def update_disruptions_on_pois(instance, pb_resp):
add_disruptions(pb_resp, poi_disruptions)


def update_odt_information_deeplink(pb_resp):
def update_booking_rule_url_in_response(pb_resp):
"""
Update placeholders present in sections[i].odt_information.deeplink with their values for each journey
Update placeholders present in sections[i].booking_rule.booking_url with their values for each journey
for each section of type ON_DEMAND_TRANSPORT
"""
if not pb_resp.journeys:
Expand All @@ -551,7 +551,7 @@ def update_odt_information_deeplink(pb_resp):
for j in pb_resp.journeys:
for s in j.sections:
if s.type == response_pb2.ON_DEMAND_TRANSPORT:
update_odt_information_deeplink_in_section(s)
update_booking_rule_url_in_section(s)


def update_total_air_pollutants(pb_resp):
Expand Down Expand Up @@ -1500,8 +1500,8 @@ def fill_journeys(self, request_type, api_request, instance):
# Update disruptions on pois
update_disruptions_on_pois(instance, pb_resp)

# Update deeplink in odt_information for all sections of type ON_DEMAND_TRANSPORT
update_odt_information_deeplink(pb_resp)
# Update booking_url in booking_rule for all sections of type ON_DEMAND_TRANSPORT
update_booking_rule_url_in_response(pb_resp)

self._compute_pagination_links(pb_resp, instance, api_request['clockwise'])
return pb_resp
Expand Down
16 changes: 8 additions & 8 deletions source/jormungandr/jormungandr/scenarios/tests/helpers_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ def verify_poi_in_impacted_objects(object, poi_empty=True):
assert object.poi.coord.lat == 2.0


def get_odt_journey(deeplink):
def get_odt_journey(booking_url):
response = response_pb2.Response()
journey = response.journeys.add()

Expand All @@ -661,13 +661,13 @@ def get_odt_journey(deeplink):
section.destination.stop_point.name = 'stop_b_name'
section.destination.stop_point.coord.lon = 3.0
section.destination.stop_point.coord.lat = 4.0
odt_information = section.odt_information
odt_information.name = "odt_name_value"
odt_information.deeplink = deeplink
odt_information.url = "odt_url_value"
odt_information.condition = "odt_conditions_value"
odt_information.phone = "odt_phone_value"
odt_information.applies_on.append(response_pb2.OdtInformation.AppliesOn.FROM)
booking_rule = section.booking_rule
booking_rule.name = "odt_name_value"
booking_rule.booking_url = booking_url
booking_rule.info_url = "odt_url_value"
booking_rule.message = "odt_conditions_value"
booking_rule.phone_number = "odt_phone_value"
booking_rule.applies_on.append(response_pb2.BookingRule.AppliesOn.FROM)
section = journey.sections.add()
section.type = response_pb2.STREET_NETWORK
section.street_network.mode = response_pb2.Walking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
get_kraken_calls,
update_best_boarding_positions,
update_disruptions_on_pois,
update_odt_information_deeplink,
update_booking_rule_url_in_response,
)
from jormungandr.instance import Instance
from jormungandr.scenarios.utils import switch_back_to_ridesharing
Expand Down Expand Up @@ -834,26 +834,26 @@ def journey_with_disruptions_on_poi_test(mocker):
return


def journey_with_odt_information_test():
deeplink = (
def journey_with_booking_rule_test():
booking_url = (
"https://domaine/search?departure-address={from_name}&destination-address={to_name}"
"&requested-departure-time={departure_datetime}&from_coord_lat={from_coord_lat}"
"&from_coord_lon={from_coord_lon}&not_managed={not_managed}"
)
response_journey_with_odt = helpers_tests.get_odt_journey(deeplink=deeplink)
response_journey_with_odt = helpers_tests.get_odt_journey(booking_url=booking_url)
assert len(response_journey_with_odt.journeys) == 1
journey = response_journey_with_odt.journeys[0]
assert len(journey.sections) == 3
odt_section = journey.sections[1]
assert odt_section.type == response_pb2.ON_DEMAND_TRANSPORT
assert (
odt_section.odt_information.deeplink
odt_section.booking_rule.booking_url
== "https://domaine/search?departure-address={from_name}&destination-address={to_name}&requested-departure-time={departure_datetime}&from_coord_lat={from_coord_lat}&from_coord_lon={from_coord_lon}&not_managed={not_managed}"
)

update_odt_information_deeplink(response_journey_with_odt)
update_booking_rule_url_in_response(response_journey_with_odt)
odt_section = response_journey_with_odt.journeys[0].sections[1]
assert (
odt_section.odt_information.deeplink
odt_section.booking_rule.booking_url
== "https://domaine/search?departure-address=stop%20a%20name&destination-address=stop_b_name&requested-departure-time=1722924300&from_coord_lat=2.0&from_coord_lon=1.0&not_managed=N/A"
)
46 changes: 23 additions & 23 deletions source/jormungandr/jormungandr/scenarios/tests/utils_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from jormungandr.scenarios.utils import (
fill_disruptions_on_pois,
fill_disruptions_on_places_nearby,
update_odt_information_deeplink_in_section,
update_booking_rule_url_in_section,
)

import pytest
Expand Down Expand Up @@ -101,59 +101,59 @@ def update_disruptions_on_pois_for_places_nearby_test(mocker):
return


def journey_with_deeplink_in_odt_information_test():
def journey_with_booking_url_in_booking_rule_test():
instance = lambda: None
# Get a response with a section of ODT having odt_information.
deeplink = (
# Get a response with a section of ODT having booking_rule.
booking_url = (
"https://domaine/search?departure-address={from_name}&destination-address={to_name}"
"&requested-departure-time={departure_datetime}&from_coord_lat={from_coord_lat}"
"&from_coord_lon={from_coord_lon}&to_coord_lat={to_coord_lat}&to_coord_lon={to_coord_lon}"
)
response_journey_with_odt = helpers_tests.get_odt_journey(deeplink=deeplink)
response_journey_with_odt = helpers_tests.get_odt_journey(booking_url=booking_url)
assert len(response_journey_with_odt.journeys) == 1
journey = response_journey_with_odt.journeys[0]
assert len(journey.sections) == 3
odt_section = journey.sections[1]
assert odt_section.type == response_pb2.ON_DEMAND_TRANSPORT
odt_information = odt_section.odt_information
assert odt_information.name == "odt_name_value"
booking_rule = odt_section.booking_rule
assert booking_rule.name == "odt_name_value"
assert (
odt_information.deeplink
booking_rule.booking_url
== "https://domaine/search?departure-address={from_name}&destination-address={to_name}&requested-departure-time={departure_datetime}&from_coord_lat={from_coord_lat}&from_coord_lon={from_coord_lon}&to_coord_lat={to_coord_lat}&to_coord_lon={to_coord_lon}"
)
assert odt_information.url == "odt_url_value"
assert odt_information.condition == "odt_conditions_value"
assert odt_information.phone == "odt_phone_value"
update_odt_information_deeplink_in_section(odt_section)
assert booking_rule.info_url == "odt_url_value"
assert booking_rule.message == "odt_conditions_value"
assert booking_rule.phone_number == "odt_phone_value"
update_booking_rule_url_in_section(odt_section)
assert (
odt_information.deeplink
booking_rule.booking_url
== "https://domaine/search?departure-address=stop%20a%20name&destination-address=stop_b_name&requested-departure-time=1722924300&from_coord_lat=2.0&from_coord_lon=1.0&to_coord_lat=4.0&to_coord_lon=3.0"
)

# Use a deeplink with fewer placeholders
deeplink = (
# Use a booking_url with fewer placeholders
booking_url = (
"https://domaine/search?departure-address={from_name}&destination-address={to_name}"
"&requested-departure-time={departure_datetime}&from_coord_lat={from_coord_lat}&from_coord_lon={from_coord_lon}"
)
response_journey_with_odt = helpers_tests.get_odt_journey(deeplink=deeplink)
response_journey_with_odt = helpers_tests.get_odt_journey(booking_url=booking_url)
odt_section = response_journey_with_odt.journeys[0].sections[1]
update_odt_information_deeplink_in_section(odt_section)
update_booking_rule_url_in_section(odt_section)
assert (
odt_section.odt_information.deeplink
odt_section.booking_rule.booking_url
== "https://domaine/search?departure-address=stop%20a%20name&destination-address=stop_b_name&requested-departure-time=1722924300&from_coord_lat=2.0&from_coord_lon=1.0"
)

# Add a placeholder which is not predefined in the function to update deeplink
# Add a placeholder which is not predefined in the function to update url
# This placeholder will not be replaced(updated)
deeplink = (
booking_url = (
"https://domaine/search?departure-address={from_name}&destination-address={to_name}"
"&requested-departure-time={departure_datetime}&from_coord_lat={from_coord_lat}"
"&from_coord_lon={from_coord_lon}&toto={toto}"
)
response_journey_with_odt = helpers_tests.get_odt_journey(deeplink=deeplink)
response_journey_with_odt = helpers_tests.get_odt_journey(booking_url=booking_url)
odt_section = response_journey_with_odt.journeys[0].sections[1]
update_odt_information_deeplink_in_section(odt_section)
update_booking_rule_url_in_section(odt_section)
assert (
odt_section.odt_information.deeplink
odt_section.booking_rule.booking_url
== "https://domaine/search?departure-address=stop%20a%20name&destination-address=stop_b_name&requested-departure-time=1722924300&from_coord_lat=2.0&from_coord_lon=1.0&toto=N/A"
)
16 changes: 9 additions & 7 deletions source/jormungandr/jormungandr/scenarios/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,12 +557,12 @@ def add_disruptions(pb_resp, pb_disruptions):
pb_resp.impacts.extend(pb_disruptions.impacts)


def update_odt_information_deeplink_in_section(section):
def update_booking_rule_url_in_section(section):
if section.type != response_pb2.ON_DEMAND_TRANSPORT:
return

deeplink = section.odt_information.deeplink
if not deeplink:
booking_url = section.booking_rule.booking_url
if not booking_url:
return

departure_datetime = section.begin_date_time
Expand All @@ -573,9 +573,9 @@ def update_odt_information_deeplink_in_section(section):
to_coord_lat = section.destination.stop_point.coord.lat
to_coord_lon = section.destination.stop_point.coord.lon

# Get all placeholders present in deeplink and match with predefined placeholder variables. value of those
# present in deeplink but absent in predefined placeholder variables will be replaced by N/A
placeholders = re.findall(r"{(\w+)}", deeplink)
# Get all placeholders present in booking_url and match with predefined placeholder variables. value of those
# present in booking_url but absent in predefined placeholder variables will be replaced by N/A
placeholders = re.findall(r"{(\w+)}", booking_url)

placeholder_dict = defaultdict(lambda: 'N/A')
fmtr = Formatter()
Expand All @@ -596,4 +596,6 @@ def update_odt_information_deeplink_in_section(section):
elif p == "to_coord_lon":
placeholder_dict[p] = to_coord_lon

section.odt_information.deeplink = requests.utils.requote_uri(fmtr.vformat(deeplink, (), placeholder_dict))
section.booking_rule.booking_url = requests.utils.requote_uri(
fmtr.vformat(booking_url, (), placeholder_dict)
)
2 changes: 1 addition & 1 deletion source/navitia-proto
Submodule navitia-proto updated 1 files
+6 −6 response.proto
Loading