Skip to content

Commit fb433b8

Browse files
feat(polyhedron attributes): new route and tests
1 parent d4c274c commit fb433b8

File tree

5 files changed

+125
-9
lines changed

5 files changed

+125
-9
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.pytest_cache
22
/data
3+
/build
4+
*.egg-info
35
dist
46
venv
57
output

src/opengeodeweb_back/routes/blueprint_routes.py

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ def save_viewable_file():
260260
DATA_FOLDER_PATH,
261261
generated_id + "." + native_extension,
262262
)
263+
os.remove(os.path.join(UPLOAD_FOLDER, secure_filename))
263264
object_type = geode_functions.get_object_type(
264265
flask.request.json["input_geode_object"]
265266
)
@@ -320,11 +321,10 @@ def create_point():
320321
methods=vertex_attribute_names_json["methods"],
321322
)
322323
def vertex_attribute_names():
323-
324-
UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"]
324+
DATA_FOLDER_PATH = flask.current_app.config["DATA_FOLDER_PATH"]
325325
utils_functions.validate_request(flask.request, vertex_attribute_names_json)
326326
file_absolute_path = os.path.join(
327-
UPLOAD_FOLDER, werkzeug.utils.secure_filename(flask.request.json["filename"])
327+
DATA_FOLDER_PATH, werkzeug.utils.secure_filename(flask.request.json["filename"])
328328
)
329329
data = geode_functions.load(
330330
flask.request.json["input_geode_object"], file_absolute_path
@@ -351,11 +351,10 @@ def vertex_attribute_names():
351351
methods=polygon_attribute_names_json["methods"],
352352
)
353353
def polygon_attribute_names():
354-
355-
UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"]
356-
utils_functions.validate_request(flask.request, vertex_attribute_names_json)
354+
DATA_FOLDER_PATH = flask.current_app.config["DATA_FOLDER_PATH"]
355+
utils_functions.validate_request(flask.request, polygon_attribute_names_json)
357356
file_absolute_path = os.path.join(
358-
UPLOAD_FOLDER, werkzeug.utils.secure_filename(flask.request.json["filename"])
357+
DATA_FOLDER_PATH, werkzeug.utils.secure_filename(flask.request.json["filename"])
359358
)
360359
data = geode_functions.load(
361360
flask.request.json["input_geode_object"], file_absolute_path
@@ -370,6 +369,35 @@ def polygon_attribute_names():
370369
)
371370

372371

372+
with open(
373+
os.path.join(schemas, "polyhedron_attribute_names.json"),
374+
"r",
375+
) as file:
376+
polyhedron_attribute_names_json = json.load(file)
377+
378+
@routes.route(
379+
polyhedron_attribute_names_json["route"],
380+
methods=polyhedron_attribute_names_json["methods"],
381+
)
382+
def polyhedron_attribute_names():
383+
DATA_FOLDER_PATH = flask.current_app.config["DATA_FOLDER_PATH"]
384+
utils_functions.validate_request(flask.request, vertex_attribute_names_json)
385+
file_absolute_path = os.path.join(
386+
DATA_FOLDER_PATH, werkzeug.utils.secure_filename(flask.request.json["filename"])
387+
)
388+
data = geode_functions.load(
389+
flask.request.json["input_geode_object"], file_absolute_path
390+
)
391+
polyhedron_attribute_names = data.polyhedron_attribute_manager().attribute_names()
392+
393+
return flask.make_response(
394+
{
395+
"polyhedron_attribute_names": polyhedron_attribute_names,
396+
},
397+
200,
398+
)
399+
400+
373401
with open(
374402
os.path.join(schemas, "ping.json"),
375403
"r",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"route": "/polyhedron_attribute_names",
3+
"methods": ["POST"],
4+
"type": "object",
5+
"properties": {
6+
"input_geode_object": {
7+
"type": "string"
8+
},
9+
"filename": {
10+
"type": "string"
11+
}
12+
},
13+
"required": ["input_geode_object", "filename"],
14+
"additionalProperties": false
15+
}

tests/polyhedron_attribute.vtu

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0"?>
2+
<VTKFile type="UnstructuredGrid" version="1.0" byte_order="LittleEndian" header_type="UInt32" compressor="vtkZLibDataCompressor">
3+
<UnstructuredGrid>
4+
<Piece NumberOfPoints="11" NumberOfCells="4">
5+
<PointData>
6+
<DataArray type="Float64" Name="toto_on_vertices" format="ascii" NumberOfComponents="1" RangeMin="1" RangeMax="11">1 2 3 4 5 6 7 8 9 10 11 </DataArray>
7+
<DataArray type="Float64" Name="points" format="ascii" NumberOfComponents="3" RangeMin="0" RangeMax="2">0 0 0 1 0 0 2 1 0 1 2 0 0 2 0 0 0 1 1 0 1 2 1 1 1 2 1 0 2 1 1 1 2 </DataArray>
8+
</PointData>
9+
<Points>
10+
<DataArray type="Float64" Name="Points" format="ascii" NumberOfComponents="3" RangeMin="0" RangeMax="2">0 0 0 1 0 0 2 1 0 1 2 0 0 2 0 0 0 1 1 0 1 2 1 1 1 2 1 0 2 1 1 1 2 </DataArray>
11+
</Points>
12+
<CellData>
13+
<DataArray type="Float64" Name="toto_on_polyhedra" format="ascii" NumberOfComponents="1" RangeMin="3" RangeMax="6">3 4 5 6 </DataArray>
14+
</CellData>
15+
<Cells>
16+
<DataArray type="Int64" Name="connectivity" format="ascii" RangeMin="0" RangeMax="10">0 1 3 4 5 6 8 9 1 2 3 6 7 8 5 6 8 9 10 6 7 8 10 </DataArray>
17+
<DataArray type="Int64" Name="offsets" format="ascii" RangeMin="0" RangeMax="11">8 14 19 23 </DataArray>
18+
<DataArray type="UInt8" Name="types" format="ascii" RangeMin="1" RangeMax="42">12 13 14 10 </DataArray>
19+
</Cells>
20+
</Piece>
21+
</UnstructuredGrid>
22+
</VTKFile>

tests/test_routes.py

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
# Third party imports
66
from werkzeug.datastructures import FileStorage
7+
from flask import app
78

89
# Local application imports
910
from src.opengeodeweb_back import test_utils
@@ -174,12 +175,19 @@ def test_vertex_attribute_names(client):
174175
)
175176
assert response.status_code == 201
176177

178+
response = client.post("/save_viewable_file", json={
179+
"input_geode_object": "PolygonalSurface3D",
180+
"filename": "vertex_attribute.vtp",
181+
})
182+
assert response.status_code == 200
183+
native_file_name = response.json["native_file_name"]
184+
177185
route = f"/vertex_attribute_names"
178186

179187
def get_full_data():
180188
return {
181189
"input_geode_object": "PolygonalSurface3D",
182-
"filename": "vertex_attribute.vtp",
190+
"filename": native_file_name,
183191
}
184192

185193
# Normal test with filename 'vertex_attribute.vtp'
@@ -200,12 +208,19 @@ def test_polygon_attribute_names(client):
200208
)
201209
assert response.status_code == 201
202210

211+
response = client.post("/save_viewable_file", json={
212+
"input_geode_object": "PolygonalSurface3D",
213+
"filename": "polygon_attribute.vtp",
214+
})
215+
assert response.status_code == 200
216+
native_file_name = response.json["native_file_name"]
217+
203218
route = f"/polygon_attribute_names"
204219

205220
def get_full_data():
206221
return {
207222
"input_geode_object": "PolygonalSurface3D",
208-
"filename": "polygon_attribute.vtp",
223+
"filename": native_file_name,
209224
}
210225

211226
# Normal test with filename 'vertex_attribute.vtp'
@@ -220,6 +235,40 @@ def get_full_data():
220235
test_utils.test_route_wrong_params(client, route, get_full_data)
221236

222237

238+
def test_polyhedron_attribute_names(client):
239+
response = client.put(
240+
f"/upload_file",
241+
data={"file": FileStorage(open("./tests/polyhedron_attribute.vtu", "rb"))},
242+
)
243+
assert response.status_code == 201
244+
245+
response = client.post("/save_viewable_file", json={
246+
"input_geode_object": "HybridSolid3D",
247+
"filename": "polyhedron_attribute.vtu",
248+
})
249+
assert response.status_code == 200
250+
native_file_name = response.json["native_file_name"]
251+
252+
route = f"/polyhedron_attribute_names"
253+
254+
def get_full_data():
255+
return {
256+
"input_geode_object": "HybridSolid3D",
257+
"filename": native_file_name,
258+
}
259+
260+
# Normal test with filename 'vertex_attribute.vtp'
261+
response = client.post(route, json=get_full_data())
262+
assert response.status_code == 200
263+
polygon_attribute_names = response.json["polyhedron_attribute_names"]
264+
assert type(polygon_attribute_names) is list
265+
for polygon_attribute_name in polygon_attribute_names:
266+
assert type(polygon_attribute_name) is str
267+
268+
# Test all params
269+
test_utils.test_route_wrong_params(client, route, get_full_data)
270+
271+
223272
def test_create_point(client):
224273
route = f"/create_point"
225274
get_full_data = lambda: {"x": 1, "y": 2, "z": 3}

0 commit comments

Comments
 (0)