From 9a4c34c19317b0618846a585a9b0c5d9342ad1b7 Mon Sep 17 00:00:00 2001 From: Abderrahim AZIME Date: Wed, 11 Oct 2023 18:31:27 +0200 Subject: [PATCH 1/5] Init jop_status api --- .../jormungandr/interfaces/v1/jop_status.py | 46 +++++++++++++++++++ .../modules/v1_routing/v1_routing.py | 4 ++ 2 files changed, 50 insertions(+) create mode 100644 source/jormungandr/jormungandr/interfaces/v1/jop_status.py diff --git a/source/jormungandr/jormungandr/interfaces/v1/jop_status.py b/source/jormungandr/jormungandr/interfaces/v1/jop_status.py new file mode 100644 index 0000000000..f7caeae8cb --- /dev/null +++ b/source/jormungandr/jormungandr/interfaces/v1/jop_status.py @@ -0,0 +1,46 @@ +# Copyright (c) 2001-2022, Hove and/or its affiliates. All rights reserved. +# +# This file is part of Navitia, +# the software to build cool stuff with public transport. +# +# Hope you'll enjoy and contribute to this project, +# powered by Hove (www.hove.com). +# Help us simplify mobility and open public transport: +# a non ending quest to the responsive locomotion way of traveling! +# +# LICENCE: This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# Stay tuned using +# twitter @navitia +# channel `#navitia` on riot https://riot.im/app/#/room/#navitia:matrix.org +# https://groups.google.com/d/forum/navitia +# www.navitia.io + +from __future__ import absolute_import, print_function, unicode_literals, division +from jormungandr import i_manager +from jormungandr.interfaces.v1.StatedResource import StatedResource + + +class JopStatus(StatedResource): + def __init__(self, *args, **kwargs): + super(JopStatus, self).__init__(self, *args, **kwargs) + + def get(self, region): + region_str = i_manager.get_region(region, None, None) + if not region_str: + return {}, 404 + instance = i_manager.instances[region_str] + if not instance: + return {}, 404 + return instance.olympic_site_params_manager.olympic_site_params, 200 diff --git a/source/jormungandr/jormungandr/modules/v1_routing/v1_routing.py b/source/jormungandr/jormungandr/modules/v1_routing/v1_routing.py index 776c4a4fdb..a5c62a48e7 100644 --- a/source/jormungandr/jormungandr/modules/v1_routing/v1_routing.py +++ b/source/jormungandr/jormungandr/modules/v1_routing/v1_routing.py @@ -51,6 +51,7 @@ VehiclePositions, free_floatings, users, + jop_status, ) from werkzeug.routing import BaseConverter, FloatConverter, PathConverter from jormungandr.modules_loader import AModule @@ -310,6 +311,9 @@ def setup(self): ) self.add_resource(Status.Status, region + 'status', coord + 'status', endpoint='status') + + self.add_resource(jop_status.JopStatus, region + 'jop_status', coord + 'jop_status', endpoint='jop_status') + self.add_resource( GeoStatus.GeoStatus, region + '_geo_status', coord + '_geo_status', endpoint='geo_status' ) From 0a3eaa6a8ccd81aaa9c37187ecb6656c8741f49a Mon Sep 17 00:00:00 2001 From: Abderrahim AZIME Date: Wed, 11 Oct 2023 18:43:13 +0200 Subject: [PATCH 2/5] pre-commit --- .../jormungandr/jormungandr/modules/v1_routing/v1_routing.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/jormungandr/jormungandr/modules/v1_routing/v1_routing.py b/source/jormungandr/jormungandr/modules/v1_routing/v1_routing.py index a5c62a48e7..9b4f4a0217 100644 --- a/source/jormungandr/jormungandr/modules/v1_routing/v1_routing.py +++ b/source/jormungandr/jormungandr/modules/v1_routing/v1_routing.py @@ -312,7 +312,9 @@ def setup(self): self.add_resource(Status.Status, region + 'status', coord + 'status', endpoint='status') - self.add_resource(jop_status.JopStatus, region + 'jop_status', coord + 'jop_status', endpoint='jop_status') + self.add_resource( + jop_status.JopStatus, region + 'jop_status', coord + 'jop_status', endpoint='jop_status' + ) self.add_resource( GeoStatus.GeoStatus, region + '_geo_status', coord + '_geo_status', endpoint='geo_status' From 610dc6aceec700cfb35d3a2c3890b982a17653a9 Mon Sep 17 00:00:00 2001 From: Abderrahim AZIME Date: Thu, 12 Oct 2023 15:44:03 +0200 Subject: [PATCH 3/5] tests added --- .../jormungandr/interfaces/v1/jop_status.py | 8 +- source/jormungandr/tests/jop_status_tests.py | 160 ++++++++++++++++++ 2 files changed, 162 insertions(+), 6 deletions(-) create mode 100644 source/jormungandr/tests/jop_status_tests.py diff --git a/source/jormungandr/jormungandr/interfaces/v1/jop_status.py b/source/jormungandr/jormungandr/interfaces/v1/jop_status.py index f7caeae8cb..953ba153e7 100644 --- a/source/jormungandr/jormungandr/interfaces/v1/jop_status.py +++ b/source/jormungandr/jormungandr/interfaces/v1/jop_status.py @@ -36,11 +36,7 @@ class JopStatus(StatedResource): def __init__(self, *args, **kwargs): super(JopStatus, self).__init__(self, *args, **kwargs) - def get(self, region): - region_str = i_manager.get_region(region, None, None) - if not region_str: - return {}, 404 + def get(self, region=None, lon=None, lat=None): + region_str = i_manager.get_region(region, lon, lat) instance = i_manager.instances[region_str] - if not instance: - return {}, 404 return instance.olympic_site_params_manager.olympic_site_params, 200 diff --git a/source/jormungandr/tests/jop_status_tests.py b/source/jormungandr/tests/jop_status_tests.py new file mode 100644 index 0000000000..3cc8ae199b --- /dev/null +++ b/source/jormungandr/tests/jop_status_tests.py @@ -0,0 +1,160 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2001-2022, Hove and/or its affiliates. All rights reserved. +# +# This file is part of Navitia, +# the software to build cool stuff with public transport. +# +# Hope you'll enjoy and contribute to this project, +# powered by Hove (www.hove.com). +# Help us simplify mobility and open public transport: +# a non ending quest to the responsive locomotion way of traveling! +# +# LICENCE: This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# Stay tuned using +# twitter @navitia +# channel `#navitia` on riot https://riot.im/app/#/room/#navitia:matrix.org +# https://groups.google.com/d/forum/navitia +# www.navitia.io + +from __future__ import absolute_import, print_function, unicode_literals, division + +from .tests_mechanism import AbstractTestFixture +from .journey_common_tests import * + + +OLYMPIC_SITES = { + "poi:BCY": { + "name": "Site Olympique JO2024: Arena Bercy (Paris)", + "departure_scenario": "scenario a", + "arrival_scenario": "scenario a", + "strict": True, + "scenarios": { + "scenario a": { + "stop_points" : { + "stop_point:IDFM:463685": { + "name": "Bercy - Arena (Paris)", + "attractivity": 1, + "virtual_fallback": 10 + }, + "stop_point:IDFM:463686": { + "name": "Pont de Tolbiac (Paris)", + "attractivity": 3, + "virtual_fallback": 150 + } + } + }, + "scenario b": { + "stop_points" : { + "stop_point:IDFM:463685": { + "name": "Bercy - Arena (Paris)", + "attractivity": 1, + "virtual_fallback": 10 + }, + "stop_point:IDFM:463686": { + "name": "Pont de Tolbiac (Paris)", + "attractivity": 3, + "virtual_fallback": 150 + } + } + }, + "scenario c": { + "stop_points" : { + "stop_point:IDFM:463685": { + "name": "Bercy - Arena (Paris)", + "attractivity": 1, + "virtual_fallback": 10 + }, + "stop_point:IDFM:463686": { + "name": "Pont de Tolbiac (Paris)", + "attractivity": 3, + "virtual_fallback": 150 + } + }, + "addtionnal_parameters": { + "max_walking_duration_to_pt": 13000 + } + } + } + }, + "poi:BCD": { + "name": "Bercy Arena (Paris)", + "departure_scenario": "default", + "arrival_scenario": "default", + "strict": True, + "scenarios": { + "default": { + "stop_points" : { + "stop_point:IDFM:463685": { + "name": "Bercy - Arena (Paris)", + "attractivity": 1, + "virtual_fallback": 10 + }, + "stop_point:IDFM:463686": { + "name": "Pont de Tolbiac (Paris)", + "attractivity": 3, + "virtual_fallback": 150 + } + }, + "additional_parameters": { + "max_walking_duration_to_pt": 13000 + } + } + } + } +} + + +@dataset({"main_routing_test": {}, "departure_board_test": {}}) +class TestJopStatus(AbstractTestFixture): + def test_with_olympic_sites(self): + instance = i_manager.instances["main_routing_test"] + instance.olympic_site_params_manager.olympic_site_params = OLYMPIC_SITES + response = self.query("/v1/coverage/main_routing_test/jop_status") + assert isinstance(response, dict) + assert len(response) == 2 + assert "poi:BCD" in response + assert "poi:BCY" in response + + def test_coord_valid(self): + instance = i_manager.instances["main_routing_test"] + instance.olympic_site_params_manager.olympic_site_params = OLYMPIC_SITES + response, status_code = self.query_no_assert("/v1/coverage/0.000001;0.000898311281954/jop_status") + assert isinstance(response, dict) + assert len(response) == 2 + assert "poi:BCD" in response + assert "poi:BCY" in response + + def test_without_olympic_sites(self): + response, status_code = self.query_no_assert("/v1/coverage/departure_board_test/jop_status") + assert isinstance(response, dict) + assert status_code == 200 + assert len(response) == 0 + + def test_instance_invalid(self): + response, status_code = self.query_no_assert("/v1/coverage/aa/jop_status") + assert isinstance(response, dict) + assert status_code == 404 + assert "error" in response + assert response["error"]["message"] == "The region aa doesn't exists" + + def test_coord_invalid(self): + instance = i_manager.instances["main_routing_test"] + instance.olympic_site_params_manager.olympic_site_params = OLYMPIC_SITES + response, status_code = self.query_no_assert("/v1/coverage/10.0;10/jop_status") + assert isinstance(response, dict) + assert status_code == 404 + assert "error" in response + assert response["error"]["message"] == "No region available for the coordinates:10.0, 10.0" From 97d2df757b17923e6afb418d40a72966cf6c049c Mon Sep 17 00:00:00 2001 From: Abderrahim AZIME Date: Thu, 12 Oct 2023 15:47:35 +0200 Subject: [PATCH 4/5] pre-commit --- source/jormungandr/tests/jop_status_tests.py | 148 +++++++++---------- 1 file changed, 72 insertions(+), 76 deletions(-) diff --git a/source/jormungandr/tests/jop_status_tests.py b/source/jormungandr/tests/jop_status_tests.py index 3cc8ae199b..e2a6ea7034 100644 --- a/source/jormungandr/tests/jop_status_tests.py +++ b/source/jormungandr/tests/jop_status_tests.py @@ -36,84 +36,80 @@ OLYMPIC_SITES = { - "poi:BCY": { - "name": "Site Olympique JO2024: Arena Bercy (Paris)", - "departure_scenario": "scenario a", - "arrival_scenario": "scenario a", - "strict": True, - "scenarios": { - "scenario a": { - "stop_points" : { - "stop_point:IDFM:463685": { - "name": "Bercy - Arena (Paris)", - "attractivity": 1, - "virtual_fallback": 10 - }, - "stop_point:IDFM:463686": { - "name": "Pont de Tolbiac (Paris)", - "attractivity": 3, - "virtual_fallback": 150 - } - } - }, - "scenario b": { - "stop_points" : { - "stop_point:IDFM:463685": { - "name": "Bercy - Arena (Paris)", - "attractivity": 1, - "virtual_fallback": 10 - }, - "stop_point:IDFM:463686": { - "name": "Pont de Tolbiac (Paris)", - "attractivity": 3, - "virtual_fallback": 150 - } - } - }, - "scenario c": { - "stop_points" : { - "stop_point:IDFM:463685": { - "name": "Bercy - Arena (Paris)", - "attractivity": 1, - "virtual_fallback": 10 - }, - "stop_point:IDFM:463686": { - "name": "Pont de Tolbiac (Paris)", - "attractivity": 3, - "virtual_fallback": 150 - } + "poi:BCY": { + "name": "Site Olympique JO2024: Arena Bercy (Paris)", + "departure_scenario": "scenario a", + "arrival_scenario": "scenario a", + "strict": True, + "scenarios": { + "scenario a": { + "stop_points": { + "stop_point:IDFM:463685": { + "name": "Bercy - Arena (Paris)", + "attractivity": 1, + "virtual_fallback": 10, + }, + "stop_point:IDFM:463686": { + "name": "Pont de Tolbiac (Paris)", + "attractivity": 3, + "virtual_fallback": 150, + }, + } + }, + "scenario b": { + "stop_points": { + "stop_point:IDFM:463685": { + "name": "Bercy - Arena (Paris)", + "attractivity": 1, + "virtual_fallback": 10, + }, + "stop_point:IDFM:463686": { + "name": "Pont de Tolbiac (Paris)", + "attractivity": 3, + "virtual_fallback": 150, + }, + } + }, + "scenario c": { + "stop_points": { + "stop_point:IDFM:463685": { + "name": "Bercy - Arena (Paris)", + "attractivity": 1, + "virtual_fallback": 10, + }, + "stop_point:IDFM:463686": { + "name": "Pont de Tolbiac (Paris)", + "attractivity": 3, + "virtual_fallback": 150, + }, + }, + "addtionnal_parameters": {"max_walking_duration_to_pt": 13000}, + }, }, - "addtionnal_parameters": { - "max_walking_duration_to_pt": 13000 - } - } - } - }, - "poi:BCD": { - "name": "Bercy Arena (Paris)", - "departure_scenario": "default", - "arrival_scenario": "default", - "strict": True, - "scenarios": { - "default": { - "stop_points" : { - "stop_point:IDFM:463685": { - "name": "Bercy - Arena (Paris)", - "attractivity": 1, - "virtual_fallback": 10 - }, - "stop_point:IDFM:463686": { - "name": "Pont de Tolbiac (Paris)", - "attractivity": 3, - "virtual_fallback": 150 - } + }, + "poi:BCD": { + "name": "Bercy Arena (Paris)", + "departure_scenario": "default", + "arrival_scenario": "default", + "strict": True, + "scenarios": { + "default": { + "stop_points": { + "stop_point:IDFM:463685": { + "name": "Bercy - Arena (Paris)", + "attractivity": 1, + "virtual_fallback": 10, + }, + "stop_point:IDFM:463686": { + "name": "Pont de Tolbiac (Paris)", + "attractivity": 3, + "virtual_fallback": 150, + }, + }, + "additional_parameters": {"max_walking_duration_to_pt": 13000}, + } }, - "additional_parameters": { - "max_walking_duration_to_pt": 13000 - } - } - } - } + }, } From 855138f91b67439340543bab27d3a091dd710a36 Mon Sep 17 00:00:00 2001 From: Abderrahim AZIME Date: Fri, 13 Oct 2023 11:19:23 +0200 Subject: [PATCH 5/5] jop_status >> opg_status --- .../interfaces/v1/{jop_status.py => opg_status.py} | 4 ++-- .../jormungandr/modules/v1_routing/v1_routing.py | 4 ++-- .../{jop_status_tests.py => opg_status_tests.py} | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) rename source/jormungandr/jormungandr/interfaces/v1/{jop_status.py => opg_status.py} (94%) rename source/jormungandr/tests/{jop_status_tests.py => opg_status_tests.py} (96%) diff --git a/source/jormungandr/jormungandr/interfaces/v1/jop_status.py b/source/jormungandr/jormungandr/interfaces/v1/opg_status.py similarity index 94% rename from source/jormungandr/jormungandr/interfaces/v1/jop_status.py rename to source/jormungandr/jormungandr/interfaces/v1/opg_status.py index 953ba153e7..dca47239d3 100644 --- a/source/jormungandr/jormungandr/interfaces/v1/jop_status.py +++ b/source/jormungandr/jormungandr/interfaces/v1/opg_status.py @@ -32,9 +32,9 @@ from jormungandr.interfaces.v1.StatedResource import StatedResource -class JopStatus(StatedResource): +class OpgStatus(StatedResource): def __init__(self, *args, **kwargs): - super(JopStatus, self).__init__(self, *args, **kwargs) + super(OpgStatus, self).__init__(self, *args, **kwargs) def get(self, region=None, lon=None, lat=None): region_str = i_manager.get_region(region, lon, lat) diff --git a/source/jormungandr/jormungandr/modules/v1_routing/v1_routing.py b/source/jormungandr/jormungandr/modules/v1_routing/v1_routing.py index 9b4f4a0217..060fd83b78 100644 --- a/source/jormungandr/jormungandr/modules/v1_routing/v1_routing.py +++ b/source/jormungandr/jormungandr/modules/v1_routing/v1_routing.py @@ -51,7 +51,7 @@ VehiclePositions, free_floatings, users, - jop_status, + opg_status, ) from werkzeug.routing import BaseConverter, FloatConverter, PathConverter from jormungandr.modules_loader import AModule @@ -313,7 +313,7 @@ def setup(self): self.add_resource(Status.Status, region + 'status', coord + 'status', endpoint='status') self.add_resource( - jop_status.JopStatus, region + 'jop_status', coord + 'jop_status', endpoint='jop_status' + opg_status.OpgStatus, region + 'opg_status', coord + 'opg_status', endpoint='opg_status' ) self.add_resource( diff --git a/source/jormungandr/tests/jop_status_tests.py b/source/jormungandr/tests/opg_status_tests.py similarity index 96% rename from source/jormungandr/tests/jop_status_tests.py rename to source/jormungandr/tests/opg_status_tests.py index e2a6ea7034..829268ad32 100644 --- a/source/jormungandr/tests/jop_status_tests.py +++ b/source/jormungandr/tests/opg_status_tests.py @@ -114,11 +114,11 @@ @dataset({"main_routing_test": {}, "departure_board_test": {}}) -class TestJopStatus(AbstractTestFixture): +class TestOpgStatus(AbstractTestFixture): def test_with_olympic_sites(self): instance = i_manager.instances["main_routing_test"] instance.olympic_site_params_manager.olympic_site_params = OLYMPIC_SITES - response = self.query("/v1/coverage/main_routing_test/jop_status") + response = self.query("/v1/coverage/main_routing_test/opg_status") assert isinstance(response, dict) assert len(response) == 2 assert "poi:BCD" in response @@ -127,20 +127,20 @@ def test_with_olympic_sites(self): def test_coord_valid(self): instance = i_manager.instances["main_routing_test"] instance.olympic_site_params_manager.olympic_site_params = OLYMPIC_SITES - response, status_code = self.query_no_assert("/v1/coverage/0.000001;0.000898311281954/jop_status") + response, status_code = self.query_no_assert("/v1/coverage/0.000001;0.000898311281954/opg_status") assert isinstance(response, dict) assert len(response) == 2 assert "poi:BCD" in response assert "poi:BCY" in response def test_without_olympic_sites(self): - response, status_code = self.query_no_assert("/v1/coverage/departure_board_test/jop_status") + response, status_code = self.query_no_assert("/v1/coverage/departure_board_test/opg_status") assert isinstance(response, dict) assert status_code == 200 assert len(response) == 0 def test_instance_invalid(self): - response, status_code = self.query_no_assert("/v1/coverage/aa/jop_status") + response, status_code = self.query_no_assert("/v1/coverage/aa/opg_status") assert isinstance(response, dict) assert status_code == 404 assert "error" in response @@ -149,7 +149,7 @@ def test_instance_invalid(self): def test_coord_invalid(self): instance = i_manager.instances["main_routing_test"] instance.olympic_site_params_manager.olympic_site_params = OLYMPIC_SITES - response, status_code = self.query_no_assert("/v1/coverage/10.0;10/jop_status") + response, status_code = self.query_no_assert("/v1/coverage/10.0;10/opg_status") assert isinstance(response, dict) assert status_code == 404 assert "error" in response