Skip to content

Commit

Permalink
Merge pull request #4227 from hove-io/show_natural_opg_journeys_defau…
Browse files Browse the repository at this point in the history
…lt_value

show_natural_opg_journeys default value = True
  • Loading branch information
azime authored Feb 29, 2024
2 parents 9501ef8 + 85b29f3 commit 95f6acb
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 19 deletions.
13 changes: 7 additions & 6 deletions source/jormungandr/jormungandr/olympic_site_params_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ def get_dict_scenario(self, poi_uri, key, datetime):
return self.build_olympic_site_params(scenario_name, data)
return {}

def get_show_natural_opg_journeys(self, conf_additional_parameters, query_show_natural_opg_journeys):
return query_show_natural_opg_journeys or conf_additional_parameters.get(
"show_natural_opg_journeys", False
)
@staticmethod
def get_show_natural_opg_journeys(conf_additional_parameters, query_show_natural_opg_journeys):
if query_show_natural_opg_journeys is None:
return conf_additional_parameters.get("show_natural_opg_journeys", True)
return query_show_natural_opg_journeys

def filter_and_get_additional_parameters(self, conf_additional_parameters):
return {
Expand Down Expand Up @@ -299,11 +300,11 @@ def get_olympic_site_params(self, pt_origin_detail, pt_destination_detail, api_r
if origin_olympic_site:
return {
"departure_scenario": result,
"show_natural_opg_journeys": api_request.get("_show_natural_opg_journeys", False),
"show_natural_opg_journeys": api_request.get("_show_natural_opg_journeys", True),
}
return {
"arrival_scenario": result,
"show_natural_opg_journeys": api_request.get("_show_natural_opg_journeys", False),
"show_natural_opg_journeys": api_request.get("_show_natural_opg_journeys", True),
}

if not self.olympic_site_params:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def test_build_with_request_params_and_without_criteria_without_keep_olympics_jo
assert api_request["_keep_olympics_journeys"]
assert not api_request.get("max_walking_duration_to_pt")
olympic_site_params = api_request["olympic_site_params"]
assert not olympic_site_params['show_natural_opg_journeys']
assert olympic_site_params['show_natural_opg_journeys']
assert "arrival_scenario" in olympic_site_params
assert "departure_scenario" not in olympic_site_params
attractivity_virtual_fallback = olympic_site_params["arrival_scenario"]["stop_point:24113"]
Expand Down Expand Up @@ -318,7 +318,7 @@ def test_build_with_request_params_and_departure_criteria():
assert api_request["criteria"] == "departure_stop_attractivity"
assert not api_request.get("max_walking_duration_to_pt")
olympic_site_params = api_request["olympic_site_params"]
assert not olympic_site_params['show_natural_opg_journeys']
assert olympic_site_params['show_natural_opg_journeys']
assert "arrival_scenario" not in olympic_site_params
assert "departure_scenario" in olympic_site_params
attractivity_virtual_fallback = olympic_site_params["departure_scenario"]["stop_point:24113"]
Expand Down Expand Up @@ -352,7 +352,7 @@ def test_build_with_request_params_and_arrival_criteria():
assert api_request["criteria"] == "arrival_stop_attractivity"
assert not api_request.get("max_walking_duration_to_pt")
olympic_site_params = api_request["olympic_site_params"]
assert not olympic_site_params['show_natural_opg_journeys']
assert olympic_site_params['show_natural_opg_journeys']
assert "arrival_scenario" in olympic_site_params
assert "departure_scenario" not in olympic_site_params
attractivity_virtual_fallback = olympic_site_params["arrival_scenario"]["stop_point:24113"]
Expand Down Expand Up @@ -647,3 +647,46 @@ def test_manage_forbidden_uris():
api_request = {"forbidden_uris[]": ["uri1", "uri2"]}
osp.manage_forbidden_uris(api_request, ["ab"])
assert len(api_request["forbidden_uris[]"]) == 3


def test_get_show_natural_opg_journeys():
data = {
"test1": {"conf_additional_parameters": {}, "query_show_natural_opg_journeys": None, "result": True},
"test2": {"conf_additional_parameters": {}, "query_show_natural_opg_journeys": False, "result": False},
"test3": {"conf_additional_parameters": {}, "query_show_natural_opg_journeys": True, "result": True},
"test4": {
"conf_additional_parameters": {"show_natural_opg_journeys": True},
"query_show_natural_opg_journeys": None,
"result": True,
},
"test5": {
"conf_additional_parameters": {"show_natural_opg_journeys": True},
"query_show_natural_opg_journeys": True,
"result": True,
},
"test6": {
"conf_additional_parameters": {"show_natural_opg_journeys": True},
"query_show_natural_opg_journeys": False,
"result": False,
},
"test7": {
"conf_additional_parameters": {"show_natural_opg_journeys": False},
"query_show_natural_opg_journeys": None,
"result": False,
},
"test8": {
"conf_additional_parameters": {"show_natural_opg_journeys": False},
"query_show_natural_opg_journeys": False,
"result": False,
},
"test9": {
"conf_additional_parameters": {"show_natural_opg_journeys": False},
"query_show_natural_opg_journeys": True,
"result": True,
},
}
for test_name, value in data.items():
result = OlympicSiteParamsManager.get_show_natural_opg_journeys(
value["conf_additional_parameters"], value["query_show_natural_opg_journeys"]
)
assert result == value["result"], "test {} failed".format(test_name)
20 changes: 10 additions & 10 deletions source/jormungandr/tests/olympic_sites_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,9 @@ def test_address_with_within_to_address_journeys(self):
template_journey_query.format(place_from=from_addr_uri, place_to=to_addr_uri)
)
journeys = [journey for journey in response['journeys']]
assert len(journeys) == 1
assert len(journeys) == 2
first_journey = response['journeys'][0]
assert len(first_journey["sections"]) == 1
assert len(first_journey["sections"]) == 3
assert first_journey["sections"][0]["type"] == "street_network"

def test_address_with_invalid_within_to_address_journeys(self):
Expand Down Expand Up @@ -485,9 +485,9 @@ def test_address_to_olympic_poi_journeys(self):
response = self.query_region(
template_journey_query.format(place_from=from_addr_uri, place_to=to_poi_uri)
)
assert len(response['journeys']) == 1
assert len(response['journeys']) == 2
first_journey = response['journeys'][0]
assert len(first_journey["sections"]) == 1
assert len(first_journey["sections"]) == 3
assert first_journey["sections"][0]["type"] == "street_network"

def test_address_to_not_olympic_poi_journeys(self):
Expand Down Expand Up @@ -547,9 +547,9 @@ def test_olympic_poi_to_address_journeys(self):
template_journey_query.format(place_from=from_poi_uri, place_to=to_addr_uri)
)
journeys = [journey for journey in response['journeys']]
assert len(journeys) == 1
assert len(journeys) == 2
first_journey = response['journeys'][0]
assert len(first_journey["sections"]) == 1
assert len(first_journey["sections"]) == 3
assert first_journey["sections"][0]["type"] == "street_network"

