Skip to content

Commit 7adbf7f

Browse files
authored
Merge pull request #4303 from hove-io/fix_odt_information_to_booking_rule
Fix: replace odt_information by booking_rule
2 parents 584e6a3 + 92d6772 commit 7adbf7f

File tree

9 files changed

+74
-72
lines changed

9 files changed

+74
-72
lines changed

docker/debian8/Dockerfile-tyr-worker

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM navitia/master
22

33
# Install some binaries from tartare-tools
4-
ENV TARTARE_TOOLS_VERSION="v0.45.0"
4+
ENV TARTARE_TOOLS_VERSION="v0.46.0"
55
ARG GITHUB_TOKEN
66
RUN git config --global url."https://x-access-token:${GITHUB_TOKEN}@github.com/hove-io/".insteadOf "ssh://[email protected]/hove-io/"
77
RUN git clone -b ${TARTARE_TOOLS_VERSION} --depth 1 https://x-access-token:${GITHUB_TOKEN}@github.com/hove-io/tartare-tools

source/jormungandr/jormungandr/interfaces/v1/serializer/journey.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
SectionType,
6969
CyclePathType,
7070
BoardingPosition,
71-
OdtInformation,
71+
BookingRule,
7272
)
7373
import navitiacommon.response_pb2
7474
from navitiacommon.type_pb2 import RTLevel
@@ -332,13 +332,13 @@ class RidesharingInformationSerializer(PbNestedSerializer):
332332
seats = SeatsDescriptionSerializer(display_none=False)
333333

334334

335-
class OdtInformationSerializer(PbNestedSerializer):
335+
class BookingRuleSerializer(PbNestedSerializer):
336336
name = jsonschema.Field(schema_type=str, display_none=True)
337-
url = jsonschema.Field(schema_type=str, display_none=True)
338-
condition = jsonschema.Field(schema_type=str, display_none=True)
339-
phone = jsonschema.Field(schema_type=str, display_none=True)
340-
deeplink = jsonschema.Field(schema_type=str, display_none=True)
341-
applies_on = EnumListField(attr='applies_on', pb_type=OdtInformation.AppliesOn)
337+
info_url = jsonschema.Field(schema_type=str, display_none=True)
338+
message = jsonschema.Field(schema_type=str, display_none=True)
339+
phone_number = jsonschema.Field(schema_type=str, display_none=True)
340+
booking_url = jsonschema.Field(schema_type=str, display_none=True)
341+
applies_on = EnumListField(attr='applies_on', pb_type=BookingRule.AppliesOn)
342342

343343

344344
class SectionSerializer(PbNestedSerializer):
@@ -431,7 +431,7 @@ def get_ridesharing_journeys(self, obj):
431431
street_informations = StreetInformationSerializer(
432432
attr="street_network.street_information", many=True, display_none=False
433433
)
434-
odt_information = OdtInformationSerializer(display_none=False)
434+
booking_rule = BookingRuleSerializer(display_none=False)
435435

436436

437437
class JourneySerializer(PbNestedSerializer):

source/jormungandr/jormungandr/interfaces/v1/test/serializer_tests.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ def sort_key(self, obj):
5757

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

6363

64-
def odt_information_serialization_test():
64+
def booking_rule_serialization_test():
6565
with app.app_context():
6666
with app.test_request_context():
6767
g.timezone = pytz.utc
@@ -71,11 +71,11 @@ def odt_information_serialization_test():
7171
journey = resp["journeys"][0]
7272
assert len(journey.get("sections", 0)) == 3
7373
section = journey["sections"][1]
74-
odt_information = section.get("odt_information", None)
75-
assert odt_information is not None
76-
assert odt_information["url"] == "odt_url_value"
77-
assert odt_information["name"] == "odt_name_value"
78-
assert odt_information["phone"] == "odt_phone_value"
79-
assert odt_information["condition"] == "odt_conditions_value"
80-
assert odt_information["deeplink"] == "https://toto.com?from=from_value&to=to_value"
81-
assert odt_information["applies_on"] == ["from"]
74+
booking_rule = section.get("booking_rule", None)
75+
assert booking_rule is not None
76+
assert booking_rule["info_url"] == "odt_url_value"
77+
assert booking_rule["name"] == "odt_name_value"
78+
assert booking_rule["phone_number"] == "odt_phone_value"
79+
assert booking_rule["message"] == "odt_conditions_value"
80+
assert booking_rule["booking_url"] == "https://toto.com?from=from_value&to=to_value"
81+
assert booking_rule["applies_on"] == ["from"]

source/jormungandr/jormungandr/scenarios/new_default.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
get_disruptions_on_poi,
5151
add_disruptions,
5252
get_impact_uris_for_poi,
53-
update_odt_information_deeplink_in_section,
53+
update_booking_rule_url_in_section,
5454
)
5555
from navitiacommon import type_pb2, response_pb2, request_pb2
5656
from jormungandr.scenarios.qualifier import (
@@ -540,9 +540,9 @@ def update_disruptions_on_pois(instance, pb_resp):
540540
add_disruptions(pb_resp, poi_disruptions)
541541

542542

543-
def update_odt_information_deeplink(pb_resp):
543+
def update_booking_rule_url_in_response(pb_resp):
544544
"""
545-
Update placeholders present in sections[i].odt_information.deeplink with their values for each journey
545+
Update placeholders present in sections[i].booking_rule.booking_url with their values for each journey
546546
for each section of type ON_DEMAND_TRANSPORT
547547
"""
548548
if not pb_resp.journeys:
@@ -551,7 +551,7 @@ def update_odt_information_deeplink(pb_resp):
551551
for j in pb_resp.journeys:
552552
for s in j.sections:
553553
if s.type == response_pb2.ON_DEMAND_TRANSPORT:
554-
update_odt_information_deeplink_in_section(s)
554+
update_booking_rule_url_in_section(s)
555555

556556

557557
def update_total_air_pollutants(pb_resp):
@@ -1500,8 +1500,8 @@ def fill_journeys(self, request_type, api_request, instance):
15001500
# Update disruptions on pois
15011501
update_disruptions_on_pois(instance, pb_resp)
15021502

1503-
# Update deeplink in odt_information for all sections of type ON_DEMAND_TRANSPORT
1504-
update_odt_information_deeplink(pb_resp)
1503+
# Update booking_url in booking_rule for all sections of type ON_DEMAND_TRANSPORT
1504+
update_booking_rule_url_in_response(pb_resp)
15051505

15061506
self._compute_pagination_links(pb_resp, instance, api_request['clockwise'])
15071507
return pb_resp

source/jormungandr/jormungandr/scenarios/tests/helpers_tests.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ def verify_poi_in_impacted_objects(object, poi_empty=True):
637637
assert object.poi.coord.lat == 2.0
638638

639639

640-
def get_odt_journey(deeplink):
640+
def get_odt_journey(booking_url):
641641
response = response_pb2.Response()
642642
journey = response.journeys.add()
643643

@@ -661,13 +661,13 @@ def get_odt_journey(deeplink):
661661
section.destination.stop_point.name = 'stop_b_name'
662662
section.destination.stop_point.coord.lon = 3.0
663663
section.destination.stop_point.coord.lat = 4.0
664-
odt_information = section.odt_information
665-
odt_information.name = "odt_name_value"
666-
odt_information.deeplink = deeplink
667-
odt_information.url = "odt_url_value"
668-
odt_information.condition = "odt_conditions_value"
669-
odt_information.phone = "odt_phone_value"
670-
odt_information.applies_on.append(response_pb2.OdtInformation.AppliesOn.FROM)
664+
booking_rule = section.booking_rule
665+
booking_rule.name = "odt_name_value"
666+
booking_rule.booking_url = booking_url
667+
booking_rule.info_url = "odt_url_value"
668+
booking_rule.message = "odt_conditions_value"
669+
booking_rule.phone_number = "odt_phone_value"
670+
booking_rule.applies_on.append(response_pb2.BookingRule.AppliesOn.FROM)
671671
section = journey.sections.add()
672672
section.type = response_pb2.STREET_NETWORK
673673
section.street_network.mode = response_pb2.Walking

source/jormungandr/jormungandr/scenarios/tests/new_default_tests.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
get_kraken_calls,
3939
update_best_boarding_positions,
4040
update_disruptions_on_pois,
41-
update_odt_information_deeplink,
41+
update_booking_rule_url_in_response,
4242
)
4343
from jormungandr.instance import Instance
4444
from jormungandr.scenarios.utils import switch_back_to_ridesharing
@@ -834,26 +834,26 @@ def journey_with_disruptions_on_poi_test(mocker):
834834
return
835835

836836

837-
def journey_with_odt_information_test():
838-
deeplink = (
837+
def journey_with_booking_rule_test():
838+
booking_url = (
839839
"https://domaine/search?departure-address={from_name}&destination-address={to_name}"
840840
"&requested-departure-time={departure_datetime}&from_coord_lat={from_coord_lat}"
841841
"&from_coord_lon={from_coord_lon}&not_managed={not_managed}"
842842
)
843-
response_journey_with_odt = helpers_tests.get_odt_journey(deeplink=deeplink)
843+
response_journey_with_odt = helpers_tests.get_odt_journey(booking_url=booking_url)
844844
assert len(response_journey_with_odt.journeys) == 1
845845
journey = response_journey_with_odt.journeys[0]
846846
assert len(journey.sections) == 3
847847
odt_section = journey.sections[1]
848848
assert odt_section.type == response_pb2.ON_DEMAND_TRANSPORT
849849
assert (
850-
odt_section.odt_information.deeplink
850+
odt_section.booking_rule.booking_url
851851
== "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}"
852852
)
853853

854-
update_odt_information_deeplink(response_journey_with_odt)
854+
update_booking_rule_url_in_response(response_journey_with_odt)
855855
odt_section = response_journey_with_odt.journeys[0].sections[1]
856856
assert (
857-
odt_section.odt_information.deeplink
857+
odt_section.booking_rule.booking_url
858858
== "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"
859859
)

source/jormungandr/jormungandr/scenarios/tests/utils_tests.py

+23-23
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from jormungandr.scenarios.utils import (
3333
fill_disruptions_on_pois,
3434
fill_disruptions_on_places_nearby,
35-
update_odt_information_deeplink_in_section,
35+
update_booking_rule_url_in_section,
3636
)
3737

3838
import pytest
@@ -101,59 +101,59 @@ def update_disruptions_on_pois_for_places_nearby_test(mocker):
101101
return
102102

103103

104-
def journey_with_deeplink_in_odt_information_test():
104+
def journey_with_booking_url_in_booking_rule_test():
105105
instance = lambda: None
106-
# Get a response with a section of ODT having odt_information.
107-
deeplink = (
106+
# Get a response with a section of ODT having booking_rule.
107+
booking_url = (
108108
"https://domaine/search?departure-address={from_name}&destination-address={to_name}"
109109
"&requested-departure-time={departure_datetime}&from_coord_lat={from_coord_lat}"
110110
"&from_coord_lon={from_coord_lon}&to_coord_lat={to_coord_lat}&to_coord_lon={to_coord_lon}"
111111
)
112-
response_journey_with_odt = helpers_tests.get_odt_journey(deeplink=deeplink)
112+
response_journey_with_odt = helpers_tests.get_odt_journey(booking_url=booking_url)
113113
assert len(response_journey_with_odt.journeys) == 1
114114
journey = response_journey_with_odt.journeys[0]
115115
assert len(journey.sections) == 3
116116
odt_section = journey.sections[1]
117117
assert odt_section.type == response_pb2.ON_DEMAND_TRANSPORT
118-
odt_information = odt_section.odt_information
119-
assert odt_information.name == "odt_name_value"
118+
booking_rule = odt_section.booking_rule
119+
assert booking_rule.name == "odt_name_value"
120120
assert (
121-
odt_information.deeplink
121+
booking_rule.booking_url
122122
== "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}"
123123
)
124-
assert odt_information.url == "odt_url_value"
125-
assert odt_information.condition == "odt_conditions_value"
126-
assert odt_information.phone == "odt_phone_value"
127-
update_odt_information_deeplink_in_section(odt_section)
124+
assert booking_rule.info_url == "odt_url_value"
125+
assert booking_rule.message == "odt_conditions_value"
126+
assert booking_rule.phone_number == "odt_phone_value"
127+
update_booking_rule_url_in_section(odt_section)
128128
assert (
129-
odt_information.deeplink
129+
booking_rule.booking_url
130130
== "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"
131131
)
132132

133-
# Use a deeplink with fewer placeholders
134-
deeplink = (
133+
# Use a booking_url with fewer placeholders
134+
booking_url = (
135135
"https://domaine/search?departure-address={from_name}&destination-address={to_name}"
136136
"&requested-departure-time={departure_datetime}&from_coord_lat={from_coord_lat}&from_coord_lon={from_coord_lon}"
137137
)
138-
response_journey_with_odt = helpers_tests.get_odt_journey(deeplink=deeplink)
138+
response_journey_with_odt = helpers_tests.get_odt_journey(booking_url=booking_url)
139139
odt_section = response_journey_with_odt.journeys[0].sections[1]
140-
update_odt_information_deeplink_in_section(odt_section)
140+
update_booking_rule_url_in_section(odt_section)
141141
assert (
142-
odt_section.odt_information.deeplink
142+
odt_section.booking_rule.booking_url
143143
== "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"
144144
)
145145

146-
# Add a placeholder which is not predefined in the function to update deeplink
146+
# Add a placeholder which is not predefined in the function to update url
147147
# This placeholder will not be replaced(updated)
148-
deeplink = (
148+
booking_url = (
149149
"https://domaine/search?departure-address={from_name}&destination-address={to_name}"
150150
"&requested-departure-time={departure_datetime}&from_coord_lat={from_coord_lat}"
151151
"&from_coord_lon={from_coord_lon}&toto={toto}"
152152
)
153-
response_journey_with_odt = helpers_tests.get_odt_journey(deeplink=deeplink)
153+
response_journey_with_odt = helpers_tests.get_odt_journey(booking_url=booking_url)
154154
odt_section = response_journey_with_odt.journeys[0].sections[1]
155-
update_odt_information_deeplink_in_section(odt_section)
155+
update_booking_rule_url_in_section(odt_section)
156156
assert (
157-
odt_section.odt_information.deeplink
157+
odt_section.booking_rule.booking_url
158158
== "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"
159159
)

source/jormungandr/jormungandr/scenarios/utils.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -557,12 +557,12 @@ def add_disruptions(pb_resp, pb_disruptions):
557557
pb_resp.impacts.extend(pb_disruptions.impacts)
558558

559559

560-
def update_odt_information_deeplink_in_section(section):
560+
def update_booking_rule_url_in_section(section):
561561
if section.type != response_pb2.ON_DEMAND_TRANSPORT:
562562
return
563563

564-
deeplink = section.odt_information.deeplink
565-
if not deeplink:
564+
booking_url = section.booking_rule.booking_url
565+
if not booking_url:
566566
return
567567

568568
departure_datetime = section.begin_date_time
@@ -573,9 +573,9 @@ def update_odt_information_deeplink_in_section(section):
573573
to_coord_lat = section.destination.stop_point.coord.lat
574574
to_coord_lon = section.destination.stop_point.coord.lon
575575

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

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

599-
section.odt_information.deeplink = requests.utils.requote_uri(fmtr.vformat(deeplink, (), placeholder_dict))
599+
section.booking_rule.booking_url = requests.utils.requote_uri(
600+
fmtr.vformat(booking_url, (), placeholder_dict)
601+
)

source/navitia-proto

0 commit comments

Comments
 (0)