From fdd569789597e5aed6ee3de82863f35c5364fbac Mon Sep 17 00:00:00 2001 From: Julien Champagnol <91873154+JulienChampagnol@users.noreply.github.com> Date: Thu, 16 Nov 2023 13:58:33 +0100 Subject: [PATCH 01/17] Next (#208) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Arnaud Botella Co-authored-by: Julien Champagnol <91873154+JulienChampagnol@users.noreply.github.com> Co-authored-by: JulienChampagnol Co-authored-by: SpliiT Co-authored-by: Clémentine <93268012+Clemamolette@users.noreply.github.com> Co-authored-by: Tao Schiro <106495600+SpliiT@users.noreply.github.com> Co-authored-by: JulienChampagnol --- app.py | 1 - blueprints/blueprint_tools.py | 114 ++++++- blueprints/blueprint_workflows.py | 3 + blueprints/tools/blueprint_crs_converter.py | 85 +---- blueprints/tools/blueprint_file_converter.py | 66 +--- .../tools/blueprint_validity_checker.py | 56 +-- .../tools/crs_converter_allowed_files.json | 9 - .../tools/crs_converter_allowed_objects.json | 17 - .../tools/crs_converter_convert_file.json | 102 +++--- ...nverter_geographic_coordinate_systems.json | 28 +- .../crs_converter_output_file_extensions.json | 17 - blueprints/tools/crs_converter_versions.json | 14 +- .../tools/file_converter_allowed_files.json | 8 - .../tools/file_converter_allowed_objects.json | 17 - .../tools/file_converter_convert_file.json | 54 +-- ...file_converter_output_file_extensions.json | 17 - .../tools/validity_checker_allowed_files.json | 9 - .../validity_checker_allowed_objects.json | 17 - .../tools/validity_checker_inspect_file.json | 40 +-- .../tools/validity_checker_test_names.json | 28 +- blueprints/tools_allowed_files.json | 13 + blueprints/tools_allowed_objects.json | 16 + ...s_geode_objects_and_output_extensions.json | 13 + blueprints/tools_missing_files.json | 16 + blueprints/workflows/blueprint_explicit.py | 20 +- blueprints/workflows/blueprint_implicit.py | 34 +- blueprints/workflows/blueprint_simplex.py | 12 +- ..._value.json => implicit_update_value.json} | 0 requirements.txt | 2 +- tests/test_crs_converter.py | 323 ++---------------- tests/test_file_converter.py | 140 ++------ tests/test_implicit.py | 3 +- tests/test_simplex.py | 2 +- tests/test_tools.py | 95 ++++++ tests/test_validity_checker.py | 38 +-- 35 files changed, 544 insertions(+), 885 deletions(-) delete mode 100644 blueprints/tools/crs_converter_allowed_files.json delete mode 100644 blueprints/tools/crs_converter_allowed_objects.json delete mode 100644 blueprints/tools/crs_converter_output_file_extensions.json delete mode 100644 blueprints/tools/file_converter_allowed_files.json delete mode 100644 blueprints/tools/file_converter_allowed_objects.json delete mode 100644 blueprints/tools/file_converter_output_file_extensions.json delete mode 100644 blueprints/tools/validity_checker_allowed_files.json delete mode 100644 blueprints/tools/validity_checker_allowed_objects.json create mode 100644 blueprints/tools_allowed_files.json create mode 100644 blueprints/tools_allowed_objects.json create mode 100644 blueprints/tools_geode_objects_and_output_extensions.json create mode 100644 blueprints/tools_missing_files.json rename blueprints/workflows/{implicit _update_value.json => implicit_update_value.json} (100%) diff --git a/app.py b/app.py index 8d09cfd..efb9199 100644 --- a/app.py +++ b/app.py @@ -87,7 +87,6 @@ def kill_task(): @app.errorhandler(HTTPException) def handle_exception(e): response = e.get_response() - print(e.description) response.data = flask.json.dumps( { "code": e.code, diff --git a/blueprints/blueprint_tools.py b/blueprints/blueprint_tools.py index 933c1d7..2cd7024 100644 --- a/blueprints/blueprint_tools.py +++ b/blueprints/blueprint_tools.py @@ -1,4 +1,8 @@ +# Standard library imports +import json import os + +# Third party imports import flask import flask_cors from opengeodeweb_back import geode_functions, geode_objects @@ -7,10 +11,7 @@ import blueprints.tools.blueprint_file_converter as bp_file_converter import blueprints.tools.blueprint_validity_checker as bp_validity_checker import blueprints.tools.blueprint_crs_converter as bp_crs_converter -import json -with open("blueprints/tools_upload_file.json", "r") as file: - upload_file_json = json.load(file) tools_routes = flask.Blueprint("crs_converter_routes", __name__) flask_cors.CORS(tools_routes) @@ -50,7 +51,28 @@ def teardown_request(exception): ) -@tools_routes.route(upload_file_json["route"], methods=upload_file_json["methods"]) +with open("blueprints/tools_allowed_files.json", "r") as file: + tools_allowed_files_json = json.load(file) + + +@tools_routes.route( + tools_allowed_files_json["route"], + methods=tools_allowed_files_json["methods"], +) +def allowed_files(): + geode_functions.validate_request(flask.request, tools_allowed_files_json) + extensions = geode_functions.list_input_extensions(flask.request.json["key"]) + return {"status": 200, "extensions": extensions} + + +with open("blueprints/tools_upload_file.json", "r") as file: + tools_upload_file_json = json.load(file) + + +@tools_routes.route( + tools_upload_file_json["route"], + methods=tools_upload_file_json["methods"], +) def upload_file(): if flask.request.method == "OPTIONS": return flask.make_response({}, 200) @@ -62,5 +84,89 @@ def upload_file(): for file in files: filename = werkzeug.utils.secure_filename(os.path.basename(file.filename)) + print(f"{filename=}") file.save(os.path.join(UPLOAD_FOLDER, filename)) return flask.make_response({"message": "File uploaded"}, 201) + + +with open("blueprints/tools_allowed_objects.json", "r") as file: + tools_allowed_objects_json = json.load(file) + + +@tools_routes.route( + tools_allowed_objects_json["route"], + methods=tools_allowed_objects_json["methods"], +) +def allowed_objects(): + geode_functions.validate_request(flask.request, tools_allowed_objects_json) + file_extension = os.path.splitext(flask.request.json["filename"])[1][1:] + allowed_objects = geode_functions.list_geode_objects( + file_extension, flask.request.json["key"] + ) + + return flask.make_response({"allowed_objects": allowed_objects}, 200) + + +with open("blueprints/tools_missing_files.json", "r") as file: + tools_missing_files_json = json.load(file) + + +@tools_routes.route( + tools_missing_files_json["route"], + methods=tools_missing_files_json["methods"], +) +def missing_files(): + UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"] + geode_functions.validate_request(flask.request, tools_missing_files_json) + + missing_files = geode_functions.missing_files( + flask.request.json["input_geode_object"], + os.path.join(UPLOAD_FOLDER, flask.request.json["filename"]), + ) + has_missing_files = missing_files.has_missing_files() + mandatory_files = missing_files.mandatory_files + additional_files = missing_files.additional_files + + mandatory_files_list = [] + for mandatory_file in mandatory_files: + mandatory_files_list.append(os.path.basename(mandatory_file)) + + additional_files_list = [] + for additional_file in additional_files: + additional_files_list.append(os.path.basename(additional_file)) + + return flask.make_response( + { + "has_missing_files": has_missing_files, + "mandatory_files": mandatory_files_list, + "additional_files": additional_files_list, + }, + 200, + ) + + +with open("blueprints/tools_geode_objects_and_output_extensions.json", "r") as file: + tools_geode_objects_and_output_extensions_json = json.load(file) + + +@tools_routes.route( + tools_geode_objects_and_output_extensions_json["route"], + methods=tools_geode_objects_and_output_extensions_json["methods"], +) +def geode_objects_and_output_extensions(): + geode_functions.validate_request( + flask.request, tools_geode_objects_and_output_extensions_json + ) + geode_objects_output_extensions = geode_functions.geode_objects_output_extensions( + flask.request.json["input_geode_object"] + ) + geode_objects_and_output_extensions = ( + geode_functions.geode_objects_output_extensions( + flask.request.json["input_geode_object"] + ) + ) + + return flask.make_response( + {"geode_objects_and_output_extensions": geode_objects_and_output_extensions}, + 200, + ) diff --git a/blueprints/blueprint_workflows.py b/blueprints/blueprint_workflows.py index 0b88167..1421f3a 100644 --- a/blueprints/blueprint_workflows.py +++ b/blueprints/blueprint_workflows.py @@ -1,4 +1,7 @@ +# Standard library imports import os + +# Third party imports import flask import flask_cors from opengeodeweb_back import geode_functions, geode_objects diff --git a/blueprints/tools/blueprint_crs_converter.py b/blueprints/tools/blueprint_crs_converter.py index 35fe61e..14553f8 100644 --- a/blueprints/tools/blueprint_crs_converter.py +++ b/blueprints/tools/blueprint_crs_converter.py @@ -1,4 +1,5 @@ # Standard library imports +import json import os import shutil import uuid @@ -9,31 +10,14 @@ import flask_cors import werkzeug from opengeodeweb_back import geode_functions -import json - -with open("blueprints/tools/crs_converter_allowed_files.json", "r") as file: - crs_converter_allowed_files_json = json.load(file) - -with open("blueprints/tools/crs_converter_allowed_objects.json", "r") as file: - crs_converter_allowed_objects_json = json.load(file) - -with open("blueprints/tools/crs_converter_convert_file.json", "r") as file: - crs_converter_convert_file_json = json.load(file) -with open( - "blueprints/tools/crs_converter_geographic_coordinate_systems.json", "r" -) as file: - crs_converter_geographic_coordinate_systems_json = json.load(file) +crs_converter_routes = flask.Blueprint("crs_converter_routes", __name__) +flask_cors.CORS(crs_converter_routes) -with open("blueprints/tools/crs_converter_output_file_extensions.json", "r") as file: - crs_converter_output_file_extensions_json = json.load(file) with open("blueprints/tools/crs_converter_versions.json", "r") as file: crs_converter_versions_json = json.load(file) -crs_converter_routes = flask.Blueprint("crs_converter_routes", __name__) -flask_cors.CORS(crs_converter_routes) - @crs_converter_routes.route( crs_converter_versions_json["route"], methods=crs_converter_versions_json["methods"] @@ -51,26 +35,10 @@ def crs_converter_versions(): ) -@crs_converter_routes.route( - crs_converter_allowed_files_json["route"], - methods=crs_converter_allowed_files_json["methods"], -) -def crs_converter_allowed_files(): - geode_functions.validate_request(flask.request, crs_converter_allowed_files_json) - extensions = geode_functions.list_input_extensions("crs") - return {"status": 200, "extensions": extensions} - - -@crs_converter_routes.route( - crs_converter_allowed_objects_json["route"], - methods=crs_converter_allowed_objects_json["methods"], -) -def crs_converter_allowed_objects(): - geode_functions.validate_request(flask.request, crs_converter_allowed_objects_json) - file_extension = os.path.splitext(flask.request.json["filename"])[1][1:] - allowed_objects = geode_functions.list_geode_objects(file_extension, "crs") - - return flask.make_response({"allowed_objects": allowed_objects}, 200) +with open( + "blueprints/tools/crs_converter_geographic_coordinate_systems.json", "r" +) as file: + crs_converter_geographic_coordinate_systems_json = json.load(file) @crs_converter_routes.route( @@ -82,7 +50,7 @@ def crs_converter_geographic_coordinate_systems(): flask.request, crs_converter_geographic_coordinate_systems_json ) infos = geode_functions.geographic_coordinate_systems( - flask.request.json["geode_object"] + flask.request.json["input_geode_object"] ) crs_list = [] @@ -96,19 +64,8 @@ def crs_converter_geographic_coordinate_systems(): return flask.make_response({"crs_list": crs_list}, 200) -@crs_converter_routes.route( - crs_converter_output_file_extensions_json["route"], - methods=crs_converter_output_file_extensions_json["methods"], -) -def crs_converter_output_file_extensions(): - geode_functions.validate_request( - flask.request, crs_converter_output_file_extensions_json - ) - output_file_extensions = geode_functions.geode_object_output_extensions( - flask.request.json["geode_object"] - ) - - return flask.make_response({"output_file_extensions": output_file_extensions}, 200) +with open("blueprints/tools/crs_converter_convert_file.json", "r") as file: + crs_converter_convert_file_json = json.load(file) @crs_converter_routes.route( @@ -122,33 +79,21 @@ async def crs_converter_convert_file(): ) UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"] - input_crs = { - "authority": flask.request.json["input_crs_authority"], - "code": flask.request.json["input_crs_code"], - "name": flask.request.json["input_crs_name"], - } - - output_crs = { - "authority": flask.request.json["output_crs_authority"], - "code": flask.request.json["output_crs_code"], - "name": flask.request.json["output_crs_name"], - } - secure_filename = werkzeug.utils.secure_filename(flask.request.json["filename"]) file_path = os.path.abspath(os.path.join(UPLOAD_FOLDER, secure_filename)) - data = geode_functions.load(flask.request.json["geode_object"], file_path) + data = geode_functions.load(flask.request.json["input_geode_object"], file_path) strict_file_name = os.path.splitext(secure_filename)[0] - new_file_name = strict_file_name + "." + flask.request.json["extension"] + new_file_name = strict_file_name + "." + flask.request.json["output_extension"] geode_functions.assign_geographic_coordinate_system_info( - flask.request.json["geode_object"], data, input_crs + flask.request.json["input_geode_object"], data, flask.request.json["input_crs"] ) geode_functions.convert_geographic_coordinate_system_info( - flask.request.json["geode_object"], data, output_crs + flask.request.json["input_geode_object"], data, flask.request.json["output_crs"] ) geode_functions.save( - flask.request.json["geode_object"], + flask.request.json["output_geode_object"], data, os.path.abspath(UPLOAD_FOLDER), new_file_name, diff --git a/blueprints/tools/blueprint_file_converter.py b/blueprints/tools/blueprint_file_converter.py index 579ed43..4973aa5 100644 --- a/blueprints/tools/blueprint_file_converter.py +++ b/blueprints/tools/blueprint_file_converter.py @@ -1,4 +1,5 @@ # Standard library imports +import json import os import shutil import zipfile @@ -8,28 +9,15 @@ import flask_cors import werkzeug from opengeodeweb_back import geode_functions -import json - -with open("blueprints/tools/crs_converter_allowed_files.json", "r") as file: - file_converter_allowed_files_json = json.load(file) - -with open("blueprints/tools/file_converter_allowed_objects.json", "r") as file: - file_converter_allowed_objects_json = json.load(file) -with open("blueprints/tools/file_converter_convert_file.json", "r") as file: - file_converter_convert_file_json = json.load(file) +file_converter_routes = flask.Blueprint("file_converter_routes", __name__) +flask_cors.CORS(file_converter_routes) -with open("blueprints/tools/file_converter_output_file_extensions.json", "r") as file: - file_converter_output_file_extensions_json = json.load(file) with open("blueprints/tools/file_converter_versions.json", "r") as file: file_converter_versions_json = json.load(file) -file_converter_routes = flask.Blueprint("file_converter_routes", __name__) -flask_cors.CORS(file_converter_routes) - - @file_converter_routes.route( file_converter_versions_json["route"], methods=file_converter_versions_json["methods"], @@ -48,40 +36,8 @@ def file_converter_versions(): ) -@file_converter_routes.route( - file_converter_allowed_files_json["route"], - methods=file_converter_allowed_files_json["methods"], -) -def file_converter_allowed_files(): - geode_functions.validate_request(flask.request, file_converter_allowed_files_json) - extensions = geode_functions.list_input_extensions() - return {"status": 200, "extensions": extensions} - - -@file_converter_routes.route( - file_converter_allowed_objects_json["route"], - methods=file_converter_allowed_objects_json["methods"], -) -def file_converter_allowed_objects(): - geode_functions.validate_request(flask.request, file_converter_allowed_objects_json) - file_extension = os.path.splitext(flask.request.json["filename"])[1][1:] - allowed_objects = geode_functions.list_geode_objects(file_extension) - - return flask.make_response({"allowed_objects": allowed_objects}, 200) - - -@file_converter_routes.route( - file_converter_output_file_extensions_json["route"], - methods=file_converter_output_file_extensions_json["methods"], -) -def file_converter_output_file_extensions(): - geode_functions.validate_request( - flask.request, file_converter_output_file_extensions_json - ) - output_file_extensions = geode_functions.geode_object_output_extensions( - flask.request.json["geode_object"] - ) - return flask.make_response({"output_file_extensions": output_file_extensions}, 200) +with open("blueprints/tools/file_converter_convert_file.json", "r") as file: + file_converter_convert_file_json = json.load(file) @file_converter_routes.route( @@ -94,16 +50,16 @@ async def file_converter_convert_file(): secure_filename = werkzeug.utils.secure_filename(flask.request.json["filename"]) file_path = os.path.abspath(os.path.join(UPLOAD_FOLDER, secure_filename)) - data = geode_functions.load(flask.request.json["geode_object"], file_path) + data = geode_functions.load(flask.request.json["input_geode_object"], file_path) strict_file_name = os.path.splitext(secure_filename)[0] - new_file_name = strict_file_name + "." + flask.request.json["extension"] + new_file_name = strict_file_name + "." + flask.request.json["output_extension"] sub_folder = f"{UPLOAD_FOLDER}/{strict_file_name}/" if os.path.exists(sub_folder): shutil.rmtree(sub_folder) geode_functions.save( - flask.request.json["geode_object"], + flask.request.json["output_geode_object"], data, os.path.abspath(UPLOAD_FOLDER), new_file_name, @@ -111,8 +67,8 @@ async def file_converter_convert_file(): mimetype = "application/octet-binary" list_exceptions = ["triangle", "vtm"] - if flask.request.json["extension"] in list_exceptions: - if flask.request.json["extension"] == "triangle": + if flask.request.json["output_extension"] in list_exceptions: + if flask.request.json["output_extension"] == "triangle": os.mkdir(sub_folder) os.chdir(sub_folder) generated_files = f"{UPLOAD_FOLDER}/{strict_file_name}" @@ -120,7 +76,7 @@ async def file_converter_convert_file(): shutil.move(generated_files + ".neigh", sub_folder) shutil.move(generated_files + ".node", sub_folder) os.chdir("..") - elif flask.request.json["extension"] == "vtm": + elif flask.request.json["output_extension"] == "vtm": generated_files = f"{UPLOAD_FOLDER}/{strict_file_name}" shutil.move(generated_files + ".vtm", sub_folder) new_file_name = strict_file_name + ".zip" diff --git a/blueprints/tools/blueprint_validity_checker.py b/blueprints/tools/blueprint_validity_checker.py index 200a2b7..b2a45e6 100644 --- a/blueprints/tools/blueprint_validity_checker.py +++ b/blueprints/tools/blueprint_validity_checker.py @@ -8,26 +8,14 @@ from opengeodeweb_back import geode_functions, inspector_functions import json -with open("blueprints/tools/validity_checker_allowed_files.json", "r") as file: - validity_checker_allowed_files_json = json.load(file) - -with open("blueprints/tools/validity_checker_allowed_objects.json", "r") as file: - validity_checker_allowed_objects_json = json.load(file) - -with open("blueprints/tools/validity_checker_inspect_file.json", "r") as file: - validity_checker_inspect_file_json = json.load(file) +validity_checker_routes = flask.Blueprint("validity_checker_routes", __name__) +flask_cors.CORS(validity_checker_routes) -with open("blueprints/tools/validity_checker_test_names.json", "r") as file: - validity_checker_test_names_json = json.load(file) with open("blueprints/tools/validity_checker_versions.json", "r") as file: validity_checker_versions_json = json.load(file) -validity_checker_routes = flask.Blueprint("validity_checker_routes", __name__) -flask_cors.CORS(validity_checker_routes) - - @validity_checker_routes.route( validity_checker_versions_json["route"], methods=validity_checker_versions_json["methods"], @@ -46,29 +34,8 @@ def validity_checker_versions(): ) -@validity_checker_routes.route( - validity_checker_allowed_files_json["route"], - methods=validity_checker_allowed_files_json["methods"], -) -def validity_checker_allowed_files(): - geode_functions.validate_request(flask.request, validity_checker_allowed_files_json) - extensions = geode_functions.list_input_extensions("inspector") - - return flask.make_response({"extensions": extensions}, 200) - - -@validity_checker_routes.route( - validity_checker_allowed_objects_json["route"], - methods=validity_checker_allowed_objects_json["methods"], -) -def validity_checker_allowed_objects(): - geode_functions.validate_request( - flask.request, validity_checker_allowed_objects_json - ) - file_extension = os.path.splitext(flask.request.json["filename"])[1][1:] - allowed_objects = geode_functions.list_geode_objects(file_extension, "inspector") - - return flask.make_response({"allowed_objects": allowed_objects}, 200) +with open("blueprints/tools/validity_checker_test_names.json", "r") as file: + validity_checker_test_names_json = json.load(file) @validity_checker_routes.route( @@ -78,7 +45,7 @@ def validity_checker_allowed_objects(): def validity_checker_test_names(): geode_functions.validate_request(flask.request, validity_checker_test_names_json) model_checks = inspector_functions.json_return( - inspector_functions.inspectors()[flask.request.json["geode_object"]][ + inspector_functions.inspectors()[flask.request.json["input_geode_object"]][ "tests_names" ] ) @@ -86,6 +53,10 @@ def validity_checker_test_names(): return flask.make_response({"model_checks": model_checks}, 200) +with open("blueprints/tools/validity_checker_inspect_file.json", "r") as file: + validity_checker_inspect_file_json = json.load(file) + + @validity_checker_routes.route( validity_checker_inspect_file_json["route"], methods=validity_checker_inspect_file_json["methods"], @@ -93,12 +64,13 @@ def validity_checker_test_names(): def validity_checker_inspect_file(): geode_functions.validate_request(flask.request, validity_checker_inspect_file_json) UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"] - array_variables = ["geode_object", "filename", "test"] secure_filename = werkzeug.utils.secure_filename(flask.request.json["filename"]) file_path = os.path.abspath(os.path.join(UPLOAD_FOLDER, secure_filename)) - data = geode_functions.load(flask.request.json["geode_object"], file_path) - inspector = geode_functions.inspector(flask.request.json["geode_object"], data) + data = geode_functions.load(flask.request.json["input_geode_object"], file_path) + inspector = geode_functions.inspector( + flask.request.json["input_geode_object"], data + ) test_result = getattr(inspector, flask.request.json["test"])() if type(test_result) == int: @@ -122,7 +94,7 @@ def validity_checker_inspect_file(): expected_result ) - if result == False: + if result is False: test_name = flask.request.json["test"] print(f"Wrong test result: {test_name}", flush=True) diff --git a/blueprints/tools/crs_converter_allowed_files.json b/blueprints/tools/crs_converter_allowed_files.json deleted file mode 100644 index b4f7056..0000000 --- a/blueprints/tools/crs_converter_allowed_files.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "$id": "/tools/crs_converter/allowed_files", - "route": "/allowed_files", - "methods": [ - "GET" - ], - "type": "object", - "additionalProperties": false -} \ No newline at end of file diff --git a/blueprints/tools/crs_converter_allowed_objects.json b/blueprints/tools/crs_converter_allowed_objects.json deleted file mode 100644 index 24f5d2c..0000000 --- a/blueprints/tools/crs_converter_allowed_objects.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "$id": "/tools/crs_converter/allowed_objects", - "route": "/allowed_objects", - "methods": [ - "POST" - ], - "type": "object", - "properties": { - "filename": { - "type": "string" - } - }, - "required": [ - "filename" - ], - "additionalProperties": false -} \ No newline at end of file diff --git a/blueprints/tools/crs_converter_convert_file.json b/blueprints/tools/crs_converter_convert_file.json index f0876ca..09b9c3a 100644 --- a/blueprints/tools/crs_converter_convert_file.json +++ b/blueprints/tools/crs_converter_convert_file.json @@ -1,49 +1,67 @@ { - "$id": "/tools/crs_converter/convert_file", - "route": "/convert_file", - "methods": [ - "POST" - ], - "type": "object", - "properties": { - "geode_object": { - "type": "string" - }, - "filename": { - "type": "string" - }, - "input_crs_authority": { - "type": "string" - }, - "input_crs_code": { - "type": "string" - }, - "input_crs_name": { - "type": "string" + "$id": "/tools/crs_converter/convert_file", + "route": "/convert_file", + "methods": ["POST"], + "type": "object", + "properties": { + "input_geode_object": { + "type": "string" + }, + "filename": { + "type": "string" + }, + "input_crs": { + "type": "object", + "properties": { + "name": { + "type": "string" }, - "output_crs_authority": { - "type": "string" + "code": { + "type": "string" }, - "output_crs_code": { - "type": "string" + "authority": { + "type": "string" + } + }, + "required": ["name", "code", "authority"], + "additionalProperties": false + }, + "output_crs": { + "type": "object", + "properties": { + "name": { + "type": "string" }, - "output_crs_name": { - "type": "string" + "code": { + "type": "string" }, - "extension": { - "type": "string" + "authority": { + "type": "string" } + }, + "required": ["name", "code", "authority"], + "additionalProperties": false + }, + "output_geode_object": { + "type": "string" + }, + "output_extension": { + "type": "string" + }, + "responseType": { + "type": "string" }, - "required": [ - "geode_object", - "filename", - "input_crs_authority", - "input_crs_code", - "input_crs_name", - "output_crs_authority", - "output_crs_code", - "output_crs_name", - "extension" - ], - "additionalProperties": false -} \ No newline at end of file + "responseEncoding": { + "type": "string" + } + }, + "required": [ + "input_geode_object", + "filename", + "input_crs", + "output_crs", + "output_geode_object", + "output_extension" + ], + "additionalProperties": false +} diff --git a/blueprints/tools/crs_converter_geographic_coordinate_systems.json b/blueprints/tools/crs_converter_geographic_coordinate_systems.json index 7413b21..2a36022 100644 --- a/blueprints/tools/crs_converter_geographic_coordinate_systems.json +++ b/blueprints/tools/crs_converter_geographic_coordinate_systems.json @@ -1,17 +1,13 @@ { - "$id": "/tools/crs_converter/geographic_coordinate_systems", - "route": "/geographic_coordinate_systems", - "methods": [ - "POST" - ], - "type": "object", - "properties": { - "geode_object": { - "type": "string" - } - }, - "required": [ - "geode_object" - ], - "additionalProperties": false -} \ No newline at end of file + "$id": "/tools/crs_converter/geographic_coordinate_systems", + "route": "/geographic_coordinate_systems", + "methods": ["POST"], + "type": "object", + "properties": { + "input_geode_object": { + "type": "string" + } + }, + "required": ["input_geode_object"], + "additionalProperties": false +} diff --git a/blueprints/tools/crs_converter_output_file_extensions.json b/blueprints/tools/crs_converter_output_file_extensions.json deleted file mode 100644 index 61681b4..0000000 --- a/blueprints/tools/crs_converter_output_file_extensions.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "$id": "/tools/crs_converter/output_file_extensions", - "route": "/output_file_extensions", - "methods": [ - "POST" - ], - "type": "object", - "properties": { - "geode_object": { - "type": "string" - } - }, - "required": [ - "geode_object" - ], - "additionalProperties": false -} \ No newline at end of file diff --git a/blueprints/tools/crs_converter_versions.json b/blueprints/tools/crs_converter_versions.json index 523d61c..ca24d57 100644 --- a/blueprints/tools/crs_converter_versions.json +++ b/blueprints/tools/crs_converter_versions.json @@ -1,9 +1,7 @@ { - "$id": "/tools/crs_converter/versions", - "route": "/versions", - "methods": [ - "GET" - ], - "type": "object", - "additionalProperties": false -} \ No newline at end of file + "$id": "/tools/crs_converter/versions", + "route": "/versions", + "methods": ["GET"], + "type": "object", + "additionalProperties": false +} diff --git a/blueprints/tools/file_converter_allowed_files.json b/blueprints/tools/file_converter_allowed_files.json deleted file mode 100644 index d9b7644..0000000 --- a/blueprints/tools/file_converter_allowed_files.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "$id": "/tools/file_converter/allowed_objects", - "route": "/allowed_objects", - "methods": [ - "GET" - ], - "type": "object" -} \ No newline at end of file diff --git a/blueprints/tools/file_converter_allowed_objects.json b/blueprints/tools/file_converter_allowed_objects.json deleted file mode 100644 index d4d71d1..0000000 --- a/blueprints/tools/file_converter_allowed_objects.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "$id": "/tools/file_converter/allowed_objects", - "route": "/allowed_objects", - "methods": [ - "POST" - ], - "type": "object", - "properties": { - "filename": { - "type": "string" - } - }, - "required": [ - "filename" - ], - "additionalProperties": false -} \ No newline at end of file diff --git a/blueprints/tools/file_converter_convert_file.json b/blueprints/tools/file_converter_convert_file.json index a69a44b..6fb0131 100644 --- a/blueprints/tools/file_converter_convert_file.json +++ b/blueprints/tools/file_converter_convert_file.json @@ -1,25 +1,33 @@ { - "$id": "/tools/file_converter/convert_file", - "route": "/convert_file", - "methods": [ - "POST" - ], - "type": "object", - "properties": { - "geode_object": { - "type": "string" - }, - "filename": { - "type": "string" - }, - "extension": { - "type": "string" - } + "$id": "/tools/file_converter/convert_file", + "route": "/convert_file", + "methods": ["POST"], + "type": "object", + "properties": { + "input_geode_object": { + "type": "string" }, - "required": [ - "geode_object", - "filename", - "extension" - ], - "additionalProperties": false -} \ No newline at end of file + "filename": { + "type": "string" + }, + "output_geode_object": { + "type": "string" + }, + "output_extension": { + "type": "string" + }, + "responseType": { + "type": "string" + }, + "responseEncoding": { + "type": "string" + } + }, + "required": [ + "input_geode_object", + "filename", + "output_geode_object", + "output_extension" + ], + "additionalProperties": false +} diff --git a/blueprints/tools/file_converter_output_file_extensions.json b/blueprints/tools/file_converter_output_file_extensions.json deleted file mode 100644 index 84b45da..0000000 --- a/blueprints/tools/file_converter_output_file_extensions.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "$id": "/tools/file_converter/output_file_extensions", - "route": "/output_file_extensions", - "methods": [ - "POST" - ], - "type": "object", - "properties": { - "geode_object": { - "type": "string" - } - }, - "required": [ - "geode_object" - ], - "additionalProperties": false -} \ No newline at end of file diff --git a/blueprints/tools/validity_checker_allowed_files.json b/blueprints/tools/validity_checker_allowed_files.json deleted file mode 100644 index d8812d7..0000000 --- a/blueprints/tools/validity_checker_allowed_files.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "$id": "/tools/validity_checker/allowed_files", - "route": "/allowed_files", - "methods": [ - "GET" - ], - "type": "object", - "additionalProperties": false -} \ No newline at end of file diff --git a/blueprints/tools/validity_checker_allowed_objects.json b/blueprints/tools/validity_checker_allowed_objects.json deleted file mode 100644 index 8c2e345..0000000 --- a/blueprints/tools/validity_checker_allowed_objects.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "$id": "/tools/validity_checker/allowed_objects", - "route": "/allowed_objects", - "methods": [ - "POST" - ], - "type": "object", - "properties": { - "filename": { - "type": "string" - } - }, - "required": [ - "filename" - ], - "additionalProperties": false -} \ No newline at end of file diff --git a/blueprints/tools/validity_checker_inspect_file.json b/blueprints/tools/validity_checker_inspect_file.json index 74db837..4bb0b63 100644 --- a/blueprints/tools/validity_checker_inspect_file.json +++ b/blueprints/tools/validity_checker_inspect_file.json @@ -1,25 +1,19 @@ { - "$id": "/tools/validity_checker/inspect_file", - "route": "/inspect_file", - "methods": [ - "POST" - ], - "type": "object", - "properties": { - "geode_object": { - "type": "string" - }, - "filename": { - "type": "string" - }, - "test": { - "type": "string" - } + "$id": "/tools/validity_checker/inspect_file", + "route": "/inspect_file", + "methods": ["POST"], + "type": "object", + "properties": { + "input_geode_object": { + "type": "string" }, - "required": [ - "geode_object", - "filename", - "test" - ], - "additionalProperties": false -} \ No newline at end of file + "filename": { + "type": "string" + }, + "test": { + "type": "string" + } + }, + "required": ["input_geode_object", "filename", "test"], + "additionalProperties": false +} diff --git a/blueprints/tools/validity_checker_test_names.json b/blueprints/tools/validity_checker_test_names.json index 76ac567..e6c793e 100644 --- a/blueprints/tools/validity_checker_test_names.json +++ b/blueprints/tools/validity_checker_test_names.json @@ -1,17 +1,13 @@ { - "$id": "/tools/validity_checker/tests_names", - "route": "/tests_names", - "methods": [ - "POST" - ], - "type": "object", - "properties": { - "geode_object": { - "type": "string" - } - }, - "required": [ - "geode_object" - ], - "additionalProperties": false -} \ No newline at end of file + "$id": "/tools/validity_checker/tests_names", + "route": "/tests_names", + "methods": ["POST"], + "type": "object", + "properties": { + "input_geode_object": { + "type": "string" + } + }, + "required": ["input_geode_object"], + "additionalProperties": false +} diff --git a/blueprints/tools_allowed_files.json b/blueprints/tools_allowed_files.json new file mode 100644 index 0000000..01403d1 --- /dev/null +++ b/blueprints/tools_allowed_files.json @@ -0,0 +1,13 @@ +{ + "$id": "/tools/allowed_files", + "route": "/allowed_files", + "methods": ["POST"], + "type": "object", + "properties": { + "key": { + "type": ["string", "null"] + } + }, + "required": ["key"], + "additionalProperties": false +} diff --git a/blueprints/tools_allowed_objects.json b/blueprints/tools_allowed_objects.json new file mode 100644 index 0000000..51f6a12 --- /dev/null +++ b/blueprints/tools_allowed_objects.json @@ -0,0 +1,16 @@ +{ + "$id": "/tools/allowed_objects", + "route": "/allowed_objects", + "methods": ["POST"], + "type": "object", + "properties": { + "filename": { + "type": "string" + }, + "key": { + "type": ["string", "null"] + } + }, + "required": ["filename", "key"], + "additionalProperties": false +} diff --git a/blueprints/tools_geode_objects_and_output_extensions.json b/blueprints/tools_geode_objects_and_output_extensions.json new file mode 100644 index 0000000..3408985 --- /dev/null +++ b/blueprints/tools_geode_objects_and_output_extensions.json @@ -0,0 +1,13 @@ +{ + "$id": "/tools/geode_objects_and_output_extensions", + "route": "/geode_objects_and_output_extensions", + "methods": ["POST"], + "type": "object", + "properties": { + "input_geode_object": { + "type": "string" + } + }, + "required": ["input_geode_object"], + "additionalProperties": false +} diff --git a/blueprints/tools_missing_files.json b/blueprints/tools_missing_files.json new file mode 100644 index 0000000..7a6b3ab --- /dev/null +++ b/blueprints/tools_missing_files.json @@ -0,0 +1,16 @@ +{ + "$id": "/tools/missing_files", + "route": "/missing_files", + "methods": ["POST"], + "type": "object", + "properties": { + "input_geode_object": { + "type": "string" + }, + "filename": { + "type": "string" + } + }, + "required": ["input_geode_object", "filename"], + "additionalProperties": false +} diff --git a/blueprints/workflows/blueprint_explicit.py b/blueprints/workflows/blueprint_explicit.py index bccc59b..545cfb3 100644 --- a/blueprints/workflows/blueprint_explicit.py +++ b/blueprints/workflows/blueprint_explicit.py @@ -9,18 +9,12 @@ import flask_cors import json -with open("blueprints/workflows/explicit_brep_stats.json") as file: - explicit_brep_stats_json = json.load(file) +explicit_routes = flask.Blueprint("explicit_routes", __name__) +flask_cors.CORS(explicit_routes) with open("blueprints/workflows/explicit_get_base_data.json") as file: explicit_get_base_data_json = json.load(file) -with open("blueprints/workflows/explicit_remesh.json") as file: - explicit_remesh_json = json.load(file) - -explicit_routes = flask.Blueprint("explicit_routes", __name__) -flask_cors.CORS(explicit_routes) - @explicit_routes.route( explicit_get_base_data_json["route"], methods=explicit_get_base_data_json["methods"] @@ -53,6 +47,10 @@ def sendBaseData(): ) +with open("blueprints/workflows/explicit_brep_stats.json") as file: + explicit_brep_stats_json = json.load(file) + + @explicit_routes.route( explicit_brep_stats_json["route"], methods=explicit_brep_stats_json["methods"] ) @@ -97,12 +95,16 @@ def sendBRepStats(): ) +with open("blueprints/workflows/explicit_remesh.json") as file: + explicit_remesh_json = json.load(file) + + @explicit_routes.route( explicit_remesh_json["route"], methods=explicit_remesh_json["methods"] ) def remesh(): DATA_FOLDER = flask.current_app.config["DATA_FOLDER"] - geode_functions.validate_request(flask.request, ["metric"]) + geode_functions.validate_request(flask.request, explicit_remesh_json) min_metric = 50 max_metric = 500 brep = geode_functions.load( diff --git a/blueprints/workflows/blueprint_implicit.py b/blueprints/workflows/blueprint_implicit.py index ae88321..5f1721f 100644 --- a/blueprints/workflows/blueprint_implicit.py +++ b/blueprints/workflows/blueprint_implicit.py @@ -12,25 +12,13 @@ import geode_conversion from opengeodeweb_back import geode_functions, geode_objects -with open("blueprints/workflows/implicit _update_value.json", "r") as file: - update_value_json = json.load(file) - -with open("blueprints/workflows/implicit_step0.json", "r") as file: - step0_json = json.load(file) - -with open("blueprints/workflows/implicit_step1.json", "r") as file: - step1_json = json.load(file) - -with open("blueprints/workflows/implicit_step2.json", "r") as file: - step2_json = json.load(file) - -with open("blueprints/workflows/implicit_step3.json", "r") as file: - step3_json = json.load(file) - implicit_routes = flask.Blueprint("implicit_routes", __name__) flask_cors.CORS(implicit_routes) +with open("blueprints/workflows/implicit_step0.json", "r") as file: + step0_json = json.load(file) + @implicit_routes.route(step0_json["route"], methods=step0_json["methods"]) def step0(): @@ -93,6 +81,10 @@ def step0(): ) +with open("blueprints/workflows/implicit_update_value.json", "r") as file: + update_value_json = json.load(file) + + @implicit_routes.route(update_value_json["route"], methods=update_value_json["methods"]) def update_value(): geode_functions.validate_request( @@ -124,6 +116,10 @@ def update_value(): ) +with open("blueprints/workflows/implicit_step1.json", "r") as file: + step1_json = json.load(file) + + @implicit_routes.route(step1_json["route"], methods=step1_json["methods"]) def step1(): geode_functions.validate_request( @@ -177,6 +173,10 @@ def step1(): ) +with open("blueprints/workflows/implicit_step2.json", "r") as file: + step2_json = json.load(file) + + @implicit_routes.route(step2_json["route"], methods=step2_json["methods"]) def step2(): geode_functions.validate_request(flask.request, step2_json) @@ -211,6 +211,10 @@ def step2(): ) +with open("blueprints/workflows/implicit_step3.json", "r") as file: + step3_json = json.load(file) + + @implicit_routes.route(step3_json["route"], methods=step3_json["methods"]) def step3(): geode_functions.validate_request(flask.request, step3_json) diff --git a/blueprints/workflows/blueprint_simplex.py b/blueprints/workflows/blueprint_simplex.py index f9cd525..1a3b546 100644 --- a/blueprints/workflows/blueprint_simplex.py +++ b/blueprints/workflows/blueprint_simplex.py @@ -7,15 +7,13 @@ import flask_cors import json -with open("blueprints/workflows/simplex_initialize.json", "r") as file: - simplex_initialize_json = json.load(file) - -with open("blueprints/workflows/simplex_remesh.json", "r") as file: - simplex_remesh_json = json.load(file) simplex_routes = flask.Blueprint("simplex_routes", __name__) flask_cors.CORS(simplex_routes) +with open("blueprints/workflows/simplex_initialize.json", "r") as file: + simplex_initialize_json = json.load(file) + @simplex_routes.route( simplex_initialize_json["route"], methods=simplex_initialize_json["methods"] @@ -38,6 +36,10 @@ def initialize(): ) +with open("blueprints/workflows/simplex_remesh.json", "r") as file: + simplex_remesh_json = json.load(file) + + @simplex_routes.route( simplex_remesh_json["route"], methods=simplex_remesh_json["methods"] ) diff --git a/blueprints/workflows/implicit _update_value.json b/blueprints/workflows/implicit_update_value.json similarity index 100% rename from blueprints/workflows/implicit _update_value.json rename to blueprints/workflows/implicit_update_value.json diff --git a/requirements.txt b/requirements.txt index 3199867..98f74e4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -107,7 +107,7 @@ opengeode-io==6.2.1 # geode-viewables # opengeode-inspector # opengeodeweb-back -opengeodeweb-back==2.0.0 +opengeodeweb-back==2.1.0 # via -r requirements.in python-dotenv==1.0.0 # via -r requirements.in diff --git a/tests/test_crs_converter.py b/tests/test_crs_converter.py index f16a63c..3622bea 100644 --- a/tests/test_crs_converter.py +++ b/tests/test_crs_converter.py @@ -14,52 +14,11 @@ def test_versions(client): assert type(version) is dict -def test_allowed_files(client): - response = client.get(f"{base_route}/allowed_files") - assert response.status_code == 200 - extensions = response.json["extensions"] - assert type(extensions) is list - for extension in extensions: - assert type(extension) is str - - -def test_allowed_objects(client): - route = f"{base_route}/allowed_objects" - - # Normal test with filename 'corbi.og_brep' - response = client.post(route, json={"filename": "corbi.og_brep"}) - assert response.status_code == 200 - allowed_objects = response.json["allowed_objects"] - assert type(allowed_objects) is list - assert "BRep" in allowed_objects - - # Normal test with filename .vtu - response = client.post(route, json={"filename": "toto.vtu"}) - assert response.status_code == 200 - allowed_objects = response.json["allowed_objects"] - list_objects = ["HybridSolid3D", "PolyhedralSolid3D", "TetrahedralSolid3D"] - for geode_object in list_objects: - assert geode_object in allowed_objects - - # Test with stupid filename - response = client.post(route, json={"filename": "toto.tutu"}) - assert response.status_code == 200 - allowed_objects = response.json["allowed_objects"] - assert type(allowed_objects) is list - assert not allowed_objects - - # Test without filename - response = client.post(route, json={}) - assert response.status_code == 400 - error_message = response.json["description"] - assert error_message == "Validation error: 'filename' is a required property" - - def test_geographic_coordinate_systems(client): route = f"{base_route}/geographic_coordinate_systems" # Normal test with geode_object 'BRep' - response = client.post(route, json={"geode_object": "BRep"}) + response = client.post(route, json={"input_geode_object": "BRep"}) assert response.status_code == 200 crs_list = response.json["crs_list"] assert type(crs_list) is list @@ -70,257 +29,49 @@ def test_geographic_coordinate_systems(client): response = client.post(route, json={}) assert response.status_code == 400 error_message = response.json["description"] - assert error_message == "Validation error: 'geode_object' is a required property" - - -def test_output_file_extensions(client): - route = f"{base_route}/output_file_extensions" - - # Normal test with geode_object - response = client.post(route, json={"geode_object": "BRep"}) - assert response.status_code == 200 - output_file_extensions = response.json["output_file_extensions"] - assert type(output_file_extensions) is list - for output_file_extension in output_file_extensions: - assert type(output_file_extension) is str - - # Test without object - response = client.post(route, json={}) - assert response.status_code == 400 - error_message = response.json["description"] - assert error_message == "Validation error: 'geode_object' is a required property" + assert ( + error_message == "Validation error: 'input_geode_object' is a required property" + ) def test_convert_file(client): - # Normal test with object/file/filename/extension - geode_object = ["BRep", "PolyhedralSolid3D"] - filenames = ["corbi.og_brep", "cube.vtu"] - input_crs_authority = "EPSG" - input_crs_code = "2000" - input_crs_name = "Anguilla 1957 / British West Indies Grid" - output_crs_authority = "EPSG" - output_crs_code = "2001" - output_crs_name = "Antigua 1943 / British West Indies Grid" - extension = ["msh", "vtu"] - - for index, filename in enumerate(filenames): - response = client.put( - "tools/upload_file", - data={"content": FileStorage(open(f"./tests/{filename}", "rb"))}, - ) - assert response.status_code == 201 - - response = client.post( - f"{base_route}/convert_file", - json={ - "geode_object": geode_object[index], - "filename": filename, - "input_crs_authority": input_crs_authority, - "input_crs_code": input_crs_code, - "input_crs_name": input_crs_name, - "output_crs_authority": output_crs_authority, - "output_crs_code": output_crs_code, - "output_crs_name": output_crs_name, - "extension": extension[index], + route = f"{base_route}/convert_file" + + filename = "corbi.og_brep" + response = client.put( + "tools/upload_file", + data={"content": FileStorage(open(f"./tests/{filename}", "rb"))}, + ) + assert response.status_code == 201 + + def get_full_data(): + return { + "input_geode_object": "BRep", + "filename": "corbi.og_brep", + "input_crs": { + "authority": "EPSG", + "code": "2000", + "name": "Anguilla 1957 / British West Indies Grid", }, - ) - - print(response) - assert response.status_code == 200 - - # Test without geode_object - response = client.post( - f"{base_route}/convert_file", - json={ - "filename": filename, - "input_crs_authority": input_crs_authority, - "input_crs_code": input_crs_code, - "input_crs_name": input_crs_name, - "output_crs_authority": output_crs_authority, - "output_crs_code": output_crs_code, - "output_crs_name": output_crs_name, - "extension": extension[index], + "output_crs": { + "authority": "EPSG", + "code": "2001", + "name": "Antigua 1943 / British West Indies Grid", }, - ) - - assert response.status_code == 400 - error_description = response.json["description"] + "output_geode_object": "BRep", + "output_extension": "msh", + } - assert ( - error_description - == "Validation error: 'geode_object' is a required property" - ) + response = client.post(route, json=get_full_data()) - # Test without filename - response = client.post( - f"{base_route}/convert_file", - json={ - "geode_object": geode_object[index], - "input_crs_authority": input_crs_authority, - "input_crs_code": input_crs_code, - "input_crs_name": input_crs_name, - "output_crs_authority": output_crs_authority, - "output_crs_code": output_crs_code, - "output_crs_name": output_crs_name, - "extension": extension[index], - }, - ) - - assert response.status_code == 400 - error_description = response.json["description"] - assert ( - error_description == "Validation error: 'filename' is a required property" - ) - - # Test without input_crs_authority - response = client.post( - f"{base_route}/convert_file", - json={ - "geode_object": geode_object[index], - "filename": filename, - "input_crs_code": input_crs_code, - "input_crs_name": input_crs_name, - "output_crs_authority": output_crs_authority, - "output_crs_code": output_crs_code, - "output_crs_name": output_crs_name, - "extension": extension[index], - }, - ) - - assert response.status_code == 400 - error_description = response.json["description"] - assert ( - error_description - == "Validation error: 'input_crs_authority' is a required property" - ) - - # Test without input_crs_code - response = client.post( - f"{base_route}/convert_file", - json={ - "geode_object": geode_object[index], - "filename": filename, - "input_crs_authority": input_crs_authority, - "input_crs_name": input_crs_name, - "output_crs_authority": output_crs_authority, - "output_crs_code": output_crs_code, - "output_crs_name": output_crs_name, - "extension": extension[index], - }, - ) - - assert response.status_code == 400 - error_description = response.json["description"] - assert ( - error_description - == "Validation error: 'input_crs_code' is a required property" - ) - - # Test without input_crs_name - response = client.post( - f"{base_route}/convert_file", - json={ - "geode_object": geode_object[index], - "filename": filename, - "input_crs_authority": input_crs_authority, - "input_crs_code": input_crs_code, - "output_crs_authority": output_crs_authority, - "output_crs_code": output_crs_code, - "output_crs_name": output_crs_name, - "extension": extension[index], - }, - ) - - assert response.status_code == 400 - error_description = response.json["description"] - assert ( - error_description - == "Validation error: 'input_crs_name' is a required property" - ) - - # Test without output_crs_authority - response = client.post( - f"{base_route}/convert_file", - json={ - "geode_object": geode_object[index], - "filename": filename, - "input_crs_authority": input_crs_authority, - "input_crs_code": input_crs_code, - "input_crs_name": input_crs_name, - "output_crs_code": output_crs_code, - "output_crs_name": output_crs_name, - "extension": extension[index], - }, - ) - - assert response.status_code == 400 - error_description = response.json["description"] - assert ( - error_description - == "Validation error: 'output_crs_authority' is a required property" - ) - - # Test without output_crs_code - response = client.post( - f"{base_route}/convert_file", - json={ - "geode_object": geode_object[index], - "filename": filename, - "input_crs_authority": input_crs_authority, - "input_crs_code": input_crs_code, - "input_crs_name": input_crs_name, - "output_crs_authority": output_crs_authority, - "output_crs_name": output_crs_name, - "extension": extension[index], - }, - ) - - assert response.status_code == 400 - error_description = response.json["description"] - assert ( - error_description - == "Validation error: 'output_crs_code' is a required property" - ) - - # Test without output_crs_name - response = client.post( - f"{base_route}/convert_file", - json={ - "geode_object": geode_object[index], - "filename": filename, - "input_crs_authority": input_crs_authority, - "input_crs_code": input_crs_code, - "input_crs_name": input_crs_name, - "output_crs_authority": output_crs_authority, - "output_crs_code": output_crs_code, - "extension": extension[index], - }, - ) - - assert response.status_code == 400 - error_description = response.json["description"] - assert ( - error_description - == "Validation error: 'output_crs_name' is a required property" - ) - - # Test without extension - response = client.post( - f"{base_route}/convert_file", - json={ - "geode_object": geode_object[index], - "filename": filename, - "input_crs_authority": input_crs_authority, - "input_crs_code": input_crs_code, - "input_crs_name": input_crs_name, - "output_crs_authority": output_crs_authority, - "output_crs_code": output_crs_code, - "output_crs_name": output_crs_name, - }, - ) + assert response.status_code == 200 + assert type((response.data)) is bytes + assert len((response.data)) > 0 + for key, value in get_full_data().items(): + json = get_full_data() + json.pop(key) + response = client.post(route, json=json) assert response.status_code == 400 error_description = response.json["description"] - assert ( - error_description == "Validation error: 'extension' is a required property" - ) + assert error_description == f"Validation error: '{key}' is a required property" diff --git a/tests/test_file_converter.py b/tests/test_file_converter.py index 133a36b..b5c4c45 100644 --- a/tests/test_file_converter.py +++ b/tests/test_file_converter.py @@ -14,132 +14,34 @@ def test_versions(client): assert type(version) is dict -def test_allowed_files(client): - response = client.get(f"{base_route}/allowed_files") - assert response.status_code == 200 - extensions = response.json["extensions"] - assert type(extensions) is list - for extension in extensions: - assert type(extension) is str - - -def test_allowed_objects(client): - # Normal test with filename 'corbi.og_brep' - response = client.post( - f"{base_route}/allowed_objects", json={"filename": "corbi.og_brep"} - ) - print(response) - assert response.status_code == 200 - allowed_objects = response.json["allowed_objects"] - assert type(allowed_objects) is list - assert "BRep" in allowed_objects - - # Normal test with filename .vtu - response = client.post( - f"{base_route}/allowed_objects", json={"filename": "toto.vtu"} - ) - assert response.status_code == 200 - allowed_objects = response.json["allowed_objects"] - list_objects = ["HybridSolid3D", "PolyhedralSolid3D", "TetrahedralSolid3D"] - for geode_object in allowed_objects: - assert geode_object in allowed_objects - - # Test with stupid filename - response = client.post( - f"{base_route}/allowed_objects", json={"filename": "toto.tutu"} - ) - assert response.status_code == 200 - allowed_objects = response.json["allowed_objects"] - assert type(allowed_objects) is list - assert not allowed_objects - - # Test without filename - response = client.post(f"{base_route}/allowed_objects", json={}) - assert response.status_code == 400 - error_message = response.json["description"] - assert error_message == "Validation error: 'filename' is a required property" - - -def test_output_file_extensions(client): - # Normal test with object - response = client.post( - f"{base_route}/output_file_extensions", json={"geode_object": "BRep"} - ) - assert response.status_code == 200 - output_file_extensions = response.json["output_file_extensions"] - assert type(output_file_extensions) is list - for output_file_extension in output_file_extensions: - assert type(output_file_extension) is str - - # Test without object - response = client.post(f"{base_route}/output_file_extensions", json={}) - assert response.status_code == 400 - error_message = response.json["description"] - assert error_message == "Validation error: 'geode_object' is a required property" - - def test_convert_file(client): - # Normal test with object/file/filename/extension - geode_object = "BRep" - filename = "corbi.og_brep" - extension = "msh" + route = f"{base_route}/convert_file" + filename = "corbi.og_brep" response = client.put( "tools/upload_file", data={"content": FileStorage(open(f"./tests/{filename}", "rb"))}, ) assert response.status_code == 201 - response = client.post( - f"{base_route}/convert_file", - json={ - "geode_object": geode_object, - "filename": filename, - "extension": extension, - }, - ) - - assert response.status_code == 200 - # assert type((response.data)) is bytes - # assert len((response.data)) > 0 - - # Test without object - response = client.post( - f"{base_route}/convert_file", - json={ - "filename": filename, - "extension": extension, - }, - ) - - assert response.status_code == 400 - error_description = response.json["description"] - assert ( - error_description == "Validation error: 'geode_object' is a required property" - ) - - # Test without filename - response = client.post( - f"{base_route}/convert_file", - json={ - "geode_object": geode_object, - "extension": extension, - }, - ) - - assert response.status_code == 400 - error_description = response.json["description"] - assert error_description == "Validation error: 'filename' is a required property" + def get_full_data(): + return { + "input_geode_object": "BRep", + "filename": "corbi.og_brep", + "output_geode_object": "BRep", + "output_extension": "msh", + } - # Test without extension - response = client.post( - f"{base_route}/convert_file", - json={ - "geode_object": geode_object, - "filename": filename, - }, - ) + response = client.post(route, json=get_full_data()) - assert response.status_code == 400 - error_description = response.json["description"] - assert error_description == "Validation error: 'extension' is a required property" + assert response.status_code == 200 + assert type((response.data)) is bytes + assert len((response.data)) > 0 + + for key, value in get_full_data().items(): + json = get_full_data() + json.pop(key) + response = client.post(route, json=json) + assert response.status_code == 400 + error_description = response.json["description"] + assert error_description == f"Validation error: '{key}' is a required property" diff --git a/tests/test_implicit.py b/tests/test_implicit.py index 92b0866..9616365 100644 --- a/tests/test_implicit.py +++ b/tests/test_implicit.py @@ -60,6 +60,7 @@ def test_step2(client): error_description = response.json["description"] assert error_description == "Validation error: 'axis' is a required property" + def test_step3(client): metric = 1 @@ -80,4 +81,4 @@ def test_step3(client): response = client.post(f"{base_route}/step3", json={}) assert response.status_code == 400 error_description = response.json["description"] - assert error_description == "Validation error: 'metric' is a required property" \ No newline at end of file + assert error_description == "Validation error: 'metric' is a required property" diff --git a/tests/test_simplex.py b/tests/test_simplex.py index 0d77630..de3cc12 100644 --- a/tests/test_simplex.py +++ b/tests/test_simplex.py @@ -53,4 +53,4 @@ def test_remesh(client): ) assert response.status_code == 400 error_description = response.json["description"] - assert error_description == "Validation error: 'metric' is a required property" \ No newline at end of file + assert error_description == "Validation error: 'metric' is a required property" diff --git a/tests/test_tools.py b/tests/test_tools.py index 84156e8..d8d5554 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -5,6 +5,42 @@ base_route = "/tools" +def test_allowed_files(client): + route = f"{base_route}/allowed_files" + response = client.post(route, json={"key": None}) + assert response.status_code == 200 + extensions = response.json["extensions"] + assert type(extensions) is list + for extension in extensions: + assert type(extension) is str + + +def test_allowed_objects(client): + route = f"{base_route}/allowed_objects" + + def get_full_data(): + return { + "filename": "corbi.og_brep", + "key": None, + } + + # Normal test with filename 'corbi.og_brep' + response = client.post(route, json=get_full_data()) + assert response.status_code == 200 + allowed_objects = response.json["allowed_objects"] + assert type(allowed_objects) is list + for allowed_object in allowed_objects: + assert type(allowed_object) is str + + for key, value in get_full_data().items(): + json = get_full_data() + json.pop(key) + response = client.post(route, json=json) + assert response.status_code == 400 + error_description = response.json["description"] + assert error_description == f"Validation error: '{key}' is a required property" + + def test_upload_file(client): response = client.put( f"{base_route}/upload_file", @@ -12,3 +48,62 @@ def test_upload_file(client): ) assert response.status_code == 201 + + +def test_missing_files(client): + route = f"{base_route}/missing_files" + + def get_full_data(): + return { + "input_geode_object": "BRep", + "filename": "corbi.og_brep", + } + + json = get_full_data() + response = client.post( + route, + json=json, + ) + + assert response.status_code == 200 + has_missing_files = response.json["has_missing_files"] + mandatory_files = response.json["mandatory_files"] + additional_files = response.json["additional_files"] + assert type(has_missing_files) is bool + assert type(mandatory_files) is list + assert type(additional_files) is list + + for key, value in get_full_data().items(): + json = get_full_data() + json.pop(key) + response = client.post(route, json=json) + assert response.status_code == 400 + error_description = response.json["description"] + assert error_description == f"Validation error: '{key}' is a required property" + + +def test_geode_objects_and_output_extensions(client): + route = f"{base_route}/geode_objects_and_output_extensions" + + def get_full_data(): + return {"input_geode_object": "BRep"} + + response = client.post(route, json=get_full_data()) + + assert response.status_code == 200 + geode_objects_and_output_extensions = response.json[ + "geode_objects_and_output_extensions" + ] + assert type(geode_objects_and_output_extensions) is list + for geode_object_and_output_extensions in geode_objects_and_output_extensions: + assert type(geode_object_and_output_extensions) is dict + assert type(geode_object_and_output_extensions["geode_object"]) is str + assert type(geode_object_and_output_extensions["output_extensions"]) is list + + # Test without input_geode_object + response = client.post(route, json={}) + assert response.status_code == 400 + error_message = response.json["description"] + assert ( + error_message == "Validation error: 'input_geode_object' is a required property" + ) diff --git a/tests/test_validity_checker.py b/tests/test_validity_checker.py index 350ea6d..41a2099 100644 --- a/tests/test_validity_checker.py +++ b/tests/test_validity_checker.py @@ -14,42 +14,6 @@ def test_versions(client): assert type(version) is dict -def test_allowed_files(client): - response = client.get(f"{base_route}/allowed_files") - assert response.status_code == 200 - extensions = response.json["extensions"] - assert type(extensions) is list - for extension in extensions: - assert type(extension) is str - - -def test_allowed_objects(client): - # Normal test with filename 'corbi.og_brep' - response = client.post( - f"{base_route}/allowed_objects", json={"filename": "corbi.og_brep"} - ) - assert response.status_code == 200 - allowed_objects = response.json["allowed_objects"] - assert type(allowed_objects) is list - for geode_object in allowed_objects: - assert type(geode_object) is str - - # Test with stupid filename - response = client.post( - f"{base_route}/allowed_objects", json={"filename": "toto.tutu"} - ) - assert response.status_code == 200 - allowed_objects = response.json["allowed_objects"] - assert type(allowed_objects) is list - assert not allowed_objects - - # Test without filename - response = client.post(f"{base_route}/allowed_objects", json={}) - assert response.status_code == 400 - error_description = response.json["description"] - assert error_description == "Validation error: 'filename' is a required property" - - def test_test_names(client): ObjectArray = [ "BRep", @@ -77,7 +41,7 @@ def test_test_names(client): # Normal test with all objects response = client.post( f"{base_route}/tests_names", - json={"geode_object": geode_object}, + json={"input_geode_object": geode_object}, ) assert response.status_code == 200 model_checks = response.json["model_checks"] From 170ca135f1f2bc1b653363a092f18a53bbff9e36 Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Tue, 5 Dec 2023 10:14:32 +0100 Subject: [PATCH 02/17] feat(schemas): filename becomes array --- blueprints/tools_allowed_objects.json | 11 ++++++++--- .../tools_geode_objects_and_output_extensions.json | 10 +++++++++- blueprints/tools_missing_files.json | 11 ++++++++--- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/blueprints/tools_allowed_objects.json b/blueprints/tools_allowed_objects.json index 51f6a12..f49d197 100644 --- a/blueprints/tools_allowed_objects.json +++ b/blueprints/tools_allowed_objects.json @@ -4,13 +4,18 @@ "methods": ["POST"], "type": "object", "properties": { - "filename": { - "type": "string" + "filenames": { + "type": "array", + "items": { + "type": "string" + }, + "uniqueItems": true, + "minItems": 1 }, "key": { "type": ["string", "null"] } }, - "required": ["filename", "key"], + "required": ["filenames", "key"], "additionalProperties": false } diff --git a/blueprints/tools_geode_objects_and_output_extensions.json b/blueprints/tools_geode_objects_and_output_extensions.json index 3408985..a29beac 100644 --- a/blueprints/tools_geode_objects_and_output_extensions.json +++ b/blueprints/tools_geode_objects_and_output_extensions.json @@ -6,8 +6,16 @@ "properties": { "input_geode_object": { "type": "string" + }, + "filenames": { + "type": "array", + "items": { + "type": "string" + }, + "uniqueItems": true, + "minItems": 1 } }, - "required": ["input_geode_object"], + "required": ["input_geode_object", "filenames"], "additionalProperties": false } diff --git a/blueprints/tools_missing_files.json b/blueprints/tools_missing_files.json index 7a6b3ab..9a4421b 100644 --- a/blueprints/tools_missing_files.json +++ b/blueprints/tools_missing_files.json @@ -7,10 +7,15 @@ "input_geode_object": { "type": "string" }, - "filename": { - "type": "string" + "filenames": { + "type": "array", + "items": { + "type": "string" + }, + "uniqueItems": true, + "minItems": 1 } }, - "required": ["input_geode_object", "filename"], + "required": ["input_geode_object", "filenames"], "additionalProperties": false } From 809ac8905f784961f1eb2bbcf322071547762d05 Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Tue, 5 Dec 2023 10:14:44 +0100 Subject: [PATCH 03/17] update deps --- requirements.txt | 93 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 68 insertions(+), 25 deletions(-) diff --git a/requirements.txt b/requirements.txt index 98f74e4..0783c2c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,66 +2,94 @@ # This file is autogenerated by pip-compile with Python 3.9 # by the following command: # -# pip-compile --resolver=backtracking requirements.in +# pip-compile --pre --resolver=backtracking requirements.in # asgiref==3.7.2 - # via flask + # via + # flask + # opengeodeweb-back +attrs==23.1.0 + # via + # jsonschema + # opengeodeweb-back + # referencing blinker==1.7.0 - # via flask + # via + # flask + # opengeodeweb-back click==8.1.7 - # via flask + # via + # flask + # opengeodeweb-back colorama==0.4.6 - # via click + # via + # click + # opengeodeweb-back flask[async]==3.0.0 # via # -r requirements.in # flask-cors + # opengeodeweb-back flask-cors==4.0.0 # via -r requirements.in -geode-background==7.4.4 +geode-background==7.4.6 # via # geode-explicit # geode-implicit # geode-simplex -geode-common==29.0.1 +geode-common==30.0.1 # via # -r requirements.in # geode-background # geode-explicit # geode-implicit + # geode-numerics # geode-simplex # geode-viewables # opengeodeweb-back -geode-conversion==5.1.3 +geode-conversion==5.1.5 # via # geode-explicit # geode-implicit -geode-explicit==4.3.5 +geode-explicit==4.3.7 # via # -r requirements.in # geode-implicit -geode-implicit==2.4.2 +geode-implicit==2.5.1 # via -r requirements.in -geode-numerics==4.1.0 +geode-numerics==4.2.1 # via # -r requirements.in # geode-implicit # geode-simplex -geode-simplex==6.2.4 +geode-simplex==6.2.6 # via -r requirements.in -geode-viewables==2.1.3 +geode-viewables==2.1.5 # via opengeodeweb-back -importlib-metadata==6.8.0 - # via flask +importlib-metadata==7.0.0 + # via + # flask + # opengeodeweb-back itsdangerous==2.1.2 - # via flask + # via + # flask + # opengeodeweb-back jinja2==3.1.2 - # via flask + # via + # flask + # opengeodeweb-back +jsonschema==4.20.0 + # via opengeodeweb-back +jsonschema-specifications==2023.11.2 + # via + # jsonschema + # opengeodeweb-back markupsafe==2.1.3 # via # jinja2 + # opengeodeweb-back # werkzeug -opengeode-core==14.9.3 +opengeode-core==14.10.1 # via # -r requirements.in # geode-background @@ -77,7 +105,7 @@ opengeode-core==14.9.3 # opengeode-inspector # opengeode-io # opengeodeweb-back -opengeode-geosciences==7.2.1 +opengeode-geosciences==7.3.1 # via # -r requirements.in # geode-explicit @@ -86,20 +114,20 @@ opengeode-geosciences==7.2.1 # opengeode-geosciencesio # opengeode-inspector # opengeodeweb-back -opengeode-geosciencesio==4.5.1 +opengeode-geosciencesio==4.5.3 # via # -r requirements.in # geode-explicit # geode-implicit # opengeode-inspector # opengeodeweb-back -opengeode-inspector==4.0.0 +opengeode-inspector==4.0.2 # via # -r requirements.in # geode-explicit # geode-implicit # opengeodeweb-back -opengeode-io==6.2.1 +opengeode-io==6.2.3 # via # -r requirements.in # geode-explicit @@ -107,15 +135,30 @@ opengeode-io==6.2.1 # geode-viewables # opengeode-inspector # opengeodeweb-back -opengeodeweb-back==2.1.0 +opengeodeweb-back==3.0.0rc4 # via -r requirements.in python-dotenv==1.0.0 # via -r requirements.in +referencing==0.31.1 + # via + # jsonschema + # jsonschema-specifications + # opengeodeweb-back +rpds-py==0.13.2 + # via + # jsonschema + # opengeodeweb-back + # referencing typing-extensions==4.8.0 - # via asgiref + # via + # asgiref + # opengeodeweb-back werkzeug==3.0.1 # via # -r requirements.in # flask + # opengeodeweb-back zipp==3.17.0 - # via importlib-metadata + # via + # importlib-metadata + # opengeodeweb-back From 700c9133bf687a23bbc7593a3e439a8c38464d14 Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Tue, 5 Dec 2023 10:14:57 +0100 Subject: [PATCH 04/17] deactivate workflows --- blueprints/blueprint_workflows.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/blueprints/blueprint_workflows.py b/blueprints/blueprint_workflows.py index 1421f3a..9bb3250 100644 --- a/blueprints/blueprint_workflows.py +++ b/blueprints/blueprint_workflows.py @@ -6,7 +6,7 @@ import flask_cors from opengeodeweb_back import geode_functions, geode_objects -import blueprints.workflows.blueprint_implicit as bp_implicit +# import blueprints.workflows.blueprint_implicit as bp_implicit import blueprints.workflows.blueprint_simplex as bp_simplex import blueprints.workflows.blueprint_explicit as bp_explicit @@ -31,9 +31,9 @@ def teardown_request(exception): ) -workflows_routes.register_blueprint( - bp_implicit.implicit_routes, url_prefix="/implicit", name="implicit_blueprint" -) +# workflows_routes.register_blueprint( +# bp_implicit.implicit_routes, url_prefix="/implicit", name="implicit_blueprint" +# ) workflows_routes.register_blueprint( bp_simplex.simplex_routes, url_prefix="/simplex", name="simplex_blueprint" ) From 77e5357be8c3b06454acf13955f9e0ab4fbc614a Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Tue, 5 Dec 2023 10:16:46 +0100 Subject: [PATCH 05/17] feat(tools_routes): refactor routes BREAKING CHANGE: routes now can handle multiple files, filename becomes filenames --- blueprints/blueprint_tools.py | 96 ++++++++++++++++++++++++++--------- 1 file changed, 72 insertions(+), 24 deletions(-) diff --git a/blueprints/blueprint_tools.py b/blueprints/blueprint_tools.py index 2cd7024..200808b 100644 --- a/blueprints/blueprint_tools.py +++ b/blueprints/blueprint_tools.py @@ -99,10 +99,16 @@ def upload_file(): ) def allowed_objects(): geode_functions.validate_request(flask.request, tools_allowed_objects_json) - file_extension = os.path.splitext(flask.request.json["filename"])[1][1:] - allowed_objects = geode_functions.list_geode_objects( - file_extension, flask.request.json["key"] - ) + filenames = flask.request.json["filenames"] + for index, filename in enumerate(filenames): + file_extension = os.path.splitext(filename)[1][1:] + filename_allowed_objects = geode_functions.list_geode_objects( + file_extension, flask.request.json["key"] + ) + if index == 0: + allowed_objects = filename_allowed_objects + else: + allowed_objects = list(set(allowed_objects) & set(filename_allowed_objects)) return flask.make_response({"allowed_objects": allowed_objects}, 200) @@ -119,21 +125,28 @@ def missing_files(): UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"] geode_functions.validate_request(flask.request, tools_missing_files_json) - missing_files = geode_functions.missing_files( - flask.request.json["input_geode_object"], - os.path.join(UPLOAD_FOLDER, flask.request.json["filename"]), - ) - has_missing_files = missing_files.has_missing_files() - mandatory_files = missing_files.mandatory_files - additional_files = missing_files.additional_files - + filenames = flask.request.json["filenames"] + has_missing_files = False mandatory_files_list = [] - for mandatory_file in mandatory_files: - mandatory_files_list.append(os.path.basename(mandatory_file)) - additional_files_list = [] - for additional_file in additional_files: - additional_files_list.append(os.path.basename(additional_file)) + + for index, filename in enumerate(filenames): + file_missing_files = geode_functions.missing_files( + flask.request.json["input_geode_object"], + os.path.join(UPLOAD_FOLDER, filename), + ) + file_has_missing_files = file_missing_files.has_missing_files() + file_mandatory_files = file_missing_files.mandatory_files + file_additional_files = file_missing_files.additional_files + + if file_has_missing_files: + has_missing_files = True + + for mandatory_file in file_mandatory_files: + mandatory_files_list.append(os.path.basename(mandatory_file)) + + for additional_file in file_additional_files: + additional_files_list.append(os.path.basename(additional_file)) return flask.make_response( { @@ -154,18 +167,53 @@ def missing_files(): methods=tools_geode_objects_and_output_extensions_json["methods"], ) def geode_objects_and_output_extensions(): + UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"] + geode_functions.validate_request( flask.request, tools_geode_objects_and_output_extensions_json ) - geode_objects_output_extensions = geode_functions.geode_objects_output_extensions( - flask.request.json["input_geode_object"] - ) - geode_objects_and_output_extensions = ( - geode_functions.geode_objects_output_extensions( - flask.request.json["input_geode_object"] + + filenames = flask.request.json["filenames"] + input_geode_object = flask.request.json["input_geode_object"] + geode_objects_and_output_extensions = [] + + print(f"{ flask.request.json=}") + for index, filename in enumerate(filenames): + data = geode_functions.load( + input_geode_object, os.path.join(UPLOAD_FOLDER, filename) + ) + file_geode_objects_and_output_extensions = ( + geode_functions.geode_objects_output_extensions(input_geode_object, data) ) - ) + if index == 0: + geode_objects_and_output_extensions = ( + file_geode_objects_and_output_extensions + ) + else: + for item in file_geode_objects_and_output_extensions: + geode_object = item["geode_object"] + output_extensions = item["output_extensions"] + + for output_extension in output_extensions: + if not output_extension.is_saveable: + geode_objects_and_output_extensions[geode_object][ + output_extension + ]["is_saveable"] = False + geode_object_and_output_extensions = { + "geode_object": geode_object, + "output_extension": output_extension, + } + + geode_objects_and_output_extensions.append( + geode_object_and_output_extensions + ) + geode_objects_and_output_extensions = list( + set(geode_objects_and_output_extensions) + & set(file_geode_objects_and_output_extensions) + ) + + print(geode_objects_and_output_extensions) return flask.make_response( {"geode_objects_and_output_extensions": geode_objects_and_output_extensions}, 200, From 5eec5a9d2928805746491292dc4a12fe433e71e9 Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Tue, 5 Dec 2023 17:19:08 +0100 Subject: [PATCH 06/17] save --- blueprints/blueprint_tools.py | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/blueprints/blueprint_tools.py b/blueprints/blueprint_tools.py index 200808b..b9b9072 100644 --- a/blueprints/blueprint_tools.py +++ b/blueprints/blueprint_tools.py @@ -175,7 +175,7 @@ def geode_objects_and_output_extensions(): filenames = flask.request.json["filenames"] input_geode_object = flask.request.json["input_geode_object"] - geode_objects_and_output_extensions = [] + geode_objects_and_output_extensions = {} print(f"{ flask.request.json=}") for index, filename in enumerate(filenames): @@ -185,33 +185,19 @@ def geode_objects_and_output_extensions(): file_geode_objects_and_output_extensions = ( geode_functions.geode_objects_output_extensions(input_geode_object, data) ) + print(f"{file_geode_objects_and_output_extensions=}") if index == 0: geode_objects_and_output_extensions = ( file_geode_objects_and_output_extensions ) else: - for item in file_geode_objects_and_output_extensions: - geode_object = item["geode_object"] - output_extensions = item["output_extensions"] - - for output_extension in output_extensions: + for geode_object, value in file_geode_objects_and_output_extensions: + for output_extension in value: if not output_extension.is_saveable: geode_objects_and_output_extensions[geode_object][ output_extension ]["is_saveable"] = False - geode_object_and_output_extensions = { - "geode_object": geode_object, - "output_extension": output_extension, - } - - geode_objects_and_output_extensions.append( - geode_object_and_output_extensions - ) - geode_objects_and_output_extensions = list( - set(geode_objects_and_output_extensions) - & set(file_geode_objects_and_output_extensions) - ) print(geode_objects_and_output_extensions) return flask.make_response( From 99806d07b35926a8432c07e68a483a4bf787bbbe Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Wed, 6 Dec 2023 15:54:49 +0100 Subject: [PATCH 07/17] update requirements --- requirements.txt | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/requirements.txt b/requirements.txt index 0783c2c..e53552f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ # This file is autogenerated by pip-compile with Python 3.9 # by the following command: # -# pip-compile --pre --resolver=backtracking requirements.in +# pip-compile --pre requirements.in # asgiref==3.7.2 # via @@ -32,12 +32,12 @@ flask[async]==3.0.0 # opengeodeweb-back flask-cors==4.0.0 # via -r requirements.in -geode-background==7.4.6 +geode-background==7.4.7 # via # geode-explicit # geode-implicit # geode-simplex -geode-common==30.0.1 +geode-common==30.0.3 # via # -r requirements.in # geode-background @@ -47,24 +47,24 @@ geode-common==30.0.1 # geode-simplex # geode-viewables # opengeodeweb-back -geode-conversion==5.1.5 +geode-conversion==5.1.6 # via # geode-explicit # geode-implicit -geode-explicit==4.3.7 +geode-explicit==4.3.8 # via # -r requirements.in # geode-implicit -geode-implicit==2.5.1 +geode-implicit==2.5.3 # via -r requirements.in -geode-numerics==4.2.1 +geode-numerics==4.2.2 # via # -r requirements.in # geode-implicit # geode-simplex -geode-simplex==6.2.6 +geode-simplex==6.2.7 # via -r requirements.in -geode-viewables==2.1.5 +geode-viewables==2.1.7 # via opengeodeweb-back importlib-metadata==7.0.0 # via @@ -89,7 +89,7 @@ markupsafe==2.1.3 # jinja2 # opengeodeweb-back # werkzeug -opengeode-core==14.10.1 +opengeode-core==14.10.2 # via # -r requirements.in # geode-background @@ -105,7 +105,7 @@ opengeode-core==14.10.1 # opengeode-inspector # opengeode-io # opengeodeweb-back -opengeode-geosciences==7.3.1 +opengeode-geosciences==7.3.2 # via # -r requirements.in # geode-explicit @@ -114,20 +114,20 @@ opengeode-geosciences==7.3.1 # opengeode-geosciencesio # opengeode-inspector # opengeodeweb-back -opengeode-geosciencesio==4.5.3 +opengeode-geosciencesio==4.5.4 # via # -r requirements.in # geode-explicit # geode-implicit # opengeode-inspector # opengeodeweb-back -opengeode-inspector==4.0.2 +opengeode-inspector==4.0.3 # via # -r requirements.in # geode-explicit # geode-implicit # opengeodeweb-back -opengeode-io==6.2.3 +opengeode-io==6.2.4 # via # -r requirements.in # geode-explicit @@ -135,7 +135,7 @@ opengeode-io==6.2.3 # geode-viewables # opengeode-inspector # opengeodeweb-back -opengeodeweb-back==3.0.0rc4 +opengeodeweb-back==3.0.0rc5 # via -r requirements.in python-dotenv==1.0.0 # via -r requirements.in From b2b4097bb98c24701e9741eb059821b86152354f Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Wed, 6 Dec 2023 15:57:25 +0100 Subject: [PATCH 08/17] move geographic_coordinate_systems to tools --- blueprints/blueprint_tools.py | 39 ++++++++++++++----- blueprints/tools/blueprint_crs_converter.py | 42 +-------------------- 2 files changed, 32 insertions(+), 49 deletions(-) diff --git a/blueprints/blueprint_tools.py b/blueprints/blueprint_tools.py index b9b9072..be7464e 100644 --- a/blueprints/blueprint_tools.py +++ b/blueprints/blueprint_tools.py @@ -84,7 +84,6 @@ def upload_file(): for file in files: filename = werkzeug.utils.secure_filename(os.path.basename(file.filename)) - print(f"{filename=}") file.save(os.path.join(UPLOAD_FOLDER, filename)) return flask.make_response({"message": "File uploaded"}, 201) @@ -158,6 +157,33 @@ def missing_files(): ) +with open("blueprints/tools_geographic_coordinate_systems.json", "r") as file: + tools_geographic_coordinate_systems_json = json.load(file) + + +@tools_routes.route( + tools_geographic_coordinate_systems_json["route"], + methods=tools_geographic_coordinate_systems_json["methods"], +) +def geographic_coordinate_systems(): + geode_functions.validate_request( + flask.request, tools_geographic_coordinate_systems_json + ) + infos = geode_functions.geographic_coordinate_systems( + flask.request.json["input_geode_object"] + ) + crs_list = [] + + for info in infos: + crs = {} + crs["name"] = info.name + crs["code"] = info.code + crs["authority"] = info.authority + crs_list.append(crs) + + return flask.make_response({"crs_list": crs_list}, 200) + + with open("blueprints/tools_geode_objects_and_output_extensions.json", "r") as file: tools_geode_objects_and_output_extensions_json = json.load(file) @@ -168,16 +194,13 @@ def missing_files(): ) def geode_objects_and_output_extensions(): UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"] - geode_functions.validate_request( flask.request, tools_geode_objects_and_output_extensions_json ) - filenames = flask.request.json["filenames"] input_geode_object = flask.request.json["input_geode_object"] geode_objects_and_output_extensions = {} - print(f"{ flask.request.json=}") for index, filename in enumerate(filenames): data = geode_functions.load( input_geode_object, os.path.join(UPLOAD_FOLDER, filename) @@ -185,21 +208,19 @@ def geode_objects_and_output_extensions(): file_geode_objects_and_output_extensions = ( geode_functions.geode_objects_output_extensions(input_geode_object, data) ) - print(f"{file_geode_objects_and_output_extensions=}") if index == 0: geode_objects_and_output_extensions = ( file_geode_objects_and_output_extensions ) else: - for geode_object, value in file_geode_objects_and_output_extensions: - for output_extension in value: - if not output_extension.is_saveable: + for geode_object, value in file_geode_objects_and_output_extensions.items(): + for output_extension, output_extension_value in value.items(): + if not output_extension_value["is_saveable"]: geode_objects_and_output_extensions[geode_object][ output_extension ]["is_saveable"] = False - print(geode_objects_and_output_extensions) return flask.make_response( {"geode_objects_and_output_extensions": geode_objects_and_output_extensions}, 200, diff --git a/blueprints/tools/blueprint_crs_converter.py b/blueprints/tools/blueprint_crs_converter.py index 14553f8..9eb1636 100644 --- a/blueprints/tools/blueprint_crs_converter.py +++ b/blueprints/tools/blueprint_crs_converter.py @@ -35,35 +35,6 @@ def crs_converter_versions(): ) -with open( - "blueprints/tools/crs_converter_geographic_coordinate_systems.json", "r" -) as file: - crs_converter_geographic_coordinate_systems_json = json.load(file) - - -@crs_converter_routes.route( - crs_converter_geographic_coordinate_systems_json["route"], - methods=crs_converter_geographic_coordinate_systems_json["methods"], -) -def crs_converter_geographic_coordinate_systems(): - geode_functions.validate_request( - flask.request, crs_converter_geographic_coordinate_systems_json - ) - infos = geode_functions.geographic_coordinate_systems( - flask.request.json["input_geode_object"] - ) - crs_list = [] - - for info in infos: - crs = {} - crs["name"] = info.name - crs["code"] = info.code - crs["authority"] = info.authority - crs_list.append(crs) - - return flask.make_response({"crs_list": crs_list}, 200) - - with open("blueprints/tools/crs_converter_convert_file.json", "r") as file: crs_converter_convert_file_json = json.load(file) @@ -92,19 +63,10 @@ async def crs_converter_convert_file(): flask.request.json["input_geode_object"], data, flask.request.json["output_crs"] ) - geode_functions.save( + saved_files = geode_functions.save( flask.request.json["output_geode_object"], data, os.path.abspath(UPLOAD_FOLDER), new_file_name, ) - response = flask.send_from_directory( - directory=UPLOAD_FOLDER, - path=new_file_name, - as_attachment=True, - mimetype="application/octet-binary", - ) - response.headers["new-file-name"] = new_file_name - response.headers["Access-Control-Expose-Headers"] = "new-file-name" - - return response + return geode_functions.send_file(UPLOAD_FOLDER, saved_files, new_file_name) From 33c08184cf35f3b8feb20bab9a9ba164a9f32e4e Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Wed, 6 Dec 2023 15:58:17 +0100 Subject: [PATCH 09/17] update tests from api change --- tests/test_crs_converter.py | 20 ------------------ tests/test_tools.py | 41 +++++++++++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/tests/test_crs_converter.py b/tests/test_crs_converter.py index 3622bea..41988b9 100644 --- a/tests/test_crs_converter.py +++ b/tests/test_crs_converter.py @@ -14,26 +14,6 @@ def test_versions(client): assert type(version) is dict -def test_geographic_coordinate_systems(client): - route = f"{base_route}/geographic_coordinate_systems" - - # Normal test with geode_object 'BRep' - response = client.post(route, json={"input_geode_object": "BRep"}) - assert response.status_code == 200 - crs_list = response.json["crs_list"] - assert type(crs_list) is list - for crs in crs_list: - assert type(crs) is dict - - # Test without geode_object - response = client.post(route, json={}) - assert response.status_code == 400 - error_message = response.json["description"] - assert ( - error_message == "Validation error: 'input_geode_object' is a required property" - ) - - def test_convert_file(client): route = f"{base_route}/convert_file" diff --git a/tests/test_tools.py b/tests/test_tools.py index d8d5554..befd8d2 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -20,11 +20,10 @@ def test_allowed_objects(client): def get_full_data(): return { - "filename": "corbi.og_brep", + "filenames": ["corbi.og_brep"], "key": None, } - # Normal test with filename 'corbi.og_brep' response = client.post(route, json=get_full_data()) assert response.status_code == 200 allowed_objects = response.json["allowed_objects"] @@ -56,7 +55,7 @@ def test_missing_files(client): def get_full_data(): return { "input_geode_object": "BRep", - "filename": "corbi.og_brep", + "filenames": ["corbi.og_brep"], } json = get_full_data() @@ -82,11 +81,34 @@ def get_full_data(): assert error_description == f"Validation error: '{key}' is a required property" +def test_geographic_coordinate_systems(client): + route = f"{base_route}/geographic_coordinate_systems" + + # Normal test with geode_object 'BRep' + response = client.post(route, json={"input_geode_object": "BRep"}) + assert response.status_code == 200 + crs_list = response.json["crs_list"] + assert type(crs_list) is list + for crs in crs_list: + assert type(crs) is dict + + # Test without geode_object + response = client.post(route, json={}) + assert response.status_code == 400 + error_message = response.json["description"] + assert ( + error_message == "Validation error: 'input_geode_object' is a required property" + ) + + def test_geode_objects_and_output_extensions(client): route = f"{base_route}/geode_objects_and_output_extensions" def get_full_data(): - return {"input_geode_object": "BRep"} + return { + "input_geode_object": "BRep", + "filenames": ["corbi.og_brep"], + } response = client.post(route, json=get_full_data()) @@ -94,11 +116,12 @@ def get_full_data(): geode_objects_and_output_extensions = response.json[ "geode_objects_and_output_extensions" ] - assert type(geode_objects_and_output_extensions) is list - for geode_object_and_output_extensions in geode_objects_and_output_extensions: - assert type(geode_object_and_output_extensions) is dict - assert type(geode_object_and_output_extensions["geode_object"]) is str - assert type(geode_object_and_output_extensions["output_extensions"]) is list + assert type(geode_objects_and_output_extensions) is dict + for geode_object, values in geode_objects_and_output_extensions.items(): + assert type(values) is dict + for output_extension, value in values.items(): + assert type(value) is dict + assert type(value["is_saveable"]) is bool # Test without input_geode_object response = client.post(route, json={}) From 7af8210f80551f3ccaa83284dc28ddbc342e222c Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Wed, 6 Dec 2023 15:58:28 +0100 Subject: [PATCH 10/17] move geographic_coordinate_systems to tools --- ...te_systems.json => tools_geographic_coordinate_systems.json} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename blueprints/{tools/crs_converter_geographic_coordinate_systems.json => tools_geographic_coordinate_systems.json} (79%) diff --git a/blueprints/tools/crs_converter_geographic_coordinate_systems.json b/blueprints/tools_geographic_coordinate_systems.json similarity index 79% rename from blueprints/tools/crs_converter_geographic_coordinate_systems.json rename to blueprints/tools_geographic_coordinate_systems.json index 2a36022..7a0abfd 100644 --- a/blueprints/tools/crs_converter_geographic_coordinate_systems.json +++ b/blueprints/tools_geographic_coordinate_systems.json @@ -1,5 +1,5 @@ { - "$id": "/tools/crs_converter/geographic_coordinate_systems", + "$id": "/tools/geographic_coordinate_systems", "route": "/geographic_coordinate_systems", "methods": ["POST"], "type": "object", From f253da3614b8c36384364c9975f36ea7257b3f3a Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Wed, 6 Dec 2023 15:58:36 +0100 Subject: [PATCH 11/17] activate implicit --- blueprints/blueprint_workflows.py | 8 ++-- blueprints/tools/blueprint_file_converter.py | 42 +------------------- 2 files changed, 6 insertions(+), 44 deletions(-) diff --git a/blueprints/blueprint_workflows.py b/blueprints/blueprint_workflows.py index 9bb3250..1421f3a 100644 --- a/blueprints/blueprint_workflows.py +++ b/blueprints/blueprint_workflows.py @@ -6,7 +6,7 @@ import flask_cors from opengeodeweb_back import geode_functions, geode_objects -# import blueprints.workflows.blueprint_implicit as bp_implicit +import blueprints.workflows.blueprint_implicit as bp_implicit import blueprints.workflows.blueprint_simplex as bp_simplex import blueprints.workflows.blueprint_explicit as bp_explicit @@ -31,9 +31,9 @@ def teardown_request(exception): ) -# workflows_routes.register_blueprint( -# bp_implicit.implicit_routes, url_prefix="/implicit", name="implicit_blueprint" -# ) +workflows_routes.register_blueprint( + bp_implicit.implicit_routes, url_prefix="/implicit", name="implicit_blueprint" +) workflows_routes.register_blueprint( bp_simplex.simplex_routes, url_prefix="/simplex", name="simplex_blueprint" ) diff --git a/blueprints/tools/blueprint_file_converter.py b/blueprints/tools/blueprint_file_converter.py index 4973aa5..99cd45e 100644 --- a/blueprints/tools/blueprint_file_converter.py +++ b/blueprints/tools/blueprint_file_converter.py @@ -54,48 +54,10 @@ async def file_converter_convert_file(): strict_file_name = os.path.splitext(secure_filename)[0] new_file_name = strict_file_name + "." + flask.request.json["output_extension"] - sub_folder = f"{UPLOAD_FOLDER}/{strict_file_name}/" - if os.path.exists(sub_folder): - shutil.rmtree(sub_folder) - - geode_functions.save( + saved_files = geode_functions.save( flask.request.json["output_geode_object"], data, os.path.abspath(UPLOAD_FOLDER), new_file_name, ) - mimetype = "application/octet-binary" - - list_exceptions = ["triangle", "vtm"] - if flask.request.json["output_extension"] in list_exceptions: - if flask.request.json["output_extension"] == "triangle": - os.mkdir(sub_folder) - os.chdir(sub_folder) - generated_files = f"{UPLOAD_FOLDER}/{strict_file_name}" - shutil.move(generated_files + ".ele", sub_folder) - shutil.move(generated_files + ".neigh", sub_folder) - shutil.move(generated_files + ".node", sub_folder) - os.chdir("..") - elif flask.request.json["output_extension"] == "vtm": - generated_files = f"{UPLOAD_FOLDER}/{strict_file_name}" - shutil.move(generated_files + ".vtm", sub_folder) - new_file_name = strict_file_name + ".zip" - mimetype = "application/zip" - with zipfile.ZipFile(f"{UPLOAD_FOLDER}/{new_file_name}", "w") as zipObj: - for folder_name, sub_folders, file_names in os.walk(sub_folder): - for flask.request.json["filename"] in file_names: - file_path = os.path.join( - folder_name, flask.request.json["filename"] - ) - zipObj.write(file_path, os.path.basename(file_path)) - - response = flask.send_from_directory( - directory=UPLOAD_FOLDER, - path=new_file_name, - as_attachment=True, - mimetype=mimetype, - ) - response.headers["new-file-name"] = new_file_name - response.headers["Access-Control-Expose-Headers"] = "new-file-name" - - return response + return geode_functions.send_file(UPLOAD_FOLDER, saved_files, new_file_name) From 437c524b7eb71fe5b573d6e738764d01871e814b Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Wed, 6 Dec 2023 16:10:01 +0100 Subject: [PATCH 12/17] remove print --- blueprints/blueprint_tools.py | 1 - 1 file changed, 1 deletion(-) diff --git a/blueprints/blueprint_tools.py b/blueprints/blueprint_tools.py index 0673fa9..be7464e 100644 --- a/blueprints/blueprint_tools.py +++ b/blueprints/blueprint_tools.py @@ -84,7 +84,6 @@ def upload_file(): for file in files: filename = werkzeug.utils.secure_filename(os.path.basename(file.filename)) - print(f"{filename=}") file.save(os.path.join(UPLOAD_FOLDER, filename)) return flask.make_response({"message": "File uploaded"}, 201) From 44e7d5808c960782573dcbcafc2b95e7938a1737 Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Thu, 7 Dec 2023 17:24:54 +0100 Subject: [PATCH 13/17] revert schemas --- blueprints/tools_allowed_objects.json | 12 ++++-------- .../tools_geode_objects_and_output_extensions.json | 12 ++++-------- blueprints/tools_missing_files.json | 12 ++++-------- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/blueprints/tools_allowed_objects.json b/blueprints/tools_allowed_objects.json index f49d197..3514ba0 100644 --- a/blueprints/tools_allowed_objects.json +++ b/blueprints/tools_allowed_objects.json @@ -4,18 +4,14 @@ "methods": ["POST"], "type": "object", "properties": { - "filenames": { - "type": "array", - "items": { - "type": "string" - }, - "uniqueItems": true, - "minItems": 1 + "filename": { + "type": "string", + "not": { "type": "null" } }, "key": { "type": ["string", "null"] } }, - "required": ["filenames", "key"], + "required": ["filename", "key"], "additionalProperties": false } diff --git a/blueprints/tools_geode_objects_and_output_extensions.json b/blueprints/tools_geode_objects_and_output_extensions.json index a29beac..2ec7a26 100644 --- a/blueprints/tools_geode_objects_and_output_extensions.json +++ b/blueprints/tools_geode_objects_and_output_extensions.json @@ -7,15 +7,11 @@ "input_geode_object": { "type": "string" }, - "filenames": { - "type": "array", - "items": { - "type": "string" - }, - "uniqueItems": true, - "minItems": 1 + "filename": { + "type": "string", + "not": { "type": "null" } } }, - "required": ["input_geode_object", "filenames"], + "required": ["input_geode_object", "filename"], "additionalProperties": false } diff --git a/blueprints/tools_missing_files.json b/blueprints/tools_missing_files.json index 9a4421b..bc1d57e 100644 --- a/blueprints/tools_missing_files.json +++ b/blueprints/tools_missing_files.json @@ -7,15 +7,11 @@ "input_geode_object": { "type": "string" }, - "filenames": { - "type": "array", - "items": { - "type": "string" - }, - "uniqueItems": true, - "minItems": 1 + "filename": { + "type": "string", + "not": { "type": "null" } } }, - "required": ["input_geode_object", "filenames"], + "required": ["input_geode_object", "filename"], "additionalProperties": false } From 5b68344a0f0e156876b45fbb05c5187c5732a498 Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Thu, 7 Dec 2023 17:25:15 +0100 Subject: [PATCH 14/17] tools blueprint mono file --- blueprints/blueprint_tools.py | 61 +++++++++++++---------------------- 1 file changed, 22 insertions(+), 39 deletions(-) diff --git a/blueprints/blueprint_tools.py b/blueprints/blueprint_tools.py index be7464e..745b8fd 100644 --- a/blueprints/blueprint_tools.py +++ b/blueprints/blueprint_tools.py @@ -13,7 +13,7 @@ import blueprints.tools.blueprint_crs_converter as bp_crs_converter -tools_routes = flask.Blueprint("crs_converter_routes", __name__) +tools_routes = flask.Blueprint("tools_routes", __name__) flask_cors.CORS(tools_routes) @@ -80,11 +80,9 @@ def upload_file(): UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"] if not os.path.exists(UPLOAD_FOLDER): os.mkdir(UPLOAD_FOLDER) - files = flask.request.files.getlist("content") - - for file in files: - filename = werkzeug.utils.secure_filename(os.path.basename(file.filename)) - file.save(os.path.join(UPLOAD_FOLDER, filename)) + file = flask.request.files["file"] + filename = werkzeug.utils.secure_filename(os.path.basename(file.filename)) + file.save(os.path.join(UPLOAD_FOLDER, filename)) return flask.make_response({"message": "File uploaded"}, 201) @@ -98,17 +96,11 @@ def upload_file(): ) def allowed_objects(): geode_functions.validate_request(flask.request, tools_allowed_objects_json) - filenames = flask.request.json["filenames"] - for index, filename in enumerate(filenames): - file_extension = os.path.splitext(filename)[1][1:] - filename_allowed_objects = geode_functions.list_geode_objects( - file_extension, flask.request.json["key"] - ) - if index == 0: - allowed_objects = filename_allowed_objects - else: - allowed_objects = list(set(allowed_objects) & set(filename_allowed_objects)) - + file_extension = os.path.splitext(flask.request.json["filename"])[1][1:] + allowed_objects = geode_functions.list_geode_objects( + file_extension, flask.request.json["key"] + ) + print(f"{allowed_objects=}") return flask.make_response({"allowed_objects": allowed_objects}, 200) @@ -124,34 +116,25 @@ def missing_files(): UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"] geode_functions.validate_request(flask.request, tools_missing_files_json) - filenames = flask.request.json["filenames"] - has_missing_files = False - mandatory_files_list = [] - additional_files_list = [] - - for index, filename in enumerate(filenames): - file_missing_files = geode_functions.missing_files( - flask.request.json["input_geode_object"], - os.path.join(UPLOAD_FOLDER, filename), - ) - file_has_missing_files = file_missing_files.has_missing_files() - file_mandatory_files = file_missing_files.mandatory_files - file_additional_files = file_missing_files.additional_files - - if file_has_missing_files: - has_missing_files = True + missing_files = geode_functions.missing_files( + flask.request.json["input_geode_object"], + os.path.join(UPLOAD_FOLDER, flask.request.json["filename"]), + ) + has_missing_files = missing_files.has_missing_files() - for mandatory_file in file_mandatory_files: - mandatory_files_list.append(os.path.basename(mandatory_file)) + mandatory_files = [] + for mandatory_file in missing_files.mandatory_files: + mandatory_files.append(os.path.basename(mandatory_file)) - for additional_file in file_additional_files: - additional_files_list.append(os.path.basename(additional_file)) + additional_files = [] + for additional_file in missing_files.additional_files: + additional_files.append(os.path.basename(additional_file)) return flask.make_response( { "has_missing_files": has_missing_files, - "mandatory_files": mandatory_files_list, - "additional_files": additional_files_list, + "mandatory_files": mandatory_files, + "additional_files": additional_files, }, 200, ) From 8537a3fe47db69d2bf310fd5c0f82627c0423224 Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Sat, 9 Dec 2023 00:22:07 +0100 Subject: [PATCH 15/17] mono file output_extensions --- blueprints/blueprint_tools.py | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/blueprints/blueprint_tools.py b/blueprints/blueprint_tools.py index 745b8fd..79ae895 100644 --- a/blueprints/blueprint_tools.py +++ b/blueprints/blueprint_tools.py @@ -180,29 +180,15 @@ def geode_objects_and_output_extensions(): geode_functions.validate_request( flask.request, tools_geode_objects_and_output_extensions_json ) - filenames = flask.request.json["filenames"] - input_geode_object = flask.request.json["input_geode_object"] - geode_objects_and_output_extensions = {} - - for index, filename in enumerate(filenames): - data = geode_functions.load( - input_geode_object, os.path.join(UPLOAD_FOLDER, filename) - ) - file_geode_objects_and_output_extensions = ( - geode_functions.geode_objects_output_extensions(input_geode_object, data) + data = geode_functions.load( + flask.request.json["input_geode_object"], + os.path.join(UPLOAD_FOLDER, flask.request.json["filename"]), + ) + geode_objects_and_output_extensions = ( + geode_functions.geode_objects_output_extensions( + flask.request.json["input_geode_object"], data ) - - if index == 0: - geode_objects_and_output_extensions = ( - file_geode_objects_and_output_extensions - ) - else: - for geode_object, value in file_geode_objects_and_output_extensions.items(): - for output_extension, output_extension_value in value.items(): - if not output_extension_value["is_saveable"]: - geode_objects_and_output_extensions[geode_object][ - output_extension - ]["is_saveable"] = False + ) return flask.make_response( {"geode_objects_and_output_extensions": geode_objects_and_output_extensions}, From a7e0a683701b47271f42dc4b611c8830c255f954 Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Mon, 11 Dec 2023 15:14:47 +0100 Subject: [PATCH 16/17] remove prints --- blueprints/blueprint_tools.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/blueprints/blueprint_tools.py b/blueprints/blueprint_tools.py index 79ae895..cec97e1 100644 --- a/blueprints/blueprint_tools.py +++ b/blueprints/blueprint_tools.py @@ -100,7 +100,6 @@ def allowed_objects(): allowed_objects = geode_functions.list_geode_objects( file_extension, flask.request.json["key"] ) - print(f"{allowed_objects=}") return flask.make_response({"allowed_objects": allowed_objects}, 200) @@ -189,7 +188,6 @@ def geode_objects_and_output_extensions(): flask.request.json["input_geode_object"], data ) ) - return flask.make_response( {"geode_objects_and_output_extensions": geode_objects_and_output_extensions}, 200, From 189e3d343fc3219837821b6c5b51606a145c5570 Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Tue, 12 Dec 2023 15:51:19 +0100 Subject: [PATCH 17/17] update tests and requirements --- requirements.txt | 5 ++--- tests/test_crs_converter.py | 2 +- tests/test_file_converter.py | 2 +- tests/test_tools.py | 8 ++++---- tests/test_validity_checker.py | 2 +- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/requirements.txt b/requirements.txt index bae2e3b..8dd2ae8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ # This file is autogenerated by pip-compile with Python 3.9 # by the following command: # -# pip-compile --pre requirements.in +# pip-compile requirements.in # asgiref==3.7.2 # via @@ -135,7 +135,7 @@ opengeode-io==6.2.4 # geode-viewables # opengeode-inspector # opengeodeweb-back -opengeodeweb-back==3.0.0rc5 +opengeodeweb-back==3.0.0rc6 # via -r requirements.in python-dotenv==1.0.0 # via -r requirements.in @@ -162,4 +162,3 @@ zipp==3.17.0 # via # importlib-metadata # opengeodeweb-back - diff --git a/tests/test_crs_converter.py b/tests/test_crs_converter.py index 41988b9..c80d4a8 100644 --- a/tests/test_crs_converter.py +++ b/tests/test_crs_converter.py @@ -20,7 +20,7 @@ def test_convert_file(client): filename = "corbi.og_brep" response = client.put( "tools/upload_file", - data={"content": FileStorage(open(f"./tests/{filename}", "rb"))}, + data={"file": FileStorage(open(f"./tests/{filename}", "rb"))}, ) assert response.status_code == 201 diff --git a/tests/test_file_converter.py b/tests/test_file_converter.py index b5c4c45..01474d8 100644 --- a/tests/test_file_converter.py +++ b/tests/test_file_converter.py @@ -20,7 +20,7 @@ def test_convert_file(client): filename = "corbi.og_brep" response = client.put( "tools/upload_file", - data={"content": FileStorage(open(f"./tests/{filename}", "rb"))}, + data={"file": FileStorage(open(f"./tests/{filename}", "rb"))}, ) assert response.status_code == 201 diff --git a/tests/test_tools.py b/tests/test_tools.py index befd8d2..7d0a1dc 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -20,7 +20,7 @@ def test_allowed_objects(client): def get_full_data(): return { - "filenames": ["corbi.og_brep"], + "filename": "corbi.og_brep", "key": None, } @@ -43,7 +43,7 @@ def get_full_data(): def test_upload_file(client): response = client.put( f"{base_route}/upload_file", - data={"content": FileStorage(open("./tests/corbi.og_brep", "rb"))}, + data={"file": FileStorage(open("./tests/corbi.og_brep", "rb"))}, ) assert response.status_code == 201 @@ -55,7 +55,7 @@ def test_missing_files(client): def get_full_data(): return { "input_geode_object": "BRep", - "filenames": ["corbi.og_brep"], + "filename": "corbi.og_brep", } json = get_full_data() @@ -107,7 +107,7 @@ def test_geode_objects_and_output_extensions(client): def get_full_data(): return { "input_geode_object": "BRep", - "filenames": ["corbi.og_brep"], + "filename": "corbi.og_brep", } response = client.post(route, json=get_full_data()) diff --git a/tests/test_validity_checker.py b/tests/test_validity_checker.py index 41a2099..391a5c5 100644 --- a/tests/test_validity_checker.py +++ b/tests/test_validity_checker.py @@ -80,7 +80,7 @@ def test_inspect_file(client): response = client.put( "tools/upload_file", - data={"content": FileStorage(open(f"./tests/{filename}", "rb"))}, + data={"file": FileStorage(open(f"./tests/{filename}", "rb"))}, ) assert response.status_code == 201