@@ -161,94 +161,6 @@ def test_registry_endpoint_with_none_data(ui_app_without_registry):
161161 assertpy .assert_that (response .status_code ).is_equal_to (EXPECTED_ERROR_STATUS )
162162
163163
164- def test_save_document_endpoint_success (ui_app_with_registry ):
165- """Test the save document endpoint successfully saves data to a labels file.
166-
167- This test verifies that the /save-document endpoint correctly processes
168- a valid request, creates a labels file, and returns success confirmation.
169- """
170- client = TestClient (ui_app_with_registry )
171-
172- # Create a temporary file in the current working directory for testing
173- with tempfile .NamedTemporaryFile (
174- mode = "w" , suffix = ".py" , delete = False , dir = os .getcwd ()
175- ) as f :
176- test_file_path = f .name
177- f .write ("# Test file content" )
178-
179- try :
180- request_data = {
181- "file_path" : test_file_path ,
182- "data" : {"test" : "data" , "key" : "value" },
183- }
184-
185- response = client .post ("/save-document" , json = request_data )
186- assertpy .assert_that (response .status_code ).is_equal_to (EXPECTED_SUCCESS_STATUS )
187-
188- response_data = response .json ()
189- assertpy .assert_that (response_data ["success" ]).is_true ()
190- assertpy .assert_that (response_data ).contains_key ("saved_to" )
191-
192- # Verify the file was created
193- labels_file = response_data ["saved_to" ]
194- assertpy .assert_that (os .path .exists (labels_file )).is_true ()
195-
196- with open (labels_file , "r" ) as f :
197- saved_data = json .load (f )
198- assertpy .assert_that (saved_data ).is_equal_to (request_data ["data" ])
199-
200- finally :
201- # Cleanup
202- if os .path .exists (test_file_path ):
203- os .unlink (test_file_path )
204- labels_file = test_file_path .replace (".py" , "-labels.json" )
205- if os .path .exists (labels_file ):
206- os .unlink (labels_file )
207-
208-
209- def test_save_document_endpoint_invalid_path (ui_app_with_registry ):
210- """Test the save document endpoint returns error for invalid file path.
211-
212- This test verifies that the /save-document endpoint correctly rejects
213- file paths that are outside the current working directory for security.
214- """
215- client = TestClient (ui_app_with_registry )
216-
217- request_data = {
218- "file_path" : "/invalid/absolute/path/outside/workspace.py" ,
219- "data" : {"test" : "data" },
220- }
221-
222- response = client .post ("/save-document" , json = request_data )
223- assertpy .assert_that (response .status_code ).is_equal_to (EXPECTED_SUCCESS_STATUS )
224-
225- response_data = response .json ()
226- assertpy .assert_that (response_data ).contains_key ("error" )
227- assertpy .assert_that (response_data ["error" ]).contains ("Invalid file path" )
228-
229-
230- def test_save_document_endpoint_exception_handling (ui_app_with_registry ):
231- """Test the save document endpoint handles exceptions gracefully.
232-
233- This test verifies that the /save-document endpoint properly catches
234- and returns error responses when exceptions occur during processing.
235- """
236- client = TestClient (ui_app_with_registry )
237-
238- # Test with a file path outside the current working directory (will cause an exception)
239- request_data = {
240- "file_path" : "/invalid/absolute/path/outside/workspace.py" ,
241- "data" : {"test" : "data" },
242- }
243-
244- response = client .post ("/save-document" , json = request_data )
245- assertpy .assert_that (response .status_code ).is_equal_to (EXPECTED_SUCCESS_STATUS )
246-
247- response_data = response .json ()
248- assertpy .assert_that (response_data ).contains_key ("error" )
249- assertpy .assert_that (response_data ["error" ]).contains ("Invalid file path" )
250-
251-
252164@pytest .mark .parametrize (
253165 "registry_available,expected_status" ,
254166 [(True , EXPECTED_SUCCESS_STATUS ), (False , EXPECTED_ERROR_STATUS )],
0 commit comments