def test_olympic_poi_to_olympic_poi_journeys(self):
Expand All @@ -567,9 +567,9 @@ def test_olympic_poi_to_olympic_poi_journeys(self):
template_journey_query.format(place_from=from_poi_uri, place_to=to_poi_uri)
)
journeys = [journey for journey in response['journeys']]
assert len(journeys) == 1
assert len(journeys) == 2
first_journey = response['journeys'][0]
assert len(first_journey["sections"]) == 1
assert len(first_journey["sections"]) == 3
assert first_journey["sections"][0]["type"] == "street_network"

def test_olympic_poi_to_olympic_poi_journeys_show_natural_opg_journeys_in_query(self):
Expand Down Expand Up @@ -644,8 +644,8 @@ def test_olympic_poi_to_olympic_poi_journeys_without_show_natural_opg_journeyss(
query = template_journey_query.format(place_from=from_poi_uri, place_to=to_poi_uri)
response = self.query_region(query)
journeys = [journey for journey in response['journeys']]
assert len(journeys) == 1
assert len(journeys) == 2
first_journey = response['journeys'][0]
assert len(first_journey["sections"]) == 1
assert len(first_journey["sections"]) == 3
assert "to_delete" not in first_journey["tags"]
assert first_journey["sections"][0]["mode"] == "walking"

0 comments on commit 95f6acb

Please sign in to comment.