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/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 9f9dcbed..be1542ed 100644 --- a/src/opengeodeweb_back/routes/blueprint_routes.py +++ b/src/opengeodeweb_back/routes/blueprint_routes.py @@ -256,6 +256,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"] ) @@ -316,11 +317,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 @@ -347,11 +347,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 @@ -366,6 +365,36 @@ 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..fca42a52 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,22 @@ 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 +211,22 @@ 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 +241,43 @@ 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}