Skip to content

Commit e85cea6

Browse files
filename -> file
1 parent a3d23fa commit e85cea6

File tree

7 files changed

+55
-64
lines changed

7 files changed

+55
-64
lines changed

src/opengeodeweb_back/geode_functions.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
import os
33

44
# Third party imports
5-
import opengeode_geosciences as og_gs
6-
import opengeode as og
75
import werkzeug
86
import flask
9-
from typing import Any
107

118
# Local application imports
129
from .geode_objects import geode_objects
@@ -15,9 +12,7 @@
1512
geode_object_type,
1613
)
1714
from .geode_objects.geode_object import GeodeObject
18-
from . import utils_functions
1915
from opengeodeweb_microservice.database.data import Data
20-
from opengeodeweb_microservice.database.connection import get_session
2116

2217

2318
def data_file_path(data_id: str, filename: str | None = None) -> str:
@@ -37,7 +32,7 @@ def load_geode_object(data_id: str) -> GeodeObject:
3732
if not data:
3833
flask.abort(404, f"Data with id {data_id} not found")
3934

40-
file_absolute_path = data_file_path(data_id, data.native_filename)
35+
file_absolute_path = data_file_path(data_id, data.native_file)
4136
print("Loading file: ", file_absolute_path)
4237
print("File exists: ", os.path.exists(file_absolute_path))
4338
return geode_object_from_string(data.geode_object).load(file_absolute_path)

src/opengeodeweb_back/routes/blueprint_routes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def save_viewable_file() -> flask.Response:
237237
return flask.make_response(
238238
utils_functions.generate_native_viewable_and_light_viewable_from_file(
239239
geode_object_type=geode_object_type(params.geode_object_type),
240-
input_filename=params.filename,
240+
input_file=params.filename,
241241
),
242242
200,
243243
)
@@ -473,7 +473,7 @@ def import_project() -> flask.Response:
473473
with get_session() as session:
474474
for data in rows:
475475
data_path = geode_functions.data_file_path(data.id)
476-
viewable_name = data.viewable_filename
476+
viewable_name = data.viewable_file
477477
if viewable_name:
478478
vpath = geode_functions.data_file_path(data.id, viewable_name)
479479
if os.path.isfile(vpath):

src/opengeodeweb_back/utils_functions.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# Standard library imports
2-
import json
32
import os
43
import threading
54
import time
65
import zipfile
76
from collections.abc import Callable
8-
from concurrent.futures import ThreadPoolExecutor, Future
7+
from concurrent.futures import ThreadPoolExecutor
98

