Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions opengeodeweb_back_schemas.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,6 @@
}
},
"models": {
"vtm_component_indices": {
"$id": "opengeodeweb_back/models/vtm_component_indices",
"route": "/vtm_component_indices",
"methods": [
"POST"
],
"type": "object",
"properties": {
"id": {
"type": "string",
"minLength": 1
}
},
"required": [
"id"
],
"additionalProperties": false
},
"mesh_components": {
"$id": "opengeodeweb_back/models/mesh_components",
"route": "/mesh_components",
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,3 @@ werkzeug==3.1.2
# flask
# flask-cors

opengeodeweb-microservice==1.*,>=1.0.12
50 changes: 26 additions & 24 deletions src/opengeodeweb_back/routes/models/blueprint_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@


@routes.route(
schemas_dict["vtm_component_indices"]["route"],
methods=schemas_dict["vtm_component_indices"]["methods"],
schemas_dict["mesh_components"]["route"],
methods=schemas_dict["mesh_components"]["methods"],
)
def uuid_to_flat_index() -> flask.Response:
def mesh_components() -> flask.Response:
json_data = utils_functions.validate_request(
flask.request, schemas_dict["vtm_component_indices"]
flask.request, schemas_dict["mesh_components"]
)
params = schemas.VtmComponentIndices.from_dict(json_data)
params = schemas.MeshComponents.from_dict(json_data)
model = geode_functions.load_geode_object(params.id)
if not isinstance(model, GeodeModel):
flask.abort(400, f"{params.id} is not a GeodeModel")

vtm_file_path = geode_functions.data_file_path(params.id, "viewable.vtm")
tree = ET.parse(vtm_file_path)
root = tree.find("vtkMultiBlockDataSet")
Expand All @@ -32,24 +36,22 @@ def uuid_to_flat_index() -> flask.Response:
if "uuid" in elem.attrib and elem.tag == "DataSet":
uuid_to_flat_index[elem.attrib["uuid"]] = current_index
current_index += 1
return flask.make_response({"uuid_to_flat_index": uuid_to_flat_index}, 200)
model_mesh_components = model.mesh_components()
mesh_components = []
for mesh_component, ids in model_mesh_components.items():
component_type = mesh_component.get()
for id in ids:
geode_id = id.string()
component_name = geode_id
viewer_id = uuid_to_flat_index[geode_id]

mesh_component_object = {
"id": params.id,
"viewer_id": viewer_id,
"geode_id": geode_id,
"name": component_name,
"type": component_type,
}
mesh_components.append(mesh_component_object)

@routes.route(
schemas_dict["mesh_components"]["route"],
methods=schemas_dict["mesh_components"]["methods"],
)
def extract_uuids_endpoint() -> flask.Response:
json_data = utils_functions.validate_request(
flask.request, schemas_dict["mesh_components"]
)
params = schemas.MeshComponents.from_dict(json_data)
model = geode_functions.load_geode_object(params.id)
if not isinstance(model, GeodeModel):
flask.abort(400, f"{params.id} is not a GeodeModel")
mesh_components = model.mesh_components()
uuid_dict = {}
for mesh_component, ids in mesh_components.items():
component_name = mesh_component.get()
uuid_dict[component_name] = [id.string() for id in ids]
return flask.make_response({"uuid_dict": uuid_dict}, 200)
return flask.make_response({"mesh_components": mesh_components}, 200)
1 change: 0 additions & 1 deletion src/opengeodeweb_back/routes/models/schemas/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from .vtm_component_indices import *
from .mesh_components import *

This file was deleted.

This file was deleted.

84 changes: 20 additions & 64 deletions tests/test_models_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,34 @@
from opengeodeweb_back import geode_functions
from opengeodeweb_back.geode_objects.geode_brep import GeodeBRep

base_dir = os.path.abspath(os.path.dirname(__file__))
data_dir = os.path.join(base_dir, "data")


def test_model_mesh_components(client: FlaskClient, test_id: str) -> None:
route = "/opengeodeweb_back/models/vtm_component_indices"

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(os.path.join(data_dir, "cube.vtm"), data_path)

response = client.post(route, json={"id": test_id})
assert response.status_code == 200
from .test_routes import test_save_viewable_file

uuid_dict = response.get_json()["uuid_to_flat_index"]
assert isinstance(uuid_dict, dict)
base_dir = os.path.abspath(os.path.dirname(__file__))
data_dir = os.path.join(base_dir, "data")

indices = list(uuid_dict.values())
indices.sort()
assert all(indices[i] > indices[i - 1] for i in range(1, len(indices)))
for uuid in uuid_dict.keys():
assert isinstance(uuid, str)

def test_mesh_components(client: FlaskClient) -> None:
geode_object_type = "BRep"
filename = "cube.og_brep"
response = test_save_viewable_file(client, geode_object_type, filename)

def test_extract_brep_uuids(client: FlaskClient, test_id: str) -> None:
route = "/opengeodeweb_back/models/mesh_components"
brep_filename = os.path.join(data_dir, "cube.og_brep")

with client.application.app_context():
data = Data.create(
geode_object=GeodeBRep.geode_object_type(),
viewer_object=GeodeBRep.viewer_type(),
input_file=brep_filename,
)
data.native_file = brep_filename
session = get_session()
if session:
session.commit()

response = client.post(route, json={"id": data.id})
assert response.status_code == 200
assert "uuid_dict" in response.get_json()
uuid_dict = response.get_json()["uuid_dict"]
assert isinstance(uuid_dict, dict)
response = client.post(route, json={"id": response.get_json()["id"]})
assert response.status_code == 200
assert "mesh_components" in response.get_json()
mesh_components = response.get_json()["mesh_components"]
assert isinstance(mesh_components, list)
assert len(mesh_components) > 0
for mesh_component in mesh_components:
assert isinstance(mesh_component, object)
assert isinstance(mesh_component["id"], str)
assert isinstance(mesh_component["geode_id"], str)
assert isinstance(mesh_component["viewer_id"], int)
assert isinstance(mesh_component["name"], str)
assert isinstance(mesh_component["type"], str)


def test_export_project_route(client: FlaskClient, tmp_path: Path) -> None:
Expand Down Expand Up @@ -178,33 +161,6 @@ def test_import_project_route(client: FlaskClient, tmp_path: Path) -> None:
client.application.config["DATA_FOLDER_PATH"] = original_data_folder


def test_save_viewable_workflow_from_file(client: FlaskClient) -> None:
file = os.path.join(data_dir, "cube.og_brep")
upload_resp = client.put(
"/opengeodeweb_back/upload_file",
data={"file": FileStorage(open(file, "rb"))},
)
assert upload_resp.status_code == 201

route = "/opengeodeweb_back/save_viewable_file"
payload = {"geode_object_type": "BRep", "filename": "cube.og_brep"}

response = client.post(route, json=payload)
assert response.status_code == 200

data_id = response.get_json()["id"]
assert isinstance(data_id, str) and len(data_id) > 0
assert response.get_json()["viewable_file"].endswith(".vtm")

comp_resp = client.post(
"/opengeodeweb_back/models/vtm_component_indices", json={"id": data_id}
)
assert comp_resp.status_code == 200

refreshed = Data.get(data_id)
assert refreshed is not None


def test_save_viewable_workflow_from_object(client: FlaskClient) -> None:
route = "/opengeodeweb_back/create/point"
point_data = {
Expand Down
14 changes: 10 additions & 4 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Third party imports
from werkzeug.datastructures import FileStorage
from flask.testing import FlaskClient
from werkzeug.test import TestResponse

# Local application imports
from opengeodeweb_microservice.database.data import Data
Expand Down Expand Up @@ -160,14 +161,18 @@ def get_full_data() -> test_utils.JsonData:
test_utils.test_route_wrong_params(client, route, get_full_data)


def test_save_viewable_file(client: FlaskClient) -> None:
test_upload_file(client, filename="corbi.og_brep")
def test_save_viewable_file(
client: FlaskClient,
geode_object_type: str = "BRep",
filename: str = "corbi.og_brep",
) -> TestResponse:
test_upload_file(client, filename)
route = f"/opengeodeweb_back/save_viewable_file"

def get_full_data() -> test_utils.JsonData:
return {
"geode_object_type": "BRep",
"filename": "corbi.og_brep",
"geode_object_type": geode_object_type,
"filename": filename,
}

# Normal test with filename 'corbi.og_brep'
Expand All @@ -187,6 +192,7 @@ def get_full_data() -> test_utils.JsonData:

# Test all params
test_utils.test_route_wrong_params(client, route, get_full_data)
return response


def test_texture_coordinates(client: FlaskClient, test_id: str) -> None:
Expand Down