Skip to content

Commit 5a81dd2

Browse files
committed
Refactored blueprints_routes and blueprint_models for improved organization and maintainability
1 parent 5612c04 commit 5a81dd2

File tree

5 files changed

+35
-47
lines changed

5 files changed

+35
-47
lines changed

src/opengeodeweb_back/app_config.py

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

src/opengeodeweb_back/geode_functions.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,6 @@ def load(geode_object: str, file_absolute_path: str):
4040
return geode_object_value(geode_object)["load"](file_absolute_path)
4141

4242

43-
def load_data(geode_object: str, request_json: dict):
44-
data_folder_path = flask.current_app.config["DATA_FOLDER_PATH"]
45-
file_absolute_path = os.path.join(
46-
data_folder_path,
47-
request_json["id"],
48-
werkzeug.utils.secure_filename(request_json["filename"]),
49-
)
50-
return load(geode_object, file_absolute_path)
51-
52-
5343
def data_file_path(request_json, filename):
5444
data_folder_path = flask.current_app.config["DATA_FOLDER_PATH"]
5545
return os.path.join(
@@ -59,10 +49,14 @@ def data_file_path(request_json, filename):
5949
)
6050

6151

62-
def upload_file_path(upload_folder, filename):
63-
secure_filename = werkzeug.utils.secure_filename(
64-
filename
65-
) # filename must be grabbed from the data_file_path function
52+
def load_data(geode_object: str, request_json: dict):
53+
file_absolute_path = data_file_path(request_json, request_json["filename"])
54+
return load(geode_object, file_absolute_path)
55+
56+
57+
def upload_file_path(filename):
58+
upload_folder = flask.current_app.config["UPLOAD_FOLDER"]
59+
secure_filename = werkzeug.utils.secure_filename(filename)
6660
return os.path.abspath(os.path.join(upload_folder, secure_filename))
6761

6862

src/opengeodeweb_back/routes/blueprint_routes.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,8 @@ def allowed_objects():
9797
if flask.request.method == "OPTIONS":
9898
return flask.make_response({}, 200)
9999

100-
UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"]
101100
utils_functions.validate_request(flask.request, allowed_objects_json)
102-
file_absolute_path = geode_functions.upload_file_path(
103-
UPLOAD_FOLDER, flask.request.json["filename"]
104-
)
101+
file_absolute_path = geode_functions.upload_file_path(flask.request.json["filename"])
105102
allowed_objects = geode_functions.list_geode_objects(
106103
file_absolute_path, flask.request.json["supported_feature"]
107104
)
@@ -120,12 +117,11 @@ def allowed_objects():
120117
methods=missing_files_json["methods"],
121118
)
122119
def missing_files():
123-
UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"]
124120
utils_functions.validate_request(flask.request, missing_files_json)
125-
121+
file_path = geode_functions.upload_file_path(flask.request.json["filename"])
126122
missing_files = geode_functions.missing_files(
127123
flask.request.json["input_geode_object"],
128-
geode_functions.upload_file_path(UPLOAD_FOLDER, flask.request.json["filename"]),
124+
file_path,
129125
)
130126
has_missing_files = missing_files.has_missing_files()
131127

@@ -186,11 +182,9 @@ def crs_converter_geographic_coordinate_systems():
186182
methods=inspect_file_json["methods"],
187183
)
188184
def inspect_file():
189-
UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"]
190185
utils_functions.validate_request(flask.request, inspect_file_json)
191186

192-
secure_filename = werkzeug.utils.secure_filename(flask.request.json["filename"])
193-
file_path = os.path.abspath(os.path.join(UPLOAD_FOLDER, secure_filename))
187+
file_path = geode_functions.upload_file_path(flask.request.json["filename"])
194188
data = geode_functions.load(flask.request.json["input_geode_object"], file_path)
195189
class_inspector = geode_functions.inspect(
196190
flask.request.json["input_geode_object"], data
@@ -211,13 +205,13 @@ def inspect_file():
211205
methods=geode_objects_and_output_extensions_json["methods"],
212206
)
213207
def geode_objects_and_output_extensions():
214-
UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"]
215208
utils_functions.validate_request(
216209
flask.request, geode_objects_and_output_extensions_json
217210
)
211+
file_path = geode_functions.upload_file_path(flask.request.json["filename"])
218212
data = geode_functions.load(
219213
flask.request.json["input_geode_object"],
220-
geode_functions.upload_file_path(UPLOAD_FOLDER, flask.request.json["filename"]),
214+
file_path,
221215
)
222216
geode_objects_and_output_extensions = (
223217
geode_functions.geode_objects_output_extensions(
@@ -243,9 +237,8 @@ def geode_objects_and_output_extensions():
243237
)
244238
def save_viewable_file():
245239
utils_functions.validate_request(flask.request, save_viewable_file_json)
246-
UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"]
247-
secure_filename = werkzeug.utils.secure_filename(flask.request.json["filename"])
248-
file_path = os.path.abspath(os.path.join(UPLOAD_FOLDER, secure_filename))
240+
241+
file_path = geode_functions.upload_file_path(flask.request.json["filename"])
249242
data = geode_functions.load(flask.request.json["input_geode_object"], file_path)
250243
return flask.make_response(
251244
utils_functions.generate_native_viewable_and_light_viewable(
@@ -296,7 +289,12 @@ def texture_coordinates():
296289

297290
texture_coordinates = data.texture_manager().texture_names()
298291

299-
return flask.make_response({"texture_coordinates": texture_coordinates}, 200)
292+
return flask.make_response(
293+
{
294+
"texture_coordinates": texture_coordinates
295+
},
296+
200
297+
)
300298

301299

302300
with open(

tests/conftest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77

88
# Local application imports
99
from app import app
10-
from src.opengeodeweb_back.app_config import TEST_ID
1110

1211

1312
@pytest.fixture(scope="session", autouse=True)
1413
def copy_data():
1514
shutil.rmtree("./data", ignore_errors=True)
16-
shutil.copytree("./tests/data/", "./data/{TEST_ID}/", dirs_exist_ok=True)
15+
shutil.copytree("./tests/data/", "./data/1/", dirs_exist_ok=True)
1716

1817

1918
@pytest.fixture

tests/test_models_routes.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import shutil
33
import flask
44

5-
import src.opengeodeweb_back.geode_functions as geode_functions
5+
from src.opengeodeweb_back import geode_functions
66

77

88
def test_model_mesh_components(client, test_id):
9-
route = "/models/vtm_component_indices"
9+
route = f"/models/vtm_component_indices"
1010

1111
with client.application.app_context():
1212
data_path = geode_functions.data_file_path({"id": test_id}, "viewable.vtm")
@@ -19,10 +19,11 @@ def test_model_mesh_components(client, test_id):
1919
uuid_dict = response.json["uuid_to_flat_index"]
2020
assert isinstance(uuid_dict, dict)
2121

22-
indices = sorted(uuid_dict.values())
22+
indices = list(uuid_dict.values())
23+
indices.sort()
2324
assert all(indices[i] > indices[i - 1] for i in range(1, len(indices)))
24-
for key in uuid_dict:
25-
assert isinstance(key, str)
25+
for uuid in uuid_dict.keys():
26+
assert isinstance(uuid, str)
2627

2728

2829
def test_extract_brep_uuids(client, test_id):
@@ -35,14 +36,13 @@ def test_extract_brep_uuids(client, test_id):
3536
data_path = geode_functions.data_file_path(json_data, brep_filename)
3637
os.makedirs(os.path.dirname(data_path), exist_ok=True)
3738
shutil.copy(f"./tests/data/{brep_filename}", data_path)
38-
3939
response = client.post(route, json=json_data)
40-
assert response.status_code == 200
4140

41+
assert response.status_code == 200
4242
uuid_dict = response.json["uuid_dict"]
4343
assert isinstance(uuid_dict, dict)
44-
expected = {"Block", "Line", "Surface", "Corner"}
45-
assert any(k in uuid_dict for k in expected)
46-
for values in uuid_dict.values():
47-
assert isinstance(values, list)
48-
assert all(isinstance(v, str) for v in values)
44+
expected_keys = {"Block", "Line", "Surface", "Corner"}
45+
assert any(key in uuid_dict for key in expected_keys)
46+
for key, value in uuid_dict.items():
47+
assert isinstance(value, list)
48+
assert all(isinstance(v, str) for v in value)

0 commit comments

Comments
 (0)