Skip to content

Commit 374ac32

Browse files
committed
session.commit() added to tests
1 parent 1a2dae9 commit 374ac32

4 files changed

Lines changed: 51 additions & 33 deletions

File tree

src/opengeodeweb_back/geode_functions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ def load_data(data_id: str) -> Any:
6161
flask.abort(404, f"Data with id {data_id} not found")
6262

6363
file_absolute_path = data_file_path(data_id, data_entry.native_file_name)
64+
print("Loading file: ", file_absolute_path)
65+
print("File exists: ", os.path.exists(file_absolute_path))
6466
return load(data_entry.geode_object, file_absolute_path)
6567

6668

tests/conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ def copy_data():
2929
print("Directory contents:", os.listdir("."))
3030

3131
init_database(app)
32+
# print(list(app.blueprints.keys()))
33+
# for rule in app.url_map.iter_rules():
34+
# print(f"Route: {rule.rule} -> {rule.endpoint}")
3235

3336

3437
@pytest.fixture

tests/test_models_routes.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,24 @@ def test_extract_brep_uuids(client, test_id):
3333
brep_filename = "cube.og_brep"
3434

3535
with client.application.app_context():
36-
data_entry = Data.create(geode_object="BRep", input_file=brep_filename)
36+
data_entry = Data.create(
37+
geode_object="BRep",
38+
input_file=brep_filename,
39+
)
3740
data_entry.native_file_name = brep_filename
38-
39-
data_path = geode_functions.data_file_path(data_entry.id, brep_filename)
40-
os.makedirs(os.path.dirname(data_path), exist_ok=True)
41-
shutil.copy(f"./tests/data/{brep_filename}", data_path)
42-
43-
json_data = {"id": data_entry.id}
44-
response = client.post(route, json=json_data)
45-
46-
assert response.status_code == 200
47-
uuid_dict = response.json["uuid_dict"]
48-
assert isinstance(uuid_dict, dict)
49-
expected_keys = {"Block", "Line", "Surface", "Corner"}
50-
assert any(key in uuid_dict for key in expected_keys)
51-
for key, value in uuid_dict.items():
52-
assert isinstance(value, list)
53-
assert all(isinstance(v, str) for v in value)
41+
session = get_session()
42+
if session:
43+
session.commit()
44+
45+
src_path = os.path.join("tests", "data", brep_filename)
46+
dest_path = os.path.join(
47+
flask.current_app.config["DATA_FOLDER_PATH"], data_entry.id, brep_filename
48+
)
49+
os.makedirs(os.path.dirname(dest_path), exist_ok=True)
50+
shutil.copy2(src_path, dest_path)
51+
52+
response = client.post(route, json={"id": data_entry.id})
53+
assert response.status_code == 200
54+
assert "uuid_dict" in response.json
55+
uuid_dict = response.json["uuid_dict"]
56+
assert isinstance(uuid_dict, dict)

tests/test_routes.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from werkzeug.datastructures import FileStorage
77

88
# Local application imports
9+
from opengeodeweb_microservice.microservice.data import Data
10+
from opengeodeweb_microservice.database.connection import get_session
911
from src.opengeodeweb_back import geode_functions, test_utils
1012

1113

@@ -171,16 +173,15 @@ def test_texture_coordinates(client, test_id):
171173
with client.application.app_context():
172174
data = Data.create(geode_object="PolygonalSurface3D", input_file="hat.vtp")
173175
data.native_file_name = "hat.vtp"
176+
session = get_session()
177+
if session:
178+
session.commit()
174179

175-
data_path = geode_functions.data_file_path(data.id, "hat.vtp")
176-
print(data_path)
180+
data_path = geode_functions.data_file_path(data.id, data.native_file_name)
177181
os.makedirs(os.path.dirname(data_path), exist_ok=True)
178182
shutil.copy("./tests/data/hat.vtp", data_path)
179-
180-
response = client.post(
181-
"/texture_coordinates",
182-
json={"id": data.id},
183-
)
183+
assert os.path.exists(data_path), f"File not found at {data_path}"
184+
response = client.post("/texture_coordinates", json={"id": data.id})
184185
assert response.status_code == 200
185186
texture_coordinates = response.json["texture_coordinates"]
186187
assert type(texture_coordinates) is list
@@ -194,12 +195,14 @@ def test_vertex_attribute_names(client, test_id):
194195
with client.application.app_context():
195196
data = Data.create(geode_object="PolygonalSurface3D", input_file="test.vtp")
196197
data.native_file_name = "test.vtp"
198+
session = get_session()
199+
if session:
200+
session.commit()
197201

198-
data_path = geode_functions.data_file_path(data.id, "test.vtp")
202+
data_path = geode_functions.data_file_path(data.id, data.native_file_name)
199203
os.makedirs(os.path.dirname(data_path), exist_ok=True)
200-
if os.path.exists("./tests/data/hat.vtp"):
201-
shutil.copy("./tests/data/hat.vtp", data_path)
202-
204+
shutil.copy("./tests/data/test.vtp", data_path)
205+
assert os.path.exists(data_path), f"File not found at {data_path}"
203206
response = client.post(route, json={"id": data.id})
204207
assert response.status_code == 200
205208
vertex_attribute_names = response.json["vertex_attribute_names"]
@@ -214,11 +217,14 @@ def test_polygon_attribute_names(client, test_id):
214217
with client.application.app_context():
215218
data = Data.create(geode_object="PolygonalSurface3D", input_file="test.vtp")
216219
data.native_file_name = "test.vtp"
220+
session = get_session()
221+
if session:
222+
session.commit()
217223

218-
data_path = geode_functions.data_file_path(data.id, "test.vtp")
224+
data_path = geode_functions.data_file_path(data.id, data.native_file_name)
219225
os.makedirs(os.path.dirname(data_path), exist_ok=True)
220-
shutil.copy("./tests/data/test.vtp", data_path)
221-
226+
shutil.copy("./tests/data/test.vtp", data_path)
227+
assert os.path.exists(data_path), f"File not found at {data_path}"
222228
response = client.post(route, json={"id": data.id})
223229
assert response.status_code == 200
224230
polygon_attribute_names = response.json["polygon_attribute_names"]
@@ -233,12 +239,16 @@ def test_polyhedron_attribute_names(client, test_id):
233239
with client.application.app_context():
234240
data = Data.create(geode_object="PolyhedralSolid3D", input_file="test.vtu")
235241
data.native_file_name = "test.vtu"
242+
session = get_session()
243+
if session:
244+
session.commit()
236245

237-
data_path = geode_functions.data_file_path(data.id, "test.vtu")
246+
data_path = geode_functions.data_file_path(data.id, data.native_file_name)
238247
os.makedirs(os.path.dirname(data_path), exist_ok=True)
239248
shutil.copy("./tests/data/test.vtu", data_path)
240-
249+
assert os.path.exists(data_path), f"File not found at {data_path}"
241250
response = client.post(route, json={"id": data.id})
251+
print(response.json)
242252
assert response.status_code == 200
243253
polyhedron_attribute_names = response.json["polyhedron_attribute_names"]
244254
assert type(polyhedron_attribute_names) is list

0 commit comments

Comments
 (0)