Skip to content

Commit 02caecd

Browse files
author
Geode-solutions robot
committed
Merge remote-tracking branch 'origin/next'
2 parents a7c1215 + 8c8cae2 commit 02caecd

File tree

3 files changed

+67
-10
lines changed

3 files changed

+67
-10
lines changed

src/opengeodeweb_back/utils_functions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ def save_all_viewables_and_return_info(
212212
data.native_file = os.path.basename(native_files[0])
213213
data.viewable_file = os.path.basename(viewable_path)
214214
data.light_viewable_file = os.path.basename(light_path)
215+
216+
if not data.input_file:
217+
data.input_file = data.native_file
218+
215219
assert data.native_file is not None
216220
assert data.viewable_file is not None
217221
assert data.light_viewable_file is not None

tests/test_models_routes.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,41 @@ def test_export_project_route(client: FlaskClient, tmp_path: Path) -> None:
6969
database_root_path = os.path.join(project_folder, "project.db")
7070
with open(database_root_path, "wb") as f:
7171
f.write(b"test_project_db")
72+
73+
with get_session() as session:
74+
session.query(Data).delete()
75+
session.commit()
76+
77+
data1 = Data(
78+
id="test_data_1",
79+
geode_object="BRep",
80+
viewer_object="BRep",
81+
input_file="test_native.txt",
82+
native_file="test_native.txt",
83+
additional_files=[],
84+
)
85+
data2 = Data(
86+
id="test_data_2",
87+
geode_object="Section",
88+
viewer_object="Section",
89+
input_file="test_input.txt",
90+
native_file="test_native2.txt",
91+
additional_files=[],
92+
)
93+
session.add(data1)
94+
session.add(data2)
95+
session.commit()
96+
97+
data1_dir = os.path.join(project_folder, "test_data_1")
98+
os.makedirs(data1_dir, exist_ok=True)
99+
with open(os.path.join(data1_dir, "test_native.txt"), "w") as f:
100+
f.write("native file content")
101+
102+
data2_dir = os.path.join(project_folder, "test_data_2")
103+
os.makedirs(data2_dir, exist_ok=True)
104+
with open(os.path.join(data2_dir, "test_input.txt"), "w") as f:
105+
f.write("input file content")
106+
72107
response = client.post(route, json={"snapshot": snapshot, "filename": filename})
73108
assert response.status_code == 200
74109
assert response.headers.get("new-file-name") == filename
@@ -77,13 +112,18 @@ def test_export_project_route(client: FlaskClient, tmp_path: Path) -> None:
77112
zip_bytes = response.get_data()
78113
tmp_zip_path = tmp_path / filename
79114
tmp_zip_path.write_bytes(zip_bytes)
115+
80116
with zipfile.ZipFile(tmp_zip_path, "r") as zip_file:
81117
names = zip_file.namelist()
82118
assert "snapshot.json" in names
83119
parsed = json.loads(zip_file.read("snapshot.json").decode("utf-8"))
84120
assert parsed == snapshot
85121
assert "project.db" in names
122+
assert "test_data_1/test_native.txt" in names
123+
assert "test_data_2/test_input.txt" in names
124+
86125
response.close()
126+
87127
export_path = os.path.join(project_folder, filename)
88128
if os.path.exists(export_path):
89129
os.remove(export_path)

tests/test_utils_functions.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,29 @@ def test_generate_native_viewable_and_light_viewable_from_object(
183183
)
184184
)
185185

186-
assert isinstance(result, dict)
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")
191-
assert isinstance(result["id"], str)
192-
assert re.match(r"[0-9a-f]{32}", result["id"])
193-
assert isinstance(result["viewer_type"], str)
194-
assert isinstance(result["binary_light_viewable"], str)
195-
assert result["input_file"] == ""
186+
assert isinstance(result, dict)
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")
191+
assert isinstance(result["id"], str)
192+
assert re.match(r"[0-9a-f]{32}", result["id"])
193+
assert isinstance(result["viewer_type"], str)
194+
assert isinstance(result["binary_light_viewable"], str)
195+
assert result["binary_light_viewable"].startswith('<?xml version="1.0"?>')
196+
197+
assert result["input_file"] == result["native_file"]
198+
199+
data = Data.get(result["id"])
200+
assert data is not None
201+
assert data.input_file == data.native_file
202+
assert data.light_viewable_file is not None
203+
assert data.light_viewable_file.endswith(".vtp")
204+
205+
data_path = os.path.join(app.config["DATA_FOLDER_PATH"], result["id"])
206+
assert os.path.exists(os.path.join(data_path, result["native_file"]))
207+
assert os.path.exists(os.path.join(data_path, result["viewable_file"]))
208+
assert os.path.exists(os.path.join(data_path, data.light_viewable_file))
196209

197210

198211
def test_generate_native_viewable_and_light_viewable_from_file(

0 commit comments

Comments
 (0)