Skip to content

Commit 5ebb91d

Browse files
committed
test
1 parent 6544070 commit 5ebb91d

File tree

7 files changed

+39
-37
lines changed

7 files changed

+39
-37
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ __pycache__
99
.vscode
1010
uploads
1111
node_modules
12-
schemas.json
13-
tmp
12+
schemas.json

src/opengeodeweb_back/app_config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ class DevConfig(Config):
3131
MINUTES_BEFORE_TIMEOUT = "1"
3232
SECONDS_BETWEEN_SHUTDOWNS = "10"
3333
DATA_FOLDER_PATH = "./data/"
34+
35+
TEST_ID = "1"

src/opengeodeweb_back/geode_functions.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import opengeode_geosciences as og_gs
66
import opengeode as og
77
import werkzeug
8+
import flask
89

910
# Local application imports
1011
from .geode_objects import geode_objects_dict
@@ -38,23 +39,25 @@ def is_loadable(geode_object: str, file_absolute_path: str):
3839
def load(geode_object: str, file_absolute_path: str):
3940
return geode_object_value(geode_object)["load"](file_absolute_path)
4041

41-
def load_from_request(geode_object: str, data_folder_path: str, request_json: dict):
42+
def load_data(geode_object: str, request_json: dict):
43+
data_folder_path = flask.current_app.config["DATA_FOLDER_PATH"]
4244
file_absolute_path = os.path.join(
4345
data_folder_path,
4446
request_json["id"],
4547
werkzeug.utils.secure_filename(request_json["filename"]),
4648
)
4749
return load(geode_object, file_absolute_path)
4850

49-
def build_data_path(data_folder_path, request_json, filename):
51+
def data_file_path(request_json, filename):
52+
data_folder_path = flask.current_app.config["DATA_FOLDER_PATH"] # Use the load_data function to get the data folder path
5053
return os.path.join(
5154
data_folder_path,
5255
request_json["id"],
5356
werkzeug.utils.secure_filename(filename),
5457
)
5558

56-
def build_upload_file_path(upload_folder, filename):
57-
secure_filename = werkzeug.utils.secure_filename(filename)
59+
def upload_file_path(upload_folder, filename):
60+
secure_filename = werkzeug.utils.secure_filename(filename) # filename must be grabbed from the data_file_path function
5861
return os.path.abspath(os.path.join(upload_folder, secure_filename)
5962
)
6063

src/opengeodeweb_back/routes/blueprint_routes.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def allowed_objects():
9999

100100
UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"]
101101
utils_functions.validate_request(flask.request, allowed_objects_json)
102-
file_absolute_path = geode_functions.build_upload_file_path(
102+
file_absolute_path = geode_functions.upload_file_path(
103103
UPLOAD_FOLDER, flask.request.json["filename"])
104104
allowed_objects = geode_functions.list_geode_objects(
105105
file_absolute_path, flask.request.json["supported_feature"]
@@ -124,7 +124,7 @@ def missing_files():
124124

125125
missing_files = geode_functions.missing_files(
126126
flask.request.json["input_geode_object"],
127-
geode_functions.build_upload_file_path(
127+
geode_functions.upload_file_path(
128128
UPLOAD_FOLDER, flask.request.json["filename"]),
129129
)
130130
has_missing_files = missing_files.has_missing_files()
@@ -217,7 +217,7 @@ def geode_objects_and_output_extensions():
217217
)
218218
data = geode_functions.load(
219219
flask.request.json["input_geode_object"],
220-
geode_functions.build_upload_file_path(
220+
geode_functions.upload_file_path(
221221
UPLOAD_FOLDER, flask.request.json["filename"]),
222222
)
223223
geode_objects_and_output_extensions = (
@@ -289,11 +289,9 @@ def create_point():
289289
methods=texture_coordinates_json["methods"],
290290
)
291291
def texture_coordinates():
292-
DATA_FOLDER_PATH = flask.current_app.config["DATA_FOLDER_PATH"]
293292
utils_functions.validate_request(flask.request, texture_coordinates_json)
294-
data = geode_functions.load_from_request(
293+
data = geode_functions.load_data(
295294
flask.request.json["input_geode_object"],
296-
DATA_FOLDER_PATH,
297295
flask.request.json,
298296
)
299297

@@ -314,11 +312,9 @@ def texture_coordinates():
314312
methods=vertex_attribute_names_json["methods"],
315313
)
316314
def vertex_attribute_names():
317-
DATA_FOLDER_PATH = flask.current_app.config["DATA_FOLDER_PATH"]
318315
utils_functions.validate_request(flask.request, vertex_attribute_names_json)
319-
data = geode_functions.load_from_request(
316+
data = geode_functions.load_data(
320317
flask.request.json["input_geode_object"],
321-
DATA_FOLDER_PATH,
322318
flask.request.json,
323319
)
324320

@@ -344,11 +340,9 @@ def vertex_attribute_names():
344340
methods=polygon_attribute_names_json["methods"],
345341
)
346342
def polygon_attribute_names():
347-
DATA_FOLDER_PATH = flask.current_app.config["DATA_FOLDER_PATH"]
348343
utils_functions.validate_request(flask.request, polygon_attribute_names_json)
349-
data = geode_functions.load_from_request(
344+
data = geode_functions.load_data(
350345
flask.request.json["input_geode_object"],
351-
DATA_FOLDER_PATH,
352346
flask.request.json,
353347
)
354348

@@ -374,11 +368,9 @@ def polygon_attribute_names():
374368
methods=polyhedron_attribute_names_json["methods"],
375369
)
376370
def polyhedron_attribute_names():
377-
DATA_FOLDER_PATH = flask.current_app.config["DATA_FOLDER_PATH"]
378371
utils_functions.validate_request(flask.request, vertex_attribute_names_json)
379-
data = geode_functions.load_from_request(
372+
data = geode_functions.load_data(
380373
flask.request.json["input_geode_object"],
381-
DATA_FOLDER_PATH,
382374
flask.request.json,
383375
)
384376

src/opengeodeweb_back/routes/models/blueprint_models.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
def uuid_to_flat_index():
2020
utils_functions.validate_request(flask.request, vtm_component_indices_json)
2121
try:
22-
vtm_file_path = geode_functions.build_data_path(
23-
flask.current_app.config["DATA_FOLDER_PATH"],
22+
vtm_file_path = geode_functions.data_file_path(
2423
flask.request.json,
2524
"viewable.vtm"
2625
)
@@ -30,14 +29,12 @@ def uuid_to_flat_index():
3029
root = tree.find("vtkMultiBlockDataSet")
3130
uuid_to_flat_index = {}
3231
current_index = 0
33-
3432
for elem in root.iter():
3533
if "uuid" in elem.attrib and elem.tag == "DataSet":
3634
uuid_to_flat_index[elem.attrib["uuid"]] = current_index
3735
current_index += 1
3836
return flask.make_response({"uuid_to_flat_index": uuid_to_flat_index}, 200)
3937

40-
4138
def extract_model_uuids(model):
4239
mesh_components = model.mesh_components()
4340
uuid_dict = {}
@@ -55,7 +52,7 @@ def extract_model_uuids(model):
5552
def extract_uuids_endpoint():
5653
utils_functions.validate_request(flask.request, mesh_components_json)
5754
try:
58-
model = geode_functions.load_from_request(
55+
model = geode_functions.load_data(
5956
flask.request.json["geode_object"],
6057
flask.current_app.config["DATA_FOLDER_PATH"],
6158
flask.request.json,

tests/conftest.py

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

@@ -8,12 +7,13 @@
87

98
# Local application imports
109
from app import app
10+
from src.opengeodeweb_back.app_config import TEST_ID
1111

1212

1313
@pytest.fixture(scope="session", autouse=True)
1414
def copy_data():
1515
shutil.rmtree("./data", ignore_errors=True)
16-
shutil.copytree("./tests/data/", "./data/1/", dirs_exist_ok=True)
16+
shutil.copytree("./tests/data/", "./data/{TEST_ID}/", dirs_exist_ok=True)
1717

1818

1919
@pytest.fixture

tests/test_models_routes.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import os
22
import shutil
3+
4+
from src.opengeodeweb_back import geode_functions
5+
36
def test_model_mesh_components(client, test_id):
47
route = "/models/vtm_component_indices"
58

6-
base_path = client.application.config["DATA_FOLDER_PATH"]
7-
data_path = os.path.join(base_path, test_id)
8-
os.makedirs(data_path, exist_ok=True)
9-
shutil.copy("./tests/data/cube.vtm", os.path.join(data_path, "viewable.vtm"))
9+
data_path = geode_functions.data_file_path(
10+
{"id": test_id},
11+
"viewable.vtm"
12+
)
13+
os.makedirs(os.path.dirname(data_path), exist_ok=True)
14+
shutil.copy("./tests/data/cube.vtm", data_path)
1015

1116
response = client.post(route, json={"id": test_id})
1217
assert response.status_code == 200
@@ -23,12 +28,16 @@ def test_model_mesh_components(client, test_id):
2328
def test_extract_brep_uuids(client, test_id):
2429
route = "/models/mesh_components"
2530

26-
base_path = client.application.config["DATA_FOLDER_PATH"]
27-
data_path = os.path.join(base_path, test_id)
28-
os.makedirs(data_path, exist_ok=True)
29-
shutil.copy("./tests/data/cube.og_brep", os.path.join(data_path, "cube.og_brep"))
31+
brep_filename = "cube.og_brep"
32+
json_data = {"id": test_id, "geode_object": "BRep", "filename": brep_filename}
33+
34+
data_path = geode_functions.data_file_path(
35+
json_data,
36+
brep_filename
37+
)
38+
os.makedirs(os.path.dirname(data_path), exist_ok=True)
39+
shutil.copy(f"./tests/data/{brep_filename}", data_path)
3040

31-
json_data = {"id": test_id, "geode_object": "BRep", "filename": "cube.og_brep"}
3241
response = client.post(route, json=json_data)
3342
assert response.status_code == 200
3443

0 commit comments

Comments
 (0)