109
# Third party imports
1110
import flask
@@ -208,15 +207,15 @@ def save_all_viewables_and_return_info(
208207
)
209208
with open(light_path, "rb") as f:
210209
binary_light_viewable = f.read()
211-
data.native_filename = os.path.basename(native_files[0])
212-
data.viewable_filename = os.path.basename(viewable_path)
210+
data.native_file = os.path.basename(native_files[0])
211+
data.viewable_file = os.path.basename(viewable_path)
213212
data.light_viewable = os.path.basename(light_path)
214-
assert data.native_filename is not None
215-
assert data.viewable_filename is not None
213+
assert data.native_file is not None
214+
assert data.viewable_file is not None
216215
assert data.light_viewable is not None
217216
return {
218-
"native_filename": data.native_filename,
219-
"viewable_filename": data.viewable_filename,
217+
"native_file": data.native_file,
218+
"viewable_file": data.viewable_file,
220219
"id": data.id,
221220
"name": geode_object.identifier.name(),
222221
"viewer_type": data.viewer_object,
@@ -239,20 +238,20 @@ def generate_native_viewable_and_light_viewable_from_object(
239238

240239

241240
def generate_native_viewable_and_light_viewable_from_file(
242-
geode_object_type: GeodeObjectType, input_filename: str
241+
geode_object_type: GeodeObjectType, input_file: str
243242
) -> dict[str, str | list[str]]:
244243
generic_geode_object = geode_objects[geode_object_type]
245244
data = Data.create(
246245
geode_object=geode_object_type,
247246
viewer_object=generic_geode_object.viewer_type(),
248-
input_file=input_filename,
247+
input_file=input_file,
249248
)
250249

251250
data_path = create_data_folder_from_id(data.id)
252251

253-
full_input_filename = geode_functions.upload_file_path(input_filename)
252+
full_input_filename = geode_functions.upload_file_path(input_file)
254253
copied_full_path = os.path.join(
255-
data_path, werkzeug.utils.secure_filename(input_filename)
254+
data_path, werkzeug.utils.secure_filename(input_file)
256255
)
257256
shutil.copy2(full_input_filename, copied_full_path)
258257

tests/test_create_routes.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Standard library imports
2-
import os
32
import uuid
43

54
# Third party imports
@@ -51,10 +50,10 @@ def test_create_point(client: FlaskClient, point_data: test_utils.JsonData) -> N
5150

5251
# Verify response data
5352
response_data = response.get_json()
54-
assert "viewable_filename" in response_data
53+
assert "viewable_file" in response_data
5554
assert "id" in response_data
5655
assert "name" in response_data
57-
assert "native_filename" in response_data
56+
assert "native_file" in response_data
5857
assert "viewer_type" in response_data
5958
assert "geode_object_type" in response_data
6059

@@ -76,10 +75,10 @@ def test_create_aoi(client: FlaskClient, aoi_data: test_utils.JsonData) -> None:
7675

7776
# Verify response data
7877
response_data = response.get_json()
79-
assert "viewable_filename" in response_data
78+
assert "viewable_file" in response_data
8079
assert "id" in response_data
8180
assert "name" in response_data
82-
assert "native_filename" in response_data
81+
assert "native_file" in response_data
8382
assert "viewer_type" in response_data
8483
assert "geode_object_type" in response_data
8584

tests/test_models_routes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_extract_brep_uuids(client: FlaskClient, test_id: str) -> None:
4646
viewer_object=GeodeBRep.viewer_type(),
4747
input_file=brep_filename,
4848
)
49-
data.native_filename = brep_filename
49+
data.native_file = brep_filename
5050
session = get_session()
5151
if session:
5252
session.commit()
@@ -106,8 +106,8 @@ def test_import_project_route(client: FlaskClient, tmp_path: Path) -> None:
106106
temp_db = tmp_path / "temp_project.db"
107107
conn = sqlite3.connect(str(temp_db))
108108
conn.execute(
109-
"CREATE TABLE datas (id TEXT PRIMARY KEY, geode_object TEXT, viewer_object TEXT, native_filename TEXT, "
110-
"viewable_filename TEXT, light_viewable TEXT, input_file TEXT, additional_files TEXT)"
109+
"CREATE TABLE datas (id TEXT PRIMARY KEY, geode_object TEXT, viewer_object TEXT, native_file TEXT, "
110+
"viewable_file TEXT, light_viewable TEXT, input_file TEXT, additional_files TEXT)"
111111
)
112112
conn.commit()
113113
conn.close()
@@ -154,7 +154,7 @@ def test_save_viewable_workflow_from_file(client: FlaskClient) -> None:
154154

155155
data_id = response.get_json()["id"]
156156
assert isinstance(data_id, str) and len(data_id) > 0
157-
assert response.get_json()["viewable_filename"].endswith(".vtm")
157+
assert response.get_json()["viewable_file"].endswith(".vtm")
158158

159159
comp_resp = client.post(
160160
"/opengeodeweb_back/models/vtm_component_indices", json={"id": data_id}
@@ -184,4 +184,4 @@ def test_save_viewable_workflow_from_object(client: FlaskClient) -> None:
184184
data_id = response.get_json()["id"]
185185
assert isinstance(data_id, str) and len(data_id) > 0
186186
assert response.get_json()["geode_object_type"] == "EdgedCurve3D"
187-
assert response.get_json()["viewable_filename"].endswith(".vtp")
187+
assert response.get_json()["viewable_file"].endswith(".vtp")

tests/test_routes.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ def get_full_data() -> test_utils.JsonData:
173173
# Normal test with filename 'corbi.og_brep'
174174
response = client.post(route, json=get_full_data())
175175
assert response.status_code == 200
176-
native_filename = response.get_json()["native_filename"]
177-
assert type(native_filename) is str
178-
viewable_filename = response.get_json()["viewable_filename"]
179-
assert type(viewable_filename) is str
176+
native_file = response.get_json()["native_file"]
177+
assert type(native_file) is str
178+
viewable_file = response.get_json()["viewable_file"]
179+
assert type(viewable_file) is str
180180
id = response.get_json().get("id")
181181
assert type(id) is str
182182
object_type = response.get_json()["viewer_type"]
@@ -197,12 +197,12 @@ def test_texture_coordinates(client: FlaskClient, test_id: str) -> None:
197197
viewer_object=GeodePolygonalSurface3D.viewer_type(),
198198
input_file=file,
199199
)
200-
data.native_filename = file
200+
data.native_file = file
201201
session = get_session()
202202
if session:
203203
session.commit()
204204

205-
data_path = geode_functions.data_file_path(data.id, data.native_filename)
205+
data_path = geode_functions.data_file_path(data.id, data.native_file)
206206
os.makedirs(os.path.dirname(data_path), exist_ok=True)
207207
assert os.path.exists(data_path), f"File not found at {data_path}"
208208
response = client.post(
@@ -225,12 +225,12 @@ def test_vertex_attribute_names(client: FlaskClient, test_id: str) -> None:
225225
viewer_object=GeodePolygonalSurface3D.viewer_type(),
226226
input_file=file,
227227
)
228-
data.native_filename = file
228+
data.native_file = file
229229
session = get_session()
230230
if session:
231231
session.commit()
232232

233-
data_path = geode_functions.data_file_path(data.id, data.native_filename)
233+
data_path = geode_functions.data_file_path(data.id, data.native_file)
234234
os.makedirs(os.path.dirname(data_path), exist_ok=True)
235235
assert os.path.exists(data_path), f"File not found at {data_path}"
236236
response = client.post(route, json={"id": data.id})
@@ -251,12 +251,12 @@ def test_cell_attribute_names(client: FlaskClient, test_id: str) -> None:
251251
viewer_object=GeodeRegularGrid2D.viewer_type(),
252252
input_file=file,
253253
)
254-
data.native_filename = file
254+
data.native_file = file
255255
session = get_session()
256256
if session:
257257
session.commit()
258258

259-
data_path = geode_functions.data_file_path(data.id, data.native_filename)
259+
data_path = geode_functions.data_file_path(data.id, data.native_file)
260260
os.makedirs(os.path.dirname(data_path), exist_ok=True)
261261
assert os.path.exists(data_path), f"File not found at {data_path}"
262262
response = client.post(route, json={"id": data.id})
@@ -277,12 +277,12 @@ def test_polygon_attribute_names(client: FlaskClient, test_id: str) -> None:
277277
viewer_object=GeodePolygonalSurface3D.viewer_type(),
278278
input_file=file,
279279
)
280-
data.native_filename = file
280+
data.native_file = file
281281
session = get_session()
282282
if session:
283283
session.commit()
284284

285-
data_path = geode_functions.data_file_path(data.id, data.native_filename)
285+
data_path = geode_functions.data_file_path(data.id, data.native_file)
286286
os.makedirs(os.path.dirname(data_path), exist_ok=True)
287287
assert os.path.exists(data_path), f"File not found at {data_path}"
288288
response = client.post(route, json={"id": data.id})
@@ -303,12 +303,12 @@ def test_polyhedron_attribute_names(client: FlaskClient, test_id: str) -> None:
303303
viewer_object=GeodePolyhedralSolid3D.viewer_type(),
304304
input_file=file,
305305
)
306-
data.native_filename = file
306+
data.native_file = file
307307
session = get_session()
308308
if session:
309309
session.commit()
310310

311-
data_path = geode_functions.data_file_path(data.id, data.native_filename)
311+
data_path = geode_functions.data_file_path(data.id, data.native_file)
312312
os.makedirs(os.path.dirname(data_path), exist_ok=True)
313313
assert os.path.exists(data_path), f"File not found at {data_path}"
314314
response = client.post(route, json={"id": data.id})

tests/test_utils_functions.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@
99
import shutil
1010
import uuid
1111
import zipfile
12-
import io
1312
from pathlib import Path
1413

1514
# Local application imports
1615
from opengeodeweb_microservice.database.data import Data
17-
from opengeodeweb_microservice.database.connection import get_session
18-
from opengeodeweb_back import geode_functions, utils_functions
16+
from opengeodeweb_back import utils_functions
1917
from opengeodeweb_back.geode_objects.geode_brep import GeodeBRep
2018

2119
base_dir = os.path.abspath(os.path.dirname(__file__))
@@ -123,12 +121,12 @@ def test_save_all_viewables_and_return_info(client: FlaskClient) -> None:
123121
)
124122

125123
assert isinstance(result, dict)
126-
native_filename = result["native_filename"]
127-
assert isinstance(native_filename, str)
128-
assert native_filename.startswith("native.")
129-
viewable_filename = result["viewable_filename"]
130-
assert isinstance(viewable_filename, str)
131-
assert viewable_filename.endswith(".vtm")
124+
native_file = result["native_file"]
125+
assert isinstance(native_file, str)
126+
assert native_file.startswith("native.")
127+
viewable_file = result["viewable_file"]
128+
assert isinstance(viewable_file, str)
129+
assert viewable_file.endswith(".vtm")
132130
assert isinstance(result["id"], str)
133131
assert len(result["id"]) == 32
134132
assert re.match(r"[0-9a-f]{32}", result["id"])
@@ -139,8 +137,8 @@ def test_save_all_viewables_and_return_info(client: FlaskClient) -> None:
139137

140138
db_entry = Data.get(result["id"])
141139
assert db_entry is not None
142-
assert db_entry.native_filename == result["native_filename"]
143-
assert db_entry.viewable_filename == result["viewable_filename"]
140+
assert db_entry.native_file == result["native_file"]
141+
assert db_entry.viewable_file == result["viewable_file"]
144142
assert db_entry.geode_object == geode_object.geode_object_type()
145143
assert db_entry.input_file == input_file
146144
assert db_entry.additional_files == additional_files
@@ -169,7 +167,7 @@ def test_save_all_viewables_commits_to_db(client: FlaskClient) -> None:
169167
assert isinstance(data_id, str)
170168
db_entry_before = Data.get(data_id)
171169
assert db_entry_before is not None
172-
assert db_entry_before.native_filename == result["native_filename"]
170+
assert db_entry_before.native_file == result["native_file"]
173171

174172

175173
def test_generate_native_viewable_and_light_viewable_from_object(
@@ -186,10 +184,10 @@ def test_generate_native_viewable_and_light_viewable_from_object(
186184
)
187185

188186
assert isinstance(result, dict)
189-
assert isinstance(result["native_filename"], str)
190-
assert result["native_filename"].startswith("native.")
191-
assert isinstance(result["viewable_filename"], str)
192-
assert result["viewable_filename"].endswith(".vtm")
187+
assert isinstance(result["native_file"], str)
188+
assert result["native_file"].startswith("native.")
189+
assert isinstance(result["viewable_file"], str)
190+
assert result["viewable_file"].endswith(".vtm")
193191
assert isinstance(result["id"], str)
194192
assert re.match(r"[0-9a-f]{32}", result["id"])
195193
assert isinstance(result["viewer_type"], str)
@@ -207,10 +205,10 @@ def test_generate_native_viewable_and_light_viewable_from_file(
207205
)
208206

209207
assert isinstance(result, dict)
210-
assert isinstance(result["native_filename"], str)
211-
assert result["native_filename"].startswith("native.")
212-
assert isinstance(result["viewable_filename"], str)
213-
assert result["viewable_filename"].endswith(".vtm")
208+
assert isinstance(result["native_file"], str)
209+
assert result["native_file"].startswith("native.")
210+
assert isinstance(result["viewable_file"], str)
211+
assert result["viewable_file"].endswith(".vtm")
214212
assert isinstance(result["id"], str)
215213
assert re.match(r"[0-9a-f]{32}", result["id"])
216214
assert isinstance(result["viewer_type"], str)

0 commit comments

Comments
 (0)