Skip to content

Commit 681e169

Browse files
committed
native. instead of filename. for native file
1 parent 6250fb9 commit 681e169

3 files changed

Lines changed: 13 additions & 20 deletions

File tree

src/opengeodeweb_back/utils_functions.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ def save_all_viewables_and_return_info(
188188
geode_object: GeodeObject,
189189
data: Data,
190190
data_path: str,
191-
native_filename: str | None = None,
192191
) -> dict[str, str | list[str]]:
193192
with ThreadPoolExecutor() as executor:
194193
native_files, viewable_path, light_path = executor.map(
@@ -197,12 +196,7 @@ def save_all_viewables_and_return_info(
197196
(
198197
geode_object.save,
199198
os.path.join(
200-
data_path,
201-
(
202-
native_filename
203-
if native_filename is not None
204-
else "native." + geode_object.native_extension()
205-
),
199+
data_path, "native." + geode_object.native_extension()
206200
),
207201
),
208202
(geode_object.save_viewable, os.path.join(data_path, "viewable")),
@@ -276,10 +270,9 @@ def generate_native_viewable_and_light_viewable_from_file(
276270
shutil.copy2(source_path, dest_path)
277271
additional_files_copied.append(additional_file.filename)
278272

273+
data.name = input_file
279274
geode_object = generic_geode_object.load(copied_full_path)
280-
return save_all_viewables_and_return_info(
281-
geode_object,
282-
data,
283-
data_path,
284-
native_filename=secure_input_file,
285-
)
275+
result = save_all_viewables_and_return_info(geode_object, data, data_path)
276+
if os.path.exists(copied_full_path):
277+
os.remove(copied_full_path)
278+
return result

tests/test_models_routes.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,27 +62,27 @@ def test_export_project_route(client: FlaskClient, tmp_path: Path) -> None:
6262
geode_object="BRep",
6363
viewer_object="BRep",
6464
viewer_elements_type="default",
65-
native_file="test_native.txt",
65+
native_file="native.txt",
6666
)
6767
data2 = Data(
6868
id="test_data_2",
6969
geode_object="Section",
7070
viewer_object="Section",
7171
viewer_elements_type="default",
72-
native_file="test_native2.txt",
72+
native_file="native.txt",
7373
)
7474
session.add(data1)
7575
session.add(data2)
7676
session.commit()
7777

7878
data1_dir = os.path.join(project_folder, "test_data_1")
7979
os.makedirs(data1_dir, exist_ok=True)
80-
with open(os.path.join(data1_dir, "test_native.txt"), "w") as f:
80+
with open(os.path.join(data1_dir, "native.txt"), "w") as f:
8181
f.write("native file content")
8282

8383
data2_dir = os.path.join(project_folder, "test_data_2")
8484
os.makedirs(data2_dir, exist_ok=True)
85-
with open(os.path.join(data2_dir, "test_native2.txt"), "w") as f:
85+
with open(os.path.join(data2_dir, "native.txt"), "w") as f:
8686
f.write("native file content")
8787

8888
response = client.post(route, json={"snapshot": snapshot, "filename": filename})
@@ -100,8 +100,8 @@ def test_export_project_route(client: FlaskClient, tmp_path: Path) -> None:
100100
parsed = json.loads(zip_file.read("snapshot.json").decode("utf-8"))
101101
assert parsed == snapshot
102102
assert "project.db" in names
103-
assert "test_data_1/test_native.txt" in names
104-
assert "test_data_2/test_native2.txt" in names
103+
assert "test_data_1/native.txt" in names
104+
assert "test_data_2/native.txt" in names
105105

106106
response.close()
107107

tests/test_utils_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def test_generate_native_viewable_and_light_viewable_from_file(
208208

209209
assert isinstance(result, dict)
210210
assert isinstance(result["native_file"], str)
211-
assert result["native_file"] == "test.og_brep"
211+
assert result["native_file"] == "native.og_brep"
212212
assert isinstance(result["viewable_file"], str)
213213
assert result["viewable_file"].endswith(".vtm")
214214
assert isinstance(result["id"], str)

0 commit comments

Comments
 (0)