From 4c81fd11896a2a3af113bfd1c4516fbeede74e75 Mon Sep 17 00:00:00 2001 From: Arnaud Botella Date: Tue, 4 Nov 2025 15:43:35 +0100 Subject: [PATCH 1/2] fix(Tests): better handle relative paths --- .../routes/blueprint_routes.py | 3 +- tests/conftest.py | 3 +- tests/test_create_routes.py | 2 +- tests/test_models_routes.py | 14 +++----- tests/test_routes.py | 32 +++++++++++-------- tests/test_utils_functions.py | 18 ++++++++--- 6 files changed, 40 insertions(+), 32 deletions(-) diff --git a/src/opengeodeweb_back/routes/blueprint_routes.py b/src/opengeodeweb_back/routes/blueprint_routes.py index 1f17f826..3338a70d 100644 --- a/src/opengeodeweb_back/routes/blueprint_routes.py +++ b/src/opengeodeweb_back/routes/blueprint_routes.py @@ -45,7 +45,8 @@ def upload_file() -> flask.Response: UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"] if not os.path.exists(UPLOAD_FOLDER): - os.mkdir(UPLOAD_FOLDER) + os.makedirs(UPLOAD_FOLDER, exist_ok=True) + file = flask.request.files["file"] filename = werkzeug.utils.secure_filename(os.path.basename(file.filename)) file.save(os.path.join(UPLOAD_FOLDER, filename)) diff --git a/tests/conftest.py b/tests/conftest.py index 3aeb777c..283d2188 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,9 +9,8 @@ import pytest # Local application imports -from src.opengeodeweb_back.app import app +from opengeodeweb_back.app import app -# from opengeodeweb_back import app_config from opengeodeweb_microservice.database.connection import init_database TEST_ID = "1" diff --git a/tests/test_create_routes.py b/tests/test_create_routes.py index ec6f6d8a..33aabf1d 100644 --- a/tests/test_create_routes.py +++ b/tests/test_create_routes.py @@ -8,7 +8,7 @@ from flask.testing import FlaskClient # Local application imports -from src.opengeodeweb_back import test_utils +from opengeodeweb_back import test_utils @pytest.fixture diff --git a/tests/test_models_routes.py b/tests/test_models_routes.py index e1f916b7..86c55687 100644 --- a/tests/test_models_routes.py +++ b/tests/test_models_routes.py @@ -6,6 +6,9 @@ from opengeodeweb_microservice.database.data import Data from opengeodeweb_microservice.database.connection import get_session +base_dir = os.path.abspath(os.path.dirname(__file__)) +data_dir = os.path.join(base_dir, "data") + def test_model_mesh_components(client, test_id): route = "/opengeodeweb_back/models/vtm_component_indices" @@ -13,7 +16,7 @@ def test_model_mesh_components(client, test_id): with client.application.app_context(): data_path = geode_functions.data_file_path(test_id, "viewable.vtm") os.makedirs(os.path.dirname(data_path), exist_ok=True) - shutil.copy("./tests/data/cube.vtm", data_path) + shutil.copy(os.path.join(data_dir, "cube.vtm"), data_path) response = client.post(route, json={"id": test_id}) assert response.status_code == 200 @@ -30,7 +33,7 @@ def test_model_mesh_components(client, test_id): def test_extract_brep_uuids(client, test_id): route = "/opengeodeweb_back/models/mesh_components" - brep_filename = "cube.og_brep" + brep_filename = os.path.join(data_dir, "cube.og_brep") with client.application.app_context(): data_entry = Data.create( @@ -43,13 +46,6 @@ def test_extract_brep_uuids(client, test_id): if session: session.commit() - src_path = os.path.join("tests", "data", brep_filename) - dest_path = os.path.join( - flask.current_app.config["DATA_FOLDER_PATH"], data_entry.id, brep_filename - ) - os.makedirs(os.path.dirname(dest_path), exist_ok=True) - shutil.copy2(src_path, dest_path) - response = client.post(route, json={"id": data_entry.id}) assert response.status_code == 200 assert "uuid_dict" in response.json diff --git a/tests/test_routes.py b/tests/test_routes.py index 8d347a15..bd8220e5 100644 --- a/tests/test_routes.py +++ b/tests/test_routes.py @@ -1,6 +1,5 @@ # Standard library imports import os -import shutil # Third party imports from werkzeug.datastructures import FileStorage @@ -10,6 +9,9 @@ from opengeodeweb_microservice.database.connection import get_session from opengeodeweb_back import geode_functions, test_utils +base_dir = os.path.abspath(os.path.dirname(__file__)) +data_dir = os.path.join(base_dir, "data") + def test_allowed_files(client): route = f"/opengeodeweb_back/allowed_files" @@ -48,9 +50,11 @@ def get_full_data(): def test_upload_file(client, filename="test.og_brep"): + file = os.path.join(data_dir, filename) + print(f"{file=}", flush=True) response = client.put( f"/opengeodeweb_back/upload_file", - data={"file": FileStorage(open(f"./tests/data/{filename}", "rb"))}, + data={"file": FileStorage(open(file, "rb"))}, ) assert response.status_code == 201 @@ -171,19 +175,19 @@ def get_full_data(): def test_texture_coordinates(client, test_id): with client.application.app_context(): + file = os.path.join(data_dir, "hat.vtp") data = Data.create( geode_object="PolygonalSurface3D", viewer_object=geode_functions.get_object_type("PolygonalSurface3D"), - input_file="hat.vtp", + input_file=file, ) - data.native_file_name = "hat.vtp" + data.native_file_name = file session = get_session() if session: session.commit() data_path = geode_functions.data_file_path(data.id, data.native_file_name) os.makedirs(os.path.dirname(data_path), exist_ok=True) - shutil.copy("./tests/data/hat.vtp", data_path) assert os.path.exists(data_path), f"File not found at {data_path}" response = client.post( "/opengeodeweb_back/texture_coordinates", json={"id": data.id} @@ -199,19 +203,19 @@ def test_vertex_attribute_names(client, test_id): route = f"/opengeodeweb_back/vertex_attribute_names" with client.application.app_context(): + file = os.path.join(data_dir, "test.vtp") data = Data.create( geode_object="PolygonalSurface3D", viewer_object=geode_functions.get_object_type("PolygonalSurface3D"), - input_file="test.vtp", + input_file=file, ) - data.native_file_name = "test.vtp" + data.native_file_name = file session = get_session() if session: session.commit() data_path = geode_functions.data_file_path(data.id, data.native_file_name) os.makedirs(os.path.dirname(data_path), exist_ok=True) - shutil.copy("./tests/data/test.vtp", data_path) assert os.path.exists(data_path), f"File not found at {data_path}" response = client.post(route, json={"id": data.id}) assert response.status_code == 200 @@ -225,19 +229,19 @@ def test_polygon_attribute_names(client, test_id): route = f"/opengeodeweb_back/polygon_attribute_names" with client.application.app_context(): + file = os.path.join(data_dir, "test.vtp") data = Data.create( geode_object="PolygonalSurface3D", viewer_object=geode_functions.get_object_type("PolygonalSurface3D"), - input_file="test.vtp", + input_file=file, ) - data.native_file_name = "test.vtp" + data.native_file_name = file session = get_session() if session: session.commit() data_path = geode_functions.data_file_path(data.id, data.native_file_name) os.makedirs(os.path.dirname(data_path), exist_ok=True) - shutil.copy("./tests/data/test.vtp", data_path) assert os.path.exists(data_path), f"File not found at {data_path}" response = client.post(route, json={"id": data.id}) assert response.status_code == 200 @@ -251,19 +255,19 @@ def test_polyhedron_attribute_names(client, test_id): route = f"/opengeodeweb_back/polyhedron_attribute_names" with client.application.app_context(): + file = os.path.join(data_dir, "test.vtu") data = Data.create( geode_object="PolyhedralSolid3D", viewer_object=geode_functions.get_object_type("PolyhedralSolid3D"), - input_file="test.vtu", + input_file=file, ) - data.native_file_name = "test.vtu" + data.native_file_name = file session = get_session() if session: session.commit() data_path = geode_functions.data_file_path(data.id, data.native_file_name) os.makedirs(os.path.dirname(data_path), exist_ok=True) - shutil.copy("./tests/data/test.vtu", data_path) assert os.path.exists(data_path), f"File not found at {data_path}" response = client.post(route, json={"id": data.id}) print(response.json) diff --git a/tests/test_utils_functions.py b/tests/test_utils_functions.py index 162af7bc..8d49d81b 100644 --- a/tests/test_utils_functions.py +++ b/tests/test_utils_functions.py @@ -12,6 +12,9 @@ from opengeodeweb_microservice.database.connection import get_session from opengeodeweb_back import geode_functions, utils_functions +base_dir = os.path.abspath(os.path.dirname(__file__)) +data_dir = os.path.join(base_dir, "data") + def test_increment_request_counter(app_context): assert flask.current_app.config.get("REQUEST_COUNTER") == 0 @@ -91,15 +94,16 @@ def test_create_data_folder_from_id(client): def test_save_all_viewables_and_return_info(client): app = client.application with app.app_context(): - base_dir = os.path.abspath(os.path.dirname(__file__)) - expected_db_path = os.path.join(base_dir, "data", "project.db") + expected_db_path = os.path.join(data_dir, "project.db") expected_uri = f"sqlite:///{expected_db_path}" assert app.config["SQLALCHEMY_DATABASE_URI"] == expected_uri assert os.path.exists(expected_db_path) geode_object = "BRep" - data = geode_functions.load(geode_object, "./tests/data/test.og_brep") + data = geode_functions.load( + geode_object, os.path.join(data_dir, "test.og_brep") + ) input_file = "test.og_brep" additional_files = ["additional_file.txt"] @@ -142,7 +146,9 @@ def test_save_all_viewables_commits_to_db(client): app = client.application with app.app_context(): geode_object = "BRep" - data = geode_functions.load(geode_object, "./tests/data/test.og_brep") + data = geode_functions.load( + geode_object, os.path.join(data_dir, "test.og_brep") + ) input_file = "test.og_brep" data_entry = Data.create( @@ -166,7 +172,9 @@ def test_generate_native_viewable_and_light_viewable_from_object(client): app = client.application with app.app_context(): geode_object = "BRep" - data = geode_functions.load(geode_object, "./tests/data/test.og_brep") + data = geode_functions.load( + geode_object, os.path.join(data_dir, "test.og_brep") + ) result = ( utils_functions.generate_native_viewable_and_light_viewable_from_object( From 9cb84a68a61a7fd332a8e06a52a5560924051057 Mon Sep 17 00:00:00 2001 From: BotellaA <3213882+BotellaA@users.noreply.github.com> Date: Tue, 4 Nov 2025 14:44:38 +0000 Subject: [PATCH 2/2] Apply prepare changes --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index b2bc3327..4e85944d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -60,4 +60,3 @@ werkzeug==3.1.2 # flask # flask-cors -opengeodeweb-microservice==1.*,>=1.0.6