Skip to content

Commit c53d028

Browse files
fix(Models): single route for models mesh_components
BREAKING CHANGE: deletes vtm_component_indices route
1 parent 60dea88 commit c53d028

7 files changed

Lines changed: 55 additions & 141 deletions

File tree

opengeodeweb_back_schemas.json

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,6 @@
3333
}
3434
},
3535
"models": {
36-
"vtm_component_indices": {
37-
"$id": "opengeodeweb_back/models/vtm_component_indices",
38-
"route": "/vtm_component_indices",
39-
"methods": [
40-
"POST"
41-
],
42-
"type": "object",
43-
"properties": {
44-
"id": {
45-
"type": "string",
46-
"minLength": 1
47-
}
48-
},
49-
"required": [
50-
"id"
51-
],
52-
"additionalProperties": false
53-
},
5436
"mesh_components": {
5537
"$id": "opengeodeweb_back/models/mesh_components",
5638
"route": "/mesh_components",

src/opengeodeweb_back/routes/models/blueprint_models.py

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@
1010
routes = flask.Blueprint("models", __name__, url_prefix="/models")
1111
schemas_dict = get_schemas_dict(os.path.join(os.path.dirname(__file__), "schemas"))
1212

13-
1413
@routes.route(
15-
schemas_dict["vtm_component_indices"]["route"],
16-
methods=schemas_dict["vtm_component_indices"]["methods"],
14+
schemas_dict["mesh_components"]["route"],
15+
methods=schemas_dict["mesh_components"]["methods"],
1716
)
18-
def uuid_to_flat_index() -> flask.Response:
17+
def mesh_components() -> flask.Response:
1918
json_data = utils_functions.validate_request(
20-
flask.request, schemas_dict["vtm_component_indices"]
19+
flask.request, schemas_dict["mesh_components"]
2120
)
22-
params = schemas.VtmComponentIndices.from_dict(json_data)
21+
params = schemas.MeshComponents.from_dict(json_data)
22+
model = geode_functions.load_geode_object(params.id)
23+
if not isinstance(model, GeodeModel):
24+
flask.abort(400, f"{params.id} is not a GeodeModel")
25+
26+
2327
vtm_file_path = geode_functions.data_file_path(params.id, "viewable.vtm")
2428
tree = ET.parse(vtm_file_path)
2529
root = tree.find("vtkMultiBlockDataSet")
@@ -32,24 +36,22 @@ def uuid_to_flat_index() -> flask.Response:
3236
if "uuid" in elem.attrib and elem.tag == "DataSet":
3337
uuid_to_flat_index[elem.attrib["uuid"]] = current_index
3438
current_index += 1
35-
return flask.make_response({"uuid_to_flat_index": uuid_to_flat_index}, 200)
36-
39+
model_mesh_components = model.mesh_components()
40+
mesh_components = []
41+
for mesh_component, ids in model_mesh_components.items():
42+
component_type = mesh_component.get()
43+
for id in ids:
44+
geode_id = id.string()
45+
component_name = geode_id
46+
viewer_id = uuid_to_flat_index[geode_id]
47+
48+
mesh_component_object = {
49+
"id": params.id,
50+
"viewer_id": viewer_id,
51+
"geode_id": geode_id,
52+
"name": component_name,
53+
"type": component_type
54+
}
55+
mesh_components.append(mesh_component_object)
3756

38-
@routes.route(
39-
schemas_dict["mesh_components"]["route"],
40-
methods=schemas_dict["mesh_components"]["methods"],
41-
)
42-
def extract_uuids_endpoint() -> flask.Response:
43-
json_data = utils_functions.validate_request(
44-
flask.request, schemas_dict["mesh_components"]
45-
)
46-
params = schemas.MeshComponents.from_dict(json_data)
47-
model = geode_functions.load_geode_object(params.id)
48-
if not isinstance(model, GeodeModel):
49-
flask.abort(400, f"{params.id} is not a GeodeModel")
50-
mesh_components = model.mesh_components()
51-
uuid_dict = {}
52-
for mesh_component, ids in mesh_components.items():
53-
component_name = mesh_component.get()
54-
uuid_dict[component_name] = [id.string() for id in ids]
55-
return flask.make_response({"uuid_dict": uuid_dict}, 200)
57+
return flask.make_response({"mesh_components": mesh_components}, 200)
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
from .vtm_component_indices import *
21
from .mesh_components import *

src/opengeodeweb_back/routes/models/schemas/vtm_component_indices.json

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/opengeodeweb_back/routes/models/schemas/vtm_component_indices.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/test_models_routes.py

Lines changed: 21 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -11,51 +11,36 @@
1111
from opengeodeweb_back import geode_functions
1212
from opengeodeweb_back.geode_objects.geode_brep import GeodeBRep
1313

14-
base_dir = os.path.abspath(os.path.dirname(__file__))
15-
data_dir = os.path.join(base_dir, "data")
16-
1714

18-
def test_model_mesh_components(client: FlaskClient, test_id: str) -> None:
19-
route = "/opengeodeweb_back/models/vtm_component_indices"
20-
21-
with client.application.app_context():
22-
data_path = geode_functions.data_file_path(test_id, "viewable.vtm")
23-
os.makedirs(os.path.dirname(data_path), exist_ok=True)
24-
shutil.copy(os.path.join(data_dir, "cube.vtm"), data_path)
25-
26-
response = client.post(route, json={"id": test_id})
27-
assert response.status_code == 200
15+
from .test_routes import test_save_viewable_file
2816

29-
uuid_dict = response.get_json()["uuid_to_flat_index"]
30-
assert isinstance(uuid_dict, dict)
17+
base_dir = os.path.abspath(os.path.dirname(__file__))
18+
data_dir = os.path.join(base_dir, "data")
3119

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

21+
def test_mesh_components(client: FlaskClient) -> None:
22+
geode_object_type = "BRep"
23+
filename = "cube.og_brep"
24+
response = test_save_viewable_file(client, geode_object_type, filename)
3825

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

43-
with client.application.app_context():
44-
data = Data.create(
45-
geode_object=GeodeBRep.geode_object_type(),
46-
viewer_object=GeodeBRep.viewer_type(),
47-
input_file=brep_filename,
48-
)
49-
data.native_file = brep_filename
50-
session = get_session()
51-
if session:
52-
session.commit()
5329

54-
response = client.post(route, json={"id": data.id})
55-
assert response.status_code == 200
56-
assert "uuid_dict" in response.get_json()
57-
uuid_dict = response.get_json()["uuid_dict"]
58-
assert isinstance(uuid_dict, dict)
30+
response = client.post(route, json={"id": response.get_json()["id"]})
31+
assert response.status_code == 200
32+
assert "mesh_components" in response.get_json()
33+
mesh_components = response.get_json()["mesh_components"]
34+
assert isinstance(mesh_components, list)
35+
assert len(mesh_components) > 0
36+
for mesh_component in mesh_components:
37+
assert isinstance(mesh_component, object)
38+
assert isinstance(mesh_component["id"], str)
39+
assert isinstance(mesh_component["geode_id"], str)
40+
assert isinstance(mesh_component["viewer_id"], int)
41+
assert isinstance(mesh_component["name"], str)
42+
assert isinstance(mesh_component["type"], str)
43+
5944

6045

6146
def test_export_project_route(client: FlaskClient, tmp_path: Path) -> None:
@@ -177,34 +162,6 @@ def test_import_project_route(client: FlaskClient, tmp_path: Path) -> None:
177162

178163
client.application.config["DATA_FOLDER_PATH"] = original_data_folder
179164

180-
181-
def test_save_viewable_workflow_from_file(client: FlaskClient) -> None:
182-
file = os.path.join(data_dir, "cube.og_brep")
183-
upload_resp = client.put(
184-
"/opengeodeweb_back/upload_file",
185-
data={"file": FileStorage(open(file, "rb"))},
186-
)
187-
assert upload_resp.status_code == 201
188-
189-
route = "/opengeodeweb_back/save_viewable_file"
190-
payload = {"geode_object_type": "BRep", "filename": "cube.og_brep"}
191-
192-
response = client.post(route, json=payload)
193-
assert response.status_code == 200
194-
195-
data_id = response.get_json()["id"]
196-
assert isinstance(data_id, str) and len(data_id) > 0
197-
assert response.get_json()["viewable_file"].endswith(".vtm")
198-
199-
comp_resp = client.post(
200-
"/opengeodeweb_back/models/vtm_component_indices", json={"id": data_id}
201-
)
202-
assert comp_resp.status_code == 200
203-
204-
refreshed = Data.get(data_id)
205-
assert refreshed is not None
206-
207-
208165
def test_save_viewable_workflow_from_object(client: FlaskClient) -> None:
209166
route = "/opengeodeweb_back/create/point"
210167
point_data = {

tests/test_routes.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Third party imports
55
from werkzeug.datastructures import FileStorage
66
from flask.testing import FlaskClient
7+
from werkzeug.test import TestResponse
78

89
# Local application imports
910
from opengeodeweb_microservice.database.data import Data
@@ -160,14 +161,14 @@ def get_full_data() -> test_utils.JsonData:
160161
test_utils.test_route_wrong_params(client, route, get_full_data)
161162

162163

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

167168
def get_full_data() -> test_utils.JsonData:
168169
return {
169-
"geode_object_type": "BRep",
170-
"filename": "corbi.og_brep",
170+
"geode_object_type": geode_object_type,
171+
"filename": filename,
171172
}
172173

173174
# Normal test with filename 'corbi.og_brep'
@@ -187,7 +188,7 @@ def get_full_data() -> test_utils.JsonData:
187188

188189
# Test all params
189190
test_utils.test_route_wrong_params(client, route, get_full_data)
190-
191+
return response
191192

192193
def test_texture_coordinates(client: FlaskClient, test_id: str) -> None:
193194
with client.application.app_context():

0 commit comments

Comments
 (0)