From fb433b8f6f804f0022f13c9e720733d4daca4722 Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Thu, 13 Feb 2025 11:00:15 +0100 Subject: [PATCH 1/3] feat(polyhedron attributes): new route and tests --- .gitignore | 2 + .../routes/blueprint_routes.py | 42 ++++++++++++--- .../schemas/polyhedron_attribute_names.json | 15 ++++++ tests/polyhedron_attribute.vtu | 22 ++++++++ tests/test_routes.py | 53 ++++++++++++++++++- 5 files changed, 125 insertions(+), 9 deletions(-) create mode 100644 src/opengeodeweb_back/routes/schemas/polyhedron_attribute_names.json create mode 100644 tests/polyhedron_attribute.vtu diff --git a/.gitignore b/.gitignore index 96807427..1a771f5b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ .pytest_cache /data +/build +*.egg-info dist venv output diff --git a/src/opengeodeweb_back/routes/blueprint_routes.py b/src/opengeodeweb_back/routes/blueprint_routes.py index f8c49a92..57aa765a 100644 --- a/src/opengeodeweb_back/routes/blueprint_routes.py +++ b/src/opengeodeweb_back/routes/blueprint_routes.py @@ -260,6 +260,7 @@ def save_viewable_file(): DATA_FOLDER_PATH, generated_id + "." + native_extension, ) + os.remove(os.path.join(UPLOAD_FOLDER, secure_filename)) object_type = geode_functions.get_object_type( flask.request.json["input_geode_object"] ) @@ -320,11 +321,10 @@ def create_point(): methods=vertex_attribute_names_json["methods"], ) def vertex_attribute_names(): - - UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"] + DATA_FOLDER_PATH = flask.current_app.config["DATA_FOLDER_PATH"] utils_functions.validate_request(flask.request, vertex_attribute_names_json) file_absolute_path = os.path.join( - UPLOAD_FOLDER, werkzeug.utils.secure_filename(flask.request.json["filename"]) + DATA_FOLDER_PATH, werkzeug.utils.secure_filename(flask.request.json["filename"]) ) data = geode_functions.load( flask.request.json["input_geode_object"], file_absolute_path @@ -351,11 +351,10 @@ def vertex_attribute_names(): methods=polygon_attribute_names_json["methods"], ) def polygon_attribute_names(): - - UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"] - utils_functions.validate_request(flask.request, vertex_attribute_names_json) + DATA_FOLDER_PATH = flask.current_app.config["DATA_FOLDER_PATH"] + utils_functions.validate_request(flask.request, polygon_attribute_names_json) file_absolute_path = os.path.join( - UPLOAD_FOLDER, werkzeug.utils.secure_filename(flask.request.json["filename"]) + DATA_FOLDER_PATH, werkzeug.utils.secure_filename(flask.request.json["filename"]) ) data = geode_functions.load( flask.request.json["input_geode_object"], file_absolute_path @@ -370,6 +369,35 @@ def polygon_attribute_names(): ) +with open( + os.path.join(schemas, "polyhedron_attribute_names.json"), + "r", +) as file: + polyhedron_attribute_names_json = json.load(file) + +@routes.route( + polyhedron_attribute_names_json["route"], + methods=polyhedron_attribute_names_json["methods"], +) +def polyhedron_attribute_names(): + DATA_FOLDER_PATH = flask.current_app.config["DATA_FOLDER_PATH"] + utils_functions.validate_request(flask.request, vertex_attribute_names_json) + file_absolute_path = os.path.join( + DATA_FOLDER_PATH, werkzeug.utils.secure_filename(flask.request.json["filename"]) + ) + data = geode_functions.load( + flask.request.json["input_geode_object"], file_absolute_path + ) + polyhedron_attribute_names = data.polyhedron_attribute_manager().attribute_names() + + return flask.make_response( + { + "polyhedron_attribute_names": polyhedron_attribute_names, + }, + 200, + ) + + with open( os.path.join(schemas, "ping.json"), "r", diff --git a/src/opengeodeweb_back/routes/schemas/polyhedron_attribute_names.json b/src/opengeodeweb_back/routes/schemas/polyhedron_attribute_names.json new file mode 100644 index 00000000..b10c7681 --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/polyhedron_attribute_names.json @@ -0,0 +1,15 @@ +{ + "route": "/polyhedron_attribute_names", + "methods": ["POST"], + "type": "object", + "properties": { + "input_geode_object": { + "type": "string" + }, + "filename": { + "type": "string" + } + }, + "required": ["input_geode_object", "filename"], + "additionalProperties": false +} diff --git a/tests/polyhedron_attribute.vtu b/tests/polyhedron_attribute.vtu new file mode 100644 index 00000000..7c86fa9c --- /dev/null +++ b/tests/polyhedron_attribute.vtu @@ -0,0 +1,22 @@ + + + + + + 1 2 3 4 5 6 7 8 9 10 11 + 0 0 0 1 0 0 2 1 0 1 2 0 0 2 0 0 0 1 1 0 1 2 1 1 1 2 1 0 2 1 1 1 2 + + + 0 0 0 1 0 0 2 1 0 1 2 0 0 2 0 0 0 1 1 0 1 2 1 1 1 2 1 0 2 1 1 1 2 + + + 3 4 5 6 + + + 0 1 3 4 5 6 8 9 1 2 3 6 7 8 5 6 8 9 10 6 7 8 10 + 8 14 19 23 + 12 13 14 10 + + + + diff --git a/tests/test_routes.py b/tests/test_routes.py index f1878636..30984939 100644 --- a/tests/test_routes.py +++ b/tests/test_routes.py @@ -4,6 +4,7 @@ # Third party imports from werkzeug.datastructures import FileStorage +from flask import app # Local application imports from src.opengeodeweb_back import test_utils @@ -174,12 +175,19 @@ def test_vertex_attribute_names(client): ) assert response.status_code == 201 + response = client.post("/save_viewable_file", json={ + "input_geode_object": "PolygonalSurface3D", + "filename": "vertex_attribute.vtp", + }) + assert response.status_code == 200 + native_file_name = response.json["native_file_name"] + route = f"/vertex_attribute_names" def get_full_data(): return { "input_geode_object": "PolygonalSurface3D", - "filename": "vertex_attribute.vtp", + "filename": native_file_name, } # Normal test with filename 'vertex_attribute.vtp' @@ -200,12 +208,19 @@ def test_polygon_attribute_names(client): ) assert response.status_code == 201 + response = client.post("/save_viewable_file", json={ + "input_geode_object": "PolygonalSurface3D", + "filename": "polygon_attribute.vtp", + }) + assert response.status_code == 200 + native_file_name = response.json["native_file_name"] + route = f"/polygon_attribute_names" def get_full_data(): return { "input_geode_object": "PolygonalSurface3D", - "filename": "polygon_attribute.vtp", + "filename": native_file_name, } # Normal test with filename 'vertex_attribute.vtp' @@ -220,6 +235,40 @@ def get_full_data(): test_utils.test_route_wrong_params(client, route, get_full_data) +def test_polyhedron_attribute_names(client): + response = client.put( + f"/upload_file", + data={"file": FileStorage(open("./tests/polyhedron_attribute.vtu", "rb"))}, + ) + assert response.status_code == 201 + + response = client.post("/save_viewable_file", json={ + "input_geode_object": "HybridSolid3D", + "filename": "polyhedron_attribute.vtu", + }) + assert response.status_code == 200 + native_file_name = response.json["native_file_name"] + + route = f"/polyhedron_attribute_names" + + def get_full_data(): + return { + "input_geode_object": "HybridSolid3D", + "filename": native_file_name, + } + + # Normal test with filename 'vertex_attribute.vtp' + response = client.post(route, json=get_full_data()) + assert response.status_code == 200 + polygon_attribute_names = response.json["polyhedron_attribute_names"] + assert type(polygon_attribute_names) is list + for polygon_attribute_name in polygon_attribute_names: + assert type(polygon_attribute_name) is str + + # Test all params + test_utils.test_route_wrong_params(client, route, get_full_data) + + def test_create_point(client): route = f"/create_point" get_full_data = lambda: {"x": 1, "y": 2, "z": 3} From cba9c66073f6410e145c4cd122742c1b2a3c2441 Mon Sep 17 00:00:00 2001 From: JulienChampagnol <91873154+JulienChampagnol@users.noreply.github.com> Date: Thu, 13 Feb 2025 10:09:19 +0000 Subject: [PATCH 2/3] Apply prepare changes --- app.py | 2 +- .../routes/blueprint_routes.py | 1 + tests/test_routes.py | 33 ++++++++++++------- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/app.py b/app.py index 856ab539..a1ee32e7 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,4 @@ -""" Packages """ +"""Packages""" import os diff --git a/src/opengeodeweb_back/routes/blueprint_routes.py b/src/opengeodeweb_back/routes/blueprint_routes.py index 3636e479..be1542ed 100644 --- a/src/opengeodeweb_back/routes/blueprint_routes.py +++ b/src/opengeodeweb_back/routes/blueprint_routes.py @@ -371,6 +371,7 @@ def polygon_attribute_names(): ) as file: polyhedron_attribute_names_json = json.load(file) + @routes.route( polyhedron_attribute_names_json["route"], methods=polyhedron_attribute_names_json["methods"], diff --git a/tests/test_routes.py b/tests/test_routes.py index 30984939..fca42a52 100644 --- a/tests/test_routes.py +++ b/tests/test_routes.py @@ -175,10 +175,13 @@ def test_vertex_attribute_names(client): ) assert response.status_code == 201 - response = client.post("/save_viewable_file", json={ - "input_geode_object": "PolygonalSurface3D", - "filename": "vertex_attribute.vtp", - }) + response = client.post( + "/save_viewable_file", + json={ + "input_geode_object": "PolygonalSurface3D", + "filename": "vertex_attribute.vtp", + }, + ) assert response.status_code == 200 native_file_name = response.json["native_file_name"] @@ -208,10 +211,13 @@ def test_polygon_attribute_names(client): ) assert response.status_code == 201 - response = client.post("/save_viewable_file", json={ - "input_geode_object": "PolygonalSurface3D", - "filename": "polygon_attribute.vtp", - }) + response = client.post( + "/save_viewable_file", + json={ + "input_geode_object": "PolygonalSurface3D", + "filename": "polygon_attribute.vtp", + }, + ) assert response.status_code == 200 native_file_name = response.json["native_file_name"] @@ -242,10 +248,13 @@ def test_polyhedron_attribute_names(client): ) assert response.status_code == 201 - response = client.post("/save_viewable_file", json={ - "input_geode_object": "HybridSolid3D", - "filename": "polyhedron_attribute.vtu", - }) + response = client.post( + "/save_viewable_file", + json={ + "input_geode_object": "HybridSolid3D", + "filename": "polyhedron_attribute.vtu", + }, + ) assert response.status_code == 200 native_file_name = response.json["native_file_name"] From 761872a076ca8e1e0bf81f3189153d325cf6ebf1 Mon Sep 17 00:00:00 2001 From: semantic-release Date: Thu, 13 Feb 2025 14:46:12 +0000 Subject: [PATCH 3/3] 5.5.0-rc.1 Automatically generated by python-semantic-release --- CHANGELOG.md | 14 +++++++++++--- pyproject.toml | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71820a1c..5cd3a35e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # CHANGELOG +## v5.5.0-rc.1 (2025-02-13) + + ## v5.4.3 (2025-01-26) @@ -11,6 +14,11 @@ - **deps**: Trigger semantic ([`ac4ddd7`](https://github.com/Geode-solutions/OpenGeodeWeb-Back/commit/ac4ddd70936ec159945b4b6864d97c664ce8b1b7)) +### Features + +- **polyhedron attributes**: New route and tests + ([`fb433b8`](https://github.com/Geode-solutions/OpenGeodeWeb-Back/commit/fb433b8f6f804f0022f13c9e720733d4daca4722)) + ## v5.4.2 (2025-01-22) @@ -159,7 +167,7 @@ BREAKING CHANGE: functions moved to utils_functions.py -### BREAKING CHANGES +### Breaking Changes - **ping route**: Functions moved to utils_functions.py @@ -675,7 +683,7 @@ BREAKING CHANGE: geode_objects_output_extensions returns a dict BREAKING CHANGE: geode_objects_output_extensions takes data as input -### BREAKING CHANGES +### Breaking Changes - **dependencies**: Geode_objects_output_extensions takes data as input @@ -718,7 +726,7 @@ BREAMING CHANGE: geode_objects_output_extensions needs data input BREAKING CHANGE: Arguments changement(array to json schema) -### BREAKING CHANGES +### Breaking Changes - **validate_request**: Arguments changement(array to json schema) diff --git a/pyproject.toml b/pyproject.toml index 3e90f1ed..55ed11e0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta" [project] name = "OpenGeodeWeb-Back" -version = "5.4.3" +version = "5.5.0-rc.1" dynamic = ["dependencies"] authors = [ { name="Geode-solutions", email="team-web@geode-solutions.com" },