@@ -29,6 +29,17 @@ def aoi_data() -> Dict[str, Any]:
2929 "z" : 0.0 ,
3030 }
3131
32+ @pytest .fixture
33+ def voi_data () -> Dict [str , Any ]:
34+ """Fixture for Volume of Interest (VOI) test data."""
35+ return {
36+ "name" : "test_voi" ,
37+ "aoi_id" : str (uuid .uuid4 ()),
38+ "z_min" : - 50.0 ,
39+ "z_max" : 100.0 ,
40+ "id" : str (uuid .uuid4 ()),
41+ }
42+
3243
3344def test_create_point (client : FlaskClient , point_data : Dict [str , Any ]) -> None :
3445 """Test the creation of a point with valid data."""
@@ -80,6 +91,33 @@ def test_create_aoi(client: FlaskClient, aoi_data: Dict[str, Any]) -> None:
8091 test_utils .test_route_wrong_params (client , route , lambda : aoi_data .copy ()) # type: ignore
8192
8293
94+ def test_create_voi (client : FlaskClient , voi_data : Dict [str , Any ]) -> None :
95+ """Test the creation of a VOI with valid data (including optional id)."""
96+ route : str = "/opengeodeweb_back/create/create_voi"
97+
98+ response = client .post (route , json = voi_data )
99+ assert response .status_code == 200
100+
101+ response_data : Any = response .json
102+ assert "id" in response_data
103+ assert "name" in response_data
104+ assert response_data ["name" ] == voi_data ["name" ]
105+ assert response_data ["object_type" ] == "mesh"
106+ assert response_data ["geode_object" ] == "EdgedCurve3D"
107+
108+ voi_data_no_id = voi_data .copy ()
109+ del voi_data_no_id ["id" ]
110+ response = client .post (route , json = voi_data_no_id )
111+ assert response .status_code == 200
112+ assert response .json ["name" ] == voi_data ["name" ]
113+
114+ voi_data_required_only = voi_data .copy ()
115+ del voi_data_required_only ["id" ]
116+
117+ test_utils .test_route_wrong_params (client , route , lambda : voi_data_required_only .copy ()) # type: ignore
118+
119+
120+
83121def test_create_point_with_invalid_data (client : FlaskClient ) -> None :
84122 """Test the point creation endpoint with invalid data."""
85123 route : str = "/opengeodeweb_back/create/create_point"
@@ -130,6 +168,28 @@ def test_create_aoi_with_invalid_data(
130168 assert response .status_code == 400
131169
132170
171+ def test_create_voi_with_invalid_data (
172+ client : FlaskClient , voi_data : Dict [str , Any ]
173+ ) -> None :
174+ """Test the VOI creation endpoint with invalid data."""
175+ route : str = "/opengeodeweb_back/create/create_voi"
176+
177+ # Test with non-numeric z_min
178+ invalid_data : Dict [str , Any ] = {** voi_data , "z_min" : "not_a_number" }
179+ response = client .post (route , json = invalid_data )
180+ assert response .status_code == 400
181+
182+ # Test with non-numeric z_max
183+ invalid_data = {** voi_data , "z_max" : "not_a_number" }
184+ response = client .post (route , json = invalid_data )
185+ assert response .status_code == 400
186+
187+ # Test with invalid aoi_id format (e.g., not a string/uuid)
188+ invalid_data = {** voi_data , "aoi_id" : 12345 }
189+ response = client .post (route , json = invalid_data )
190+ assert response .status_code == 400
191+
192+
133193def test_create_point_file_generation (
134194 client : FlaskClient , point_data : Dict [str , Any ]
135195) -> None :
@@ -208,3 +268,43 @@ def test_create_aoi_file_generation(
208268 # Verify file extensions
209269 assert response_data ["native_file_name" ].endswith (".og_edc3d" )
210270 assert response_data ["viewable_file_name" ].endswith (".vtp" )
271+
272+
273+ def test_create_voi_file_generation (
274+ client : FlaskClient , voi_data : Dict [str , Any ]
275+ ) -> None :
276+ """Test that the VOI creation generates the correct files."""
277+ route : str = "/opengeodeweb_back/create/create_voi"
278+
279+ # Make the request
280+ response = client .post (route , json = voi_data )
281+ assert response .status_code == 200
282+ response_data : Any = response .json
283+
284+ # Get the data folder path for this specific ID
285+ DATA_FOLDER_PATH : str = client .application .config ["DATA_FOLDER_PATH" ]
286+ data_id : str = response_data ["id" ]
287+ data_folder : str = os .path .join (DATA_FOLDER_PATH , data_id )
288+
289+ # Check that the data folder exists
290+ assert os .path .exists (data_folder )
291+ assert os .path .isdir (data_folder )
292+
293+ # Check native file exists
294+ native_file_path : str = os .path .join (data_folder , response_data ["native_file_name" ])
295+ assert os .path .exists (native_file_path )
296+
297+ # Check viewable file exists
298+ viewable_file_path : str = os .path .join (
299+ data_folder , response_data ["viewable_file_name" ]
300+ )
301+ assert os .path .exists (viewable_file_path )
302+
303+ # Check light viewable file exists if present
304+ if "binary_light_viewable" in response_data :
305+ light_viewable_file_path : str = os .path .join (data_folder , "light_viewable.vtp" )
306+ assert os .path .exists (light_viewable_file_path )
307+
308+ # Verify file extensions (VOI uses EdgedCurve3D like AOI)
309+ assert response_data ["native_file_name" ].endswith (".og_edc3d" )
310+ assert response_data ["viewable_file_name" ].endswith (".vtp" )
0 commit comments