11# Standard library imports
22import os
3- from typing import Dict , Any , TypedDict , cast
3+ import uuid
4+ from typing import Any , Callable , Dict , List
45
56# Third party imports
67import pytest
8+ from flask .testing import FlaskClient
79
810# Local application imports
911from src .opengeodeweb_back import test_utils
1012
11- # --- Type definitions for test data ---
12- class Point (TypedDict ):
13- x : float
14- y : float
15-
16- class PointData (TypedDict ):
17- name : str
18- x : float
19- y : float
20- z : float
21-
22- class AOIData (TypedDict ):
23- name : str
24- points : list [Point ]
25- z : float
26-
27- # --- Fixtures ---
2813@pytest .fixture
29- def point_data () -> PointData :
14+ def point_data () -> Dict [ str , Any ] :
3015 return {
3116 "name" : "test_point" ,
3217 "x" : 1.0 ,
@@ -35,7 +20,7 @@ def point_data() -> PointData:
3520 }
3621
3722@pytest .fixture
38- def aoi_data () -> AOIData :
23+ def aoi_data () -> Dict [ str , Any ] :
3924 return {
4025 "name" : "test_aoi" ,
4126 "points" : [
@@ -47,50 +32,58 @@ def aoi_data() -> AOIData:
4732 "z" : 0.0
4833 }
4934
50- # --- Tests ---
51- def test_create_point (client : Any , point_data : PointData ) -> None :
35+ def test_create_point (client : FlaskClient , point_data : Dict [str , Any ]) -> None :
5236 """Test the creation of a point with valid data."""
5337 route : str = "/opengeodeweb_back/create/create_point"
38+
5439 # Test with all required data
5540 response = client .post (route , json = point_data )
5641 assert response .status_code == 200
42+
5743 # Verify response data
58- response_data : Dict [ str , Any ] = response .json
44+ response_data : Any = response .json
5945 assert "viewable_file_name" in response_data
6046 assert "id" in response_data
6147 assert "name" in response_data
6248 assert "native_file_name" in response_data
6349 assert "object_type" in response_data
6450 assert "geode_object" in response_data
51+
6552 assert response_data ["name" ] == point_data ["name" ]
6653 assert response_data ["object_type" ] == "mesh"
6754 assert response_data ["geode_object" ] == "PointSet3D"
68- # Test with missing parameters - IMPORTANT: use .copy() to avoid mutation
55+
56+ # Test with missing parameters
6957 test_utils .test_route_wrong_params (client , route , lambda : point_data .copy ()) # type: ignore
7058
71- def test_create_aoi (client : Any , aoi_data : AOIData ) -> None :
59+ def test_create_aoi (client : FlaskClient , aoi_data : Dict [ str , Any ] ) -> None :
7260 """Test the creation of an AOI with valid data."""
7361 route : str = "/opengeodeweb_back/create/create_aoi"
62+
7463 # Test with all required data
7564 response = client .post (route , json = aoi_data )
7665 assert response .status_code == 200
66+
7767 # Verify response data
78- response_data : Dict [ str , Any ] = response .json
68+ response_data : Any = response .json
7969 assert "viewable_file_name" in response_data
8070 assert "id" in response_data
8171 assert "name" in response_data
8272 assert "native_file_name" in response_data
8373 assert "object_type" in response_data
8474 assert "geode_object" in response_data
75+
8576 assert response_data ["name" ] == aoi_data ["name" ]
8677 assert response_data ["object_type" ] == "mesh"
8778 assert response_data ["geode_object" ] == "EdgedCurve3D"
88- # Test with missing parameters - IMPORTANT: use .copy() to avoid mutation
89- test_utils .test_route_wrong_params (client , route , lambda : aoi_data .copy ()) # type: ignore
9079
91- def test_create_point_with_invalid_data (client : Any ) -> None :
80+ # Test with missing parameters
81+ test_utils .test_route_wrong_params (client , route , lambda : aoi_data .copy ())# type: ignore
82+
83+ def test_create_point_with_invalid_data (client : FlaskClient ) -> None :
9284 """Test the point creation endpoint with invalid data."""
9385 route : str = "/opengeodeweb_back/create/create_point"
86+
9487 # Test with non-numeric coordinates
9588 invalid_data : Dict [str , Any ] = {
9689 "name" : "invalid_point" ,
@@ -100,6 +93,7 @@ def test_create_point_with_invalid_data(client: Any) -> None:
10093 }
10194 response = client .post (route , json = invalid_data )
10295 assert response .status_code == 400
96+
10397 # Test with missing coordinates
10498 invalid_data = {
10599 "name" : "invalid_point" ,
@@ -109,9 +103,10 @@ def test_create_point_with_invalid_data(client: Any) -> None:
109103 response = client .post (route , json = invalid_data )
110104 assert response .status_code == 400
111105
112- def test_create_aoi_with_invalid_data (client : Any , aoi_data : AOIData ) -> None :
106+ def test_create_aoi_with_invalid_data (client : FlaskClient , aoi_data : Dict [ str , Any ] ) -> None :
113107 """Test the AOI creation endpoint with invalid data."""
114108 route : str = "/opengeodeweb_back/create/create_aoi"
109+
115110 # Test with invalid points
116111 invalid_data : Dict [str , Any ] = {
117112 ** aoi_data ,
@@ -124,6 +119,7 @@ def test_create_aoi_with_invalid_data(client: Any, aoi_data: AOIData) -> None:
124119 }
125120 response = client .post (route , json = invalid_data )
126121 assert response .status_code == 400
122+
127123 # Test with too few points
128124 invalid_data = {
129125 ** aoi_data ,
@@ -134,6 +130,7 @@ def test_create_aoi_with_invalid_data(client: Any, aoi_data: AOIData) -> None:
134130 }
135131 response = client .post (route , json = invalid_data )
136132 assert response .status_code == 400
133+
137134 # Test with invalid z value
138135 invalid_data = {
139136 ** aoi_data ,
@@ -142,58 +139,72 @@ def test_create_aoi_with_invalid_data(client: Any, aoi_data: AOIData) -> None:
142139 response = client .post (route , json = invalid_data )
143140 assert response .status_code == 400
144141
145- def test_create_point_file_generation (client : Any , point_data : PointData ) -> None :
142+ def test_create_point_file_generation (client : FlaskClient , point_data : Dict [ str , Any ] ) -> None :
146143 """Test that the point creation generates the correct files."""
147144 route : str = "/opengeodeweb_back/create/create_point"
145+
148146 # Make the request
149147 response = client .post (route , json = point_data )
150148 assert response .status_code == 200
151- response_data : Dict [str , Any ] = response .json
149+ response_data : Any = response .json
150+
152151 # Get the data folder path for this specific ID
153152 DATA_FOLDER_PATH : str = client .application .config ["DATA_FOLDER_PATH" ]
154153 data_id : str = response_data ["id" ]
155154 data_folder : str = os .path .join (DATA_FOLDER_PATH , data_id )
155+
156156 # Check that the data folder exists
157157 assert os .path .exists (data_folder )
158158 assert os .path .isdir (data_folder )
159+
159160 # Check native file exists
160161 native_file_path : str = os .path .join (data_folder , response_data ["native_file_name" ])
161162 assert os .path .exists (native_file_path )
163+
162164 # Check viewable file exists
163165 viewable_file_path : str = os .path .join (data_folder , response_data ["viewable_file_name" ])
164166 assert os .path .exists (viewable_file_path )
167+
165168 # Check light viewable file exists if present
166169 if "binary_light_viewable" in response_data :
167170 light_viewable_file_path : str = os .path .join (data_folder , "light_viewable.vtp" )
168171 assert os .path .exists (light_viewable_file_path )
172+
169173 # Verify file extensions
170174 assert response_data ["native_file_name" ].endswith (".og_pts3d" )
171175 assert response_data ["viewable_file_name" ].endswith (".vtp" )
172176
173- def test_create_aoi_file_generation (client : Any , aoi_data : AOIData ) -> None :
177+ def test_create_aoi_file_generation (client : FlaskClient , aoi_data : Dict [ str , Any ] ) -> None :
174178 """Test that the AOI creation generates the correct files."""
175179 route : str = "/opengeodeweb_back/create/create_aoi"
180+
176181 # Make the request
177182 response = client .post (route , json = aoi_data )
178183 assert response .status_code == 200
179- response_data : Dict [str , Any ] = response .json
184+ response_data : Any = response .json
185+
180186 # Get the data folder path for this specific ID
181187 DATA_FOLDER_PATH : str = client .application .config ["DATA_FOLDER_PATH" ]
182188 data_id : str = response_data ["id" ]
183189 data_folder : str = os .path .join (DATA_FOLDER_PATH , data_id )
190+
184191 # Check that the data folder exists
185192 assert os .path .exists (data_folder )
186193 assert os .path .isdir (data_folder )
194+
187195 # Check native file exists
188196 native_file_path : str = os .path .join (data_folder , response_data ["native_file_name" ])
189197 assert os .path .exists (native_file_path )
198+
190199 # Check viewable file exists
191200 viewable_file_path : str = os .path .join (data_folder , response_data ["viewable_file_name" ])
192201 assert os .path .exists (viewable_file_path )
202+
193203 # Check light viewable file exists if present
194204 if "binary_light_viewable" in response_data :
195205 light_viewable_file_path : str = os .path .join (data_folder , "light_viewable.vtp" )
196206 assert os .path .exists (light_viewable_file_path )
207+
197208 # Verify file extensions
198209 assert response_data ["native_file_name" ].endswith (".og_edc3d" )
199- assert response_data ["viewable_file_name" ].endswith (".vtp" )
210+ assert response_data ["viewable_file_name" ].endswith (".vtp" )
0 commit comments