|
34 | 34 | fill_disruptions_on_places_nearby,
|
35 | 35 | update_booking_rule_url_in_section,
|
36 | 36 | )
|
37 |
| - |
| 37 | +import pytz |
| 38 | +from jormungandr import app |
| 39 | +from flask import g |
38 | 40 | import pytest
|
39 | 41 | from pytest_mock import mocker
|
40 | 42 |
|
@@ -102,58 +104,59 @@ def update_disruptions_on_pois_for_places_nearby_test(mocker):
|
102 | 104 |
|
103 | 105 |
|
104 | 106 | def journey_with_booking_url_in_booking_rule_test():
|
105 |
| - instance = lambda: None |
106 |
| - # Get a response with a section of ODT having booking_rule. |
107 |
| - booking_url = ( |
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(booking_url=booking_url) |
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 |
| - booking_rule = odt_section.booking_rule |
119 |
| - assert booking_rule.name == "odt_name_value" |
120 |
| - assert ( |
121 |
| - booking_rule.booking_url |
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 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) |
128 |
| - assert ( |
129 |
| - booking_rule.booking_url |
130 |
| - == "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" |
131 |
| - ) |
132 |
| - |
133 |
| - # Use a booking_url with fewer placeholders |
134 |
| - booking_url = ( |
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(booking_url=booking_url) |
139 |
| - odt_section = response_journey_with_odt.journeys[0].sections[1] |
140 |
| - update_booking_rule_url_in_section(odt_section) |
141 |
| - assert ( |
142 |
| - odt_section.booking_rule.booking_url |
143 |
| - == "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" |
144 |
| - ) |
145 |
| - |
146 |
| - # Add a placeholder which is not predefined in the function to update url |
147 |
| - # This placeholder will not be replaced(updated) |
148 |
| - booking_url = ( |
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(booking_url=booking_url) |
154 |
| - odt_section = response_journey_with_odt.journeys[0].sections[1] |
155 |
| - update_booking_rule_url_in_section(odt_section) |
156 |
| - assert ( |
157 |
| - odt_section.booking_rule.booking_url |
158 |
| - == "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" |
159 |
| - ) |
| 107 | + with app.app_context(): |
| 108 | + g.timezone = pytz.timezone("Europe/Paris") |
| 109 | + # Get a response with a section of ODT having booking_rule. |
| 110 | + booking_url = ( |
| 111 | + "https://domaine/search?departure-address={from_name}&destination-address={to_name}" |
| 112 | + "&requested-departure-time={departure_datetime}&from_coord_lat={from_coord_lat}" |
| 113 | + "&from_coord_lon={from_coord_lon}&to_coord_lat={to_coord_lat}&to_coord_lon={to_coord_lon}" |
| 114 | + ) |
| 115 | + response_journey_with_odt = helpers_tests.get_odt_journey(booking_url=booking_url) |
| 116 | + assert len(response_journey_with_odt.journeys) == 1 |
| 117 | + journey = response_journey_with_odt.journeys[0] |
| 118 | + assert len(journey.sections) == 3 |
| 119 | + odt_section = journey.sections[1] |
| 120 | + assert odt_section.type == response_pb2.ON_DEMAND_TRANSPORT |
| 121 | + booking_rule = odt_section.booking_rule |
| 122 | + assert booking_rule.name == "odt_name_value" |
| 123 | + assert ( |
| 124 | + booking_rule.booking_url |
| 125 | + == "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}" |
| 126 | + ) |
| 127 | + assert booking_rule.info_url == "odt_url_value" |
| 128 | + assert booking_rule.message == "odt_conditions_value" |
| 129 | + assert booking_rule.phone_number == "odt_phone_value" |
| 130 | + update_booking_rule_url_in_section(odt_section) |
| 131 | + assert ( |
| 132 | + booking_rule.booking_url |
| 133 | + == "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" |
| 134 | + ) |
| 135 | + |
| 136 | + # Use a booking_url with fewer placeholders |
| 137 | + booking_url = ( |
| 138 | + "https://domaine/search?departure-address={from_name}&destination-address={to_name}" |
| 139 | + "&requested-departure-time={departure_datetime}&from_coord_lat={from_coord_lat}&from_coord_lon={from_coord_lon}" |
| 140 | + ) |
| 141 | + response_journey_with_odt = helpers_tests.get_odt_journey(booking_url=booking_url) |
| 142 | + odt_section = response_journey_with_odt.journeys[0].sections[1] |
| 143 | + update_booking_rule_url_in_section(odt_section) |
| 144 | + assert ( |
| 145 | + odt_section.booking_rule.booking_url |
| 146 | + == "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" |
| 147 | + ) |
| 148 | + |
| 149 | + # Add a placeholder which is not predefined in the function to update url |
| 150 | + # This placeholder will not be replaced(updated) |
| 151 | + booking_url = ( |
| 152 | + "https://domaine/search?departure-address={from_name}&destination-address={to_name}" |
| 153 | + "&requested-departure-time={departure_datetime}&from_coord_lat={from_coord_lat}" |
| 154 | + "&from_coord_lon={from_coord_lon}&toto={toto}" |
| 155 | + ) |
| 156 | + response_journey_with_odt = helpers_tests.get_odt_journey(booking_url=booking_url) |
| 157 | + odt_section = response_journey_with_odt.journeys[0].sections[1] |
| 158 | + update_booking_rule_url_in_section(odt_section) |
| 159 | + assert ( |
| 160 | + odt_section.booking_rule.booking_url |
| 161 | + == "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" |
| 162 | + ) |
0 commit comments