Skip to content

Commit 279e8bf

Browse files
Merge pull request #116 from Geode-solutions/feat/polyhedron_attribute_names
feat(polyhedron attributes): new route and tests
2 parents 40dbd9c + cba9c66 commit 279e8bf

File tree

6 files changed

+136
-10
lines changed

6 files changed

+136
-10
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

app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Packages """
1+
"""Packages"""
22

33
import os
44

src/opengeodeweb_back/routes/blueprint_routes.py

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ def save_viewable_file():
256256
DATA_FOLDER_PATH,
257257
generated_id + "." + native_extension,
258258
)
259+
os.remove(os.path.join(UPLOAD_FOLDER, secure_filename))
259260
object_type = geode_functions.get_object_type(
260261
flask.request.json["input_geode_object"]
261262
)
@@ -316,11 +317,10 @@ def create_point():
316317
methods=vertex_attribute_names_json["methods"],
317318
)
318319
def vertex_attribute_names():
319-
320-
UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"]
320+
DATA_FOLDER_PATH = flask.current_app.config["DATA_FOLDER_PATH"]
321321
utils_functions.validate_request(flask.request, vertex_attribute_names_json)
322322
file_absolute_path = os.path.join(
323-
UPLOAD_FOLDER, werkzeug.utils.secure_filename(flask.request.json["filename"])
323+
DATA_FOLDER_PATH, werkzeug.utils.secure_filename(flask.request.json["filename"])
324324
)
325325
data = geode_functions.load(
326326
flask.request.json["input_geode_object"], file_absolute_path
@@ -347,11 +347,10 @@ def vertex_attribute_names():
347347
methods=polygon_attribute_names_json["methods"],
348348
)
349349
def polygon_attribute_names():
350-
351-
UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"]
352-
utils_functions.validate_request(flask.request, vertex_attribute_names_json)
350+
DATA_FOLDER_PATH = flask.current_app.config["DATA_FOLDER_PATH"]
351+
utils_functions.validate_request(flask.request, polygon_attribute_names_json)
353352
file_absolute_path = os.path.join(
354-
UPLOAD_FOLDER, werkzeug.utils.secure_filename(flask.request.json["filename"])
353+
DATA_FOLDER_PATH, werkzeug.utils.secure_filename(flask.request.json["filename"])
355354
)
356355
data = geode_functions.load(
357356
flask.request.json["input_geode_object"], file_absolute_path
@@ -366,6 +365,36 @@ def polygon_attribute_names():
366365
)
367366

368367

368+
with open(
369+
os.path.join(schemas, "polyhedron_attribute_names.json"),
370+
"r",
371+
) as file:
372+
polyhedron_attribute_names_json = json.load(file)
373+
374+
375+
@routes.route(
376+
polyhedron_attribute_names_json["route"],
377+
methods=polyhedron_attribute_names_json["methods"],
378+
)
379+
def polyhedron_attribute_names():
380+
DATA_FOLDER_PATH = flask.current_app.config["DATA_FOLDER_PATH"]
381+
utils_functions.validate_request(flask.request, vertex_attribute_names_json)
382+
file_absolute_path = os.path.join(
383+
DATA_FOLDER_PATH, werkzeug.utils.secure_filename(flask.request.json["filename"])
384+
)
385+
data = geode_functions.load(
386+
flask.request.json["input_geode_object"], file_absolute_path
387+
)
388+
polyhedron_attribute_names = data.polyhedron_attribute_manager().attribute_names()
389+
390+
return flask.make_response(
391+
{
392+
"polyhedron_attribute_names": polyhedron_attribute_names,
393+
},
394+
200,
395+
)
396+
397+
369398
with open(
370399
os.path.join(schemas, "ping.json"),
371400
"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: 60 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,22 @@ def test_vertex_attribute_names(client):
174175
)
175176
assert response.status_code == 201
176177

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

179190
def get_full_data():
180191
return {
181192
"input_geode_object": "PolygonalSurface3D",
182-
"filename": "vertex_attribute.vtp",
193+
"filename": native_file_name,
183194
}
184195

185196
# Normal test with filename 'vertex_attribute.vtp'
@@ -200,12 +211,22 @@ def test_polygon_attribute_names(client):
200211
)
201212
assert response.status_code == 201
202213

214+
response = client.post(
215+
"/save_viewable_file",
216+
json={
217+
"input_geode_object": "PolygonalSurface3D",
218+
"filename": "polygon_attribute.vtp",
219+
},
220+
)
221+
assert response.status_code == 200
222+
native_file_name = response.json["native_file_name"]
223+
203224
route = f"/polygon_attribute_names"
204225

205226
def get_full_data():
206227
return {
207228
"input_geode_object": "PolygonalSurface3D",
208-
"filename": "polygon_attribute.vtp",
229+
"filename": native_file_name,
209230
}
210231

211232
# Normal test with filename 'vertex_attribute.vtp'
@@ -220,6 +241,43 @@ def get_full_data():
220241
test_utils.test_route_wrong_params(client, route, get_full_data)
221242

222243

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

0 commit comments

Comments
 (0)