diff --git a/source/jormungandr/jormungandr/olympic_site_params_manager.py b/source/jormungandr/jormungandr/olympic_site_params_manager.py index 0026a5e5e8..a43ec3bdc6 100644 --- a/source/jormungandr/jormungandr/olympic_site_params_manager.py +++ b/source/jormungandr/jormungandr/olympic_site_params_manager.py @@ -100,7 +100,10 @@ def get_dict_scenario(self, poi_uri, key, datetime): return {} @staticmethod - def get_show_natural_opg_journeys(conf_additional_parameters, query_show_natural_opg_journeys): + def get_show_natural_opg_journeys(conf_additional_parameters, api_request): + if api_request.get("wheelchair"): + return True + query_show_natural_opg_journeys = api_request.get("_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 @@ -297,14 +300,17 @@ def get_olympic_site_params(self, pt_origin_detail, pt_destination_detail, api_r for spt_id, attractivity in attractivities.items(): virtual_fallback = virtual_duration.get(spt_id, 0) result[spt_id] = AttractivityVirtualFallback(attractivity, virtual_fallback) + show_natural_opg_journeys = api_request.get("_show_natural_opg_journeys", True) or api_request.get( + "wheelchair" + ) if origin_olympic_site: return { "departure_scenario": result, - "show_natural_opg_journeys": api_request.get("_show_natural_opg_journeys", True), + "show_natural_opg_journeys": show_natural_opg_journeys, } return { "arrival_scenario": result, - "show_natural_opg_journeys": api_request.get("_show_natural_opg_journeys", True), + "show_natural_opg_journeys": show_natural_opg_journeys, } if not self.olympic_site_params: @@ -330,7 +336,7 @@ def get_olympic_site_params(self, pt_origin_detail, pt_destination_detail, api_r "additional_parameters": self.filter_and_get_additional_parameters(conf_additional_parameters), "strict": self.get_strict_parameter(origin_olympic_site.uri) if origin_olympic_site else False, "show_natural_opg_journeys": self.get_show_natural_opg_journeys( - conf_additional_parameters, api_request.get("_show_natural_opg_journeys") + conf_additional_parameters, api_request ), } if arrival_olympic_site_params: @@ -344,7 +350,7 @@ def get_olympic_site_params(self, pt_origin_detail, pt_destination_detail, api_r if destination_olympic_site else False, "show_natural_opg_journeys": self.get_show_natural_opg_journeys( - conf_additional_parameters, api_request.get("_show_natural_opg_journeys") + conf_additional_parameters, api_request ), } return {} diff --git a/source/jormungandr/jormungandr/tests/olympic_site_params_manager_tests.py b/source/jormungandr/jormungandr/tests/olympic_site_params_manager_tests.py index 99abe8d575..34453e5cd7 100644 --- a/source/jormungandr/jormungandr/tests/olympic_site_params_manager_tests.py +++ b/source/jormungandr/jormungandr/tests/olympic_site_params_manager_tests.py @@ -364,6 +364,113 @@ def test_build_with_request_params_and_arrival_criteria(): assert attractivity_virtual_fallback.virtual_duration == 820 +def test_build_with_show_natural_opg_journeys_false(): + instance = FakeInstance(olympics_forbidden_uris=DEFAULT_OLYMPICS_FORBIDDEN_URIS) + osp = FakeOlympicSiteParamsManager(instance, DEFAULT_OLYMPIC_SITE_PARAMS_BUCKET) + osp.fill_olympic_site_params_from_s3() + api_request = dict() + api_request["_olympics_sites_attractivities[]"] = [('stop_point:24113', 3), ('stop_point:24131', 30)] + api_request["_olympics_sites_virtual_fallback[]"] = [('stop_point:24113', 800), ('stop_point:24131', 820)] + api_request["criteria"] = "arrival_stop_attractivity" + api_request["_show_natural_opg_journeys"] = False + + assert api_request["criteria"] == "arrival_stop_attractivity" + assert not api_request.get("max_walking_duration_to_pt") + assert "_keep_olympics_journeys" not in api_request + pt_destination_detail = make_pt_object(type_pb2.POI, 2, 3, "poi:BCD") + property = pt_destination_detail.poi.properties.add() + property.type = DEFAULT_OLYMPICS_FORBIDDEN_URIS["poi_property_key"] + property.value = DEFAULT_OLYMPICS_FORBIDDEN_URIS["poi_property_value"] + pt_origin_detail = make_pt_object(type_pb2.ADDRESS, 1, 2, "SA:BCD") + osp.build(pt_origin_detail, pt_destination_detail, api_request) + assert api_request["_keep_olympics_journeys"] + 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 "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"] + assert attractivity_virtual_fallback.attractivity == 3 + assert attractivity_virtual_fallback.virtual_duration == 800 + + attractivity_virtual_fallback = olympic_site_params["arrival_scenario"]["stop_point:24131"] + assert attractivity_virtual_fallback.attractivity == 30 + assert attractivity_virtual_fallback.virtual_duration == 820 + + +def test_build_with_show_natural_opg_journeys_false_wheelchair_false(): + instance = FakeInstance(olympics_forbidden_uris=DEFAULT_OLYMPICS_FORBIDDEN_URIS) + osp = FakeOlympicSiteParamsManager(instance, DEFAULT_OLYMPIC_SITE_PARAMS_BUCKET) + osp.fill_olympic_site_params_from_s3() + api_request = dict() + api_request["_olympics_sites_attractivities[]"] = [('stop_point:24113', 3), ('stop_point:24131', 30)] + api_request["_olympics_sites_virtual_fallback[]"] = [('stop_point:24113', 800), ('stop_point:24131', 820)] + api_request["criteria"] = "arrival_stop_attractivity" + api_request["_show_natural_opg_journeys"] = False + api_request["wheelchair"] = False + + assert api_request["criteria"] == "arrival_stop_attractivity" + assert not api_request.get("max_walking_duration_to_pt") + assert "_keep_olympics_journeys" not in api_request + pt_destination_detail = make_pt_object(type_pb2.POI, 2, 3, "poi:BCD") + property = pt_destination_detail.poi.properties.add() + property.type = DEFAULT_OLYMPICS_FORBIDDEN_URIS["poi_property_key"] + property.value = DEFAULT_OLYMPICS_FORBIDDEN_URIS["poi_property_value"] + pt_origin_detail = make_pt_object(type_pb2.ADDRESS, 1, 2, "SA:BCD") + osp.build(pt_origin_detail, pt_destination_detail, api_request) + assert api_request["_keep_olympics_journeys"] + 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 "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"] + assert attractivity_virtual_fallback.attractivity == 3 + assert attractivity_virtual_fallback.virtual_duration == 800 + + attractivity_virtual_fallback = olympic_site_params["arrival_scenario"]["stop_point:24131"] + assert attractivity_virtual_fallback.attractivity == 30 + assert attractivity_virtual_fallback.virtual_duration == 820 + + +def test_build_with_show_natural_opg_journeys_false_wheelchair_True(): + instance = FakeInstance(olympics_forbidden_uris=DEFAULT_OLYMPICS_FORBIDDEN_URIS) + osp = FakeOlympicSiteParamsManager(instance, DEFAULT_OLYMPIC_SITE_PARAMS_BUCKET) + osp.fill_olympic_site_params_from_s3() + api_request = dict() + api_request["_olympics_sites_attractivities[]"] = [('stop_point:24113', 3), ('stop_point:24131', 30)] + api_request["_olympics_sites_virtual_fallback[]"] = [('stop_point:24113', 800), ('stop_point:24131', 820)] + api_request["criteria"] = "arrival_stop_attractivity" + api_request["_show_natural_opg_journeys"] = False + api_request["wheelchair"] = True + + assert api_request["criteria"] == "arrival_stop_attractivity" + assert not api_request.get("max_walking_duration_to_pt") + assert "_keep_olympics_journeys" not in api_request + pt_destination_detail = make_pt_object(type_pb2.POI, 2, 3, "poi:BCD") + property = pt_destination_detail.poi.properties.add() + property.type = DEFAULT_OLYMPICS_FORBIDDEN_URIS["poi_property_key"] + property.value = DEFAULT_OLYMPICS_FORBIDDEN_URIS["poi_property_value"] + pt_origin_detail = make_pt_object(type_pb2.ADDRESS, 1, 2, "SA:BCD") + osp.build(pt_origin_detail, pt_destination_detail, api_request) + assert api_request["_keep_olympics_journeys"] + 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 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"] + assert attractivity_virtual_fallback.attractivity == 3 + assert attractivity_virtual_fallback.virtual_duration == 800 + + attractivity_virtual_fallback = olympic_site_params["arrival_scenario"]["stop_point:24131"] + assert attractivity_virtual_fallback.attractivity == 30 + assert attractivity_virtual_fallback.virtual_duration == 820 + + def test_build_without_request_params(): instance = FakeInstance(olympics_forbidden_uris=DEFAULT_OLYMPICS_FORBIDDEN_URIS) osp = FakeOlympicSiteParamsManager(instance, DEFAULT_OLYMPIC_SITE_PARAMS_BUCKET) @@ -651,42 +758,79 @@ def test_manage_forbidden_uris(): 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}, + "test1": { + "conf_additional_parameters": {}, + "api_request": {"_show_natural_opg_journeys": None}, + "result": True, + }, + "test2": { + "conf_additional_parameters": {}, + "api_request": {"_show_natural_opg_journeys": False}, + "result": False, + }, + "test3": { + "conf_additional_parameters": {}, + "api_request": {"_show_natural_opg_journeys": True}, + "result": True, + }, "test4": { "conf_additional_parameters": {"show_natural_opg_journeys": True}, - "query_show_natural_opg_journeys": None, + "api_request": {"_show_natural_opg_journeys": None}, "result": True, }, "test5": { "conf_additional_parameters": {"show_natural_opg_journeys": True}, - "query_show_natural_opg_journeys": True, + "api_request": {"_show_natural_opg_journeys": True}, "result": True, }, "test6": { "conf_additional_parameters": {"show_natural_opg_journeys": True}, - "query_show_natural_opg_journeys": False, + "api_request": {"_show_natural_opg_journeys": False}, "result": False, }, "test7": { "conf_additional_parameters": {"show_natural_opg_journeys": False}, - "query_show_natural_opg_journeys": None, + "api_request": {"_show_natural_opg_journeys": None}, "result": False, }, "test8": { "conf_additional_parameters": {"show_natural_opg_journeys": False}, - "query_show_natural_opg_journeys": False, + "api_request": {"_show_natural_opg_journeys": False}, "result": False, }, "test9": { "conf_additional_parameters": {"show_natural_opg_journeys": False}, - "query_show_natural_opg_journeys": True, + "api_request": {"_show_natural_opg_journeys": True}, + "result": True, + }, + "test10": { + "conf_additional_parameters": {"show_natural_opg_journeys": False}, + "api_request": {"_show_natural_opg_journeys": True, "wheelchair": True}, + "result": True, + }, + "test11": { + "conf_additional_parameters": {"show_natural_opg_journeys": False}, + "api_request": {"_show_natural_opg_journeys": True, "wheelchair": False}, + "result": True, + }, + "test12": { + "conf_additional_parameters": {"show_natural_opg_journeys": False}, + "api_request": {"_show_natural_opg_journeys": False, "wheelchair": True}, + "result": True, + }, + "test13": { + "conf_additional_parameters": {"show_natural_opg_journeys": True}, + "api_request": {"_show_natural_opg_journeys": False, "wheelchair": True}, + "result": True, + }, + "test14": { + "conf_additional_parameters": {"show_natural_opg_journeys": True}, + "api_request": {"_show_natural_opg_journeys": True, "wheelchair": 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"] + value["conf_additional_parameters"], value["api_request"] ) assert result == value["result"], "test {} failed".format(test_name)