11# Standard library imports
22import os
3- import shutil
43
54# Third party imports
65from werkzeug .datastructures import FileStorage
109from opengeodeweb_microservice .database .connection import get_session
1110from opengeodeweb_back import geode_functions , test_utils
1211
12+ base_dir = os .path .abspath (os .path .dirname (__file__ ))
13+ data_dir = os .path .join (base_dir , "data" )
14+
1315
1416def test_allowed_files (client ):
1517 route = f"/opengeodeweb_back/allowed_files"
@@ -48,9 +50,11 @@ def get_full_data():
4850
4951
5052def test_upload_file (client , filename = "test.og_brep" ):
53+ file = os .path .join (data_dir , filename )
54+ print (f"{ file = } " , flush = True )
5155 response = client .put (
5256 f"/opengeodeweb_back/upload_file" ,
53- data = {"file" : FileStorage (open (f"./tests/data/ { filename } " , "rb" ))},
57+ data = {"file" : FileStorage (open (file , "rb" ))},
5458 )
5559 assert response .status_code == 201
5660
@@ -171,19 +175,19 @@ def get_full_data():
171175
172176def test_texture_coordinates (client , test_id ):
173177 with client .application .app_context ():
178+ file = os .path .join (data_dir , "hat.vtp" )
174179 data = Data .create (
175180 geode_object = "PolygonalSurface3D" ,
176181 viewer_object = geode_functions .get_object_type ("PolygonalSurface3D" ),
177- input_file = "hat.vtp" ,
182+ input_file = file ,
178183 )
179- data .native_file_name = "hat.vtp"
184+ data .native_file_name = file
180185 session = get_session ()
181186 if session :
182187 session .commit ()
183188
184189 data_path = geode_functions .data_file_path (data .id , data .native_file_name )
185190 os .makedirs (os .path .dirname (data_path ), exist_ok = True )
186- shutil .copy ("./tests/data/hat.vtp" , data_path )
187191 assert os .path .exists (data_path ), f"File not found at { data_path } "
188192 response = client .post (
189193 "/opengeodeweb_back/texture_coordinates" , json = {"id" : data .id }
@@ -199,19 +203,19 @@ def test_vertex_attribute_names(client, test_id):
199203 route = f"/opengeodeweb_back/vertex_attribute_names"
200204
201205 with client .application .app_context ():
206+ file = os .path .join (data_dir , "test.vtp" )
202207 data = Data .create (
203208 geode_object = "PolygonalSurface3D" ,
204209 viewer_object = geode_functions .get_object_type ("PolygonalSurface3D" ),
205- input_file = "test.vtp" ,
210+ input_file = file ,
206211 )
207- data .native_file_name = "test.vtp"
212+ data .native_file_name = file
208213 session = get_session ()
209214 if session :
210215 session .commit ()
211216
212217 data_path = geode_functions .data_file_path (data .id , data .native_file_name )
213218 os .makedirs (os .path .dirname (data_path ), exist_ok = True )
214- shutil .copy ("./tests/data/test.vtp" , data_path )
215219 assert os .path .exists (data_path ), f"File not found at { data_path } "
216220 response = client .post (route , json = {"id" : data .id })
217221 assert response .status_code == 200
@@ -225,19 +229,19 @@ def test_polygon_attribute_names(client, test_id):
225229 route = f"/opengeodeweb_back/polygon_attribute_names"
226230
227231 with client .application .app_context ():
232+ file = os .path .join (data_dir , "test.vtp" )
228233 data = Data .create (
229234 geode_object = "PolygonalSurface3D" ,
230235 viewer_object = geode_functions .get_object_type ("PolygonalSurface3D" ),
231- input_file = "test.vtp" ,
236+ input_file = file ,
232237 )
233- data .native_file_name = "test.vtp"
238+ data .native_file_name = file
234239 session = get_session ()
235240 if session :
236241 session .commit ()
237242
238243 data_path = geode_functions .data_file_path (data .id , data .native_file_name )
239244 os .makedirs (os .path .dirname (data_path ), exist_ok = True )
240- shutil .copy ("./tests/data/test.vtp" , data_path )
241245 assert os .path .exists (data_path ), f"File not found at { data_path } "
242246 response = client .post (route , json = {"id" : data .id })
243247 assert response .status_code == 200
@@ -251,19 +255,19 @@ def test_polyhedron_attribute_names(client, test_id):
251255 route = f"/opengeodeweb_back/polyhedron_attribute_names"
252256
253257 with client .application .app_context ():
258+ file = os .path .join (data_dir , "test.vtu" )
254259 data = Data .create (
255260 geode_object = "PolyhedralSolid3D" ,
256261 viewer_object = geode_functions .get_object_type ("PolyhedralSolid3D" ),
257- input_file = "test.vtu" ,
262+ input_file = file ,
258263 )
259- data .native_file_name = "test.vtu"
264+ data .native_file_name = file
260265 session = get_session ()
261266 if session :
262267 session .commit ()
263268
264269 data_path = geode_functions .data_file_path (data .id , data .native_file_name )
265270 os .makedirs (os .path .dirname (data_path ), exist_ok = True )
266- shutil .copy ("./tests/data/test.vtu" , data_path )
267271 assert os .path .exists (data_path ), f"File not found at { data_path } "
268272 response = client .post (route , json = {"id" : data .id })
269273 print (response .json )
0 commit comments