From c30308eb928ac3d98aabe50e8d4ba806872a090a Mon Sep 17 00:00:00 2001 From: Renato Ambrosone Date: Fri, 11 Apr 2025 13:56:11 +0200 Subject: [PATCH] FIX: api version is now consistent with release Change-Id: I25582e7937ec912666e2ba48d5687ec3ae694883 --- gnpyapi/core/__init__.py | 5 ++++- gnpyapi/core/route/path_request_route.py | 9 +++------ gnpyapi/core/route/status_route.py | 5 +++-- tests/test_api.py | 8 +++++++- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/gnpyapi/core/__init__.py b/gnpyapi/core/__init__.py index ed51ab5..84d037f 100644 --- a/gnpyapi/core/__init__.py +++ b/gnpyapi/core/__init__.py @@ -4,6 +4,9 @@ """ from flask import Flask +API_VERSION = "/api/v0.1" + app = Flask(__name__) -import gnpyapi.core.route.path_request_route # noqa: F401, E402 +import gnpyapi.core.route.path_request_route # noqa: E402 +import gnpyapi.core.route.status_route # noqa: F401, E402 diff --git a/gnpyapi/core/route/path_request_route.py b/gnpyapi/core/route/path_request_route.py index a776189..fe73a68 100644 --- a/gnpyapi/core/route/path_request_route.py +++ b/gnpyapi/core/route/path_request_route.py @@ -1,5 +1,4 @@ # coding: utf-8 -from pathlib import Path from flask import request @@ -7,14 +6,12 @@ from gnpyapi.core import app from gnpyapi.core.exception.equipment_error import EquipmentError from gnpyapi.core.exception.topology_error import TopologyError from gnpyapi.core.service.path_request_service import PathRequestService +from gnpyapi.core import API_VERSION -PATH_COMPUTATION_BASE_PATH = '/api/v1/path-computation' -PATH_REQUEST_BASE_PATH = '/api/v1/path-request' -AUTODESIGN_PATH = PATH_COMPUTATION_BASE_PATH + '//autodesign' - -_examples_dir = Path(__file__).parent.parent.parent / 'example-data' +PATH_REQUEST_BASE_PATH = '/path-request' +@app.route(API_VERSION + PATH_REQUEST_BASE_PATH, methods=['POST']) @app.route(PATH_REQUEST_BASE_PATH, methods=['POST']) def path_request(path_request_service: PathRequestService): data = request.json diff --git a/gnpyapi/core/route/status_route.py b/gnpyapi/core/route/status_route.py index 8fd3ebd..64331c5 100644 --- a/gnpyapi/core/route/status_route.py +++ b/gnpyapi/core/route/status_route.py @@ -1,7 +1,8 @@ # coding: utf-8 from gnpyapi.core import app +from gnpyapi.core import API_VERSION -@app.route('/api/v1/status', methods=['GET']) +@app.route(API_VERSION + '/status', methods=['GET']) def api_status(): - return {"version": "v1", "status": "ok"}, 200 + return {"version": "v0.1", "status": "ok"}, 200 diff --git a/tests/test_api.py b/tests/test_api.py index d88844c..8c7d5bf 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -17,7 +17,7 @@ TEST_DATA_DIR = Path(__file__).parent / 'data' TEST_REQ_DIR = TEST_DATA_DIR / 'req' TEST_RES_DIR = TEST_DATA_DIR / 'res' -API_VERSION = '/api/v1' +API_VERSION = '/api/v0.1' def read_json_file(path): @@ -40,3 +40,9 @@ def test_echo(client): response = client.post(f"{API_VERSION}/path-request", json=input_data) assert response.status_code == 201 assert response.get_json() == expected_response + + +def test_status(client): + response = client.get(f"{API_VERSION}/status") + assert response.status_code == 200 + assert response.get_json() == {"version": "v0.1", "status": "ok"}