|
29 | 29 |
|
30 | 30 | from navitiacommon import type_pb2, response_pb2
|
31 | 31 | import jormungandr.scenarios.tests.helpers_tests as helpers_tests
|
32 |
| -from jormungandr.scenarios.utils import fill_disruptions_on_pois, fill_disruptions_on_places_nearby |
| 32 | +from jormungandr.scenarios.utils import ( |
| 33 | + fill_disruptions_on_pois, |
| 34 | + fill_disruptions_on_places_nearby, |
| 35 | + update_odt_information_deeplink_in_section, |
| 36 | +) |
| 37 | + |
33 | 38 | import pytest
|
34 | 39 | from pytest_mock import mocker
|
35 | 40 |
|
@@ -94,3 +99,61 @@ def update_disruptions_on_pois_for_places_nearby_test(mocker):
|
94 | 99 |
|
95 | 100 | mock.assert_called_once()
|
96 | 101 | return
|
| 102 | + |
| 103 | + |
| 104 | +def journey_with_deeplink_in_odt_information_test(): |
| 105 | + instance = lambda: None |
| 106 | + # Get a response with a section of ODT having odt_information. |
| 107 | + deeplink = ( |
| 108 | + "https://domaine/search?departure-address={from_name}&destination-address={to_name}" |
| 109 | + "&requested-departure-time={departure_datetime}&from_coord_lat={from_coord_lat}" |
| 110 | + "&from_coord_lon={from_coord_lon}&to_coord_lat={to_coord_lat}&to_coord_lon={to_coord_lon}" |
| 111 | + ) |
| 112 | + response_journey_with_odt = helpers_tests.get_odt_journey(deeplink=deeplink) |
| 113 | + assert len(response_journey_with_odt.journeys) == 1 |
| 114 | + journey = response_journey_with_odt.journeys[0] |
| 115 | + assert len(journey.sections) == 3 |
| 116 | + odt_section = journey.sections[1] |
| 117 | + assert odt_section.type == response_pb2.ON_DEMAND_TRANSPORT |
| 118 | + odt_information = odt_section.odt_informations |
| 119 | + assert odt_information.name == "odt_name_value" |
| 120 | + assert ( |
| 121 | + odt_information.deeplink |
| 122 | + == "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}" |
| 123 | + ) |
| 124 | + assert odt_information.url == "odt_url_value" |
| 125 | + assert odt_information.conditions == "odt_conditions_value" |
| 126 | + assert odt_information.phone == "odt_phone_value" |
| 127 | + update_odt_information_deeplink_in_section(odt_section) |
| 128 | + assert ( |
| 129 | + odt_information.deeplink |
| 130 | + == "https://domaine/search?departure-address=stop_a_name&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" |
| 131 | + ) |
| 132 | + |
| 133 | + # Use a deeplink with fewer placeholders |
| 134 | + deeplink = ( |
| 135 | + "https://domaine/search?departure-address={from_name}&destination-address={to_name}" |
| 136 | + "&requested-departure-time={departure_datetime}&from_coord_lat={from_coord_lat}&from_coord_lon={from_coord_lon}" |
| 137 | + ) |
| 138 | + response_journey_with_odt = helpers_tests.get_odt_journey(deeplink=deeplink) |
| 139 | + odt_section = response_journey_with_odt.journeys[0].sections[1] |
| 140 | + update_odt_information_deeplink_in_section(odt_section) |
| 141 | + assert ( |
| 142 | + odt_section.odt_informations.deeplink |
| 143 | + == "https://domaine/search?departure-address=stop_a_name&destination-address=stop_b_name&requested-departure-time=1722924300&from_coord_lat=2.0&from_coord_lon=1.0" |
| 144 | + ) |
| 145 | + |
| 146 | + # Add a placeholder which is not predefined in the function to update deeplink |
| 147 | + # This placeholder will not be replaced(updated) |
| 148 | + deeplink = ( |
| 149 | + "https://domaine/search?departure-address={from_name}&destination-address={to_name}" |
| 150 | + "&requested-departure-time={departure_datetime}&from_coord_lat={from_coord_lat}" |
| 151 | + "&from_coord_lon={from_coord_lon}&toto={toto}" |
| 152 | + ) |
| 153 | + response_journey_with_odt = helpers_tests.get_odt_journey(deeplink=deeplink) |
| 154 | + odt_section = response_journey_with_odt.journeys[0].sections[1] |
| 155 | + update_odt_information_deeplink_in_section(odt_section) |
| 156 | + assert ( |
| 157 | + odt_section.odt_informations.deeplink |
| 158 | + == "https://domaine/search?departure-address=stop_a_name&destination-address=stop_b_name&requested-departure-time=1722924300&from_coord_lat=2.0&from_coord_lon=1.0&toto=N/A" |
| 159 | + ) |
0 commit comments