@@ -401,6 +401,85 @@ def test_scan_tool_auth_failure(self, mock_get_user_id):
401401 assert "Failed to update tool" in data ["detail" ]
402402
403403
404+ class TestLoadLastToolConfigAPI :
405+ """Test endpoint for loading last tool configuration"""
406+
407+ @patch ('apps.tool_config_app.get_current_user_id' )
408+ @patch ('apps.tool_config_app.load_last_tool_config_impl' )
409+ def test_load_last_tool_config_success (self , mock_load_config , mock_get_user_id ):
410+ """Test successful loading of last tool configuration"""
411+ mock_get_user_id .return_value = ("user123" , "tenant456" )
412+ mock_load_config .return_value = {"param1" : "value1" , "param2" : "value2" }
413+
414+ response = client .get ("/tool/load_config/123" )
415+
416+ assert response .status_code == HTTPStatus .OK
417+ data = response .json ()
418+ assert data ["status" ] == "success"
419+ assert data ["message" ] == {"param1" : "value1" , "param2" : "value2" }
420+
421+ mock_get_user_id .assert_called_once_with (None )
422+ mock_load_config .assert_called_once_with (123 , "tenant456" , "user123" )
423+
424+ @patch ('apps.tool_config_app.get_current_user_id' )
425+ @patch ('apps.tool_config_app.load_last_tool_config_impl' )
426+ def test_load_last_tool_config_not_found (self , mock_load_config , mock_get_user_id ):
427+ """Test loading tool config when not found"""
428+ mock_get_user_id .return_value = ("user123" , "tenant456" )
429+ mock_load_config .side_effect = ValueError ("Tool configuration not found for tool ID: 123" )
430+
431+ response = client .get ("/tool/load_config/123" )
432+
433+ assert response .status_code == HTTPStatus .NOT_FOUND
434+ data = response .json ()
435+ assert "Tool configuration not found" in data ["detail" ]
436+
437+ mock_get_user_id .assert_called_once_with (None )
438+ mock_load_config .assert_called_once_with (123 , "tenant456" , "user123" )
439+
440+ @patch ('apps.tool_config_app.get_current_user_id' )
441+ @patch ('apps.tool_config_app.load_last_tool_config_impl' )
442+ def test_load_last_tool_config_service_error (self , mock_load_config , mock_get_user_id ):
443+ """Test service error when loading tool config"""
444+ mock_get_user_id .return_value = ("user123" , "tenant456" )
445+ mock_load_config .side_effect = Exception ("Database error" )
446+
447+ response = client .get ("/tool/load_config/123" )
448+
449+ assert response .status_code == HTTPStatus .INTERNAL_SERVER_ERROR
450+ data = response .json ()
451+ assert "Failed to load tool config" in data ["detail" ]
452+
453+ mock_get_user_id .assert_called_once_with (None )
454+ mock_load_config .assert_called_once_with (123 , "tenant456" , "user123" )
455+
456+ @patch ('apps.tool_config_app.get_current_user_id' )
457+ def test_load_last_tool_config_auth_error (self , mock_get_user_id ):
458+ """Test authentication error when loading tool config"""
459+ mock_get_user_id .side_effect = Exception ("Auth error" )
460+
461+ response = client .get ("/tool/load_config/123" )
462+
463+ assert response .status_code == HTTPStatus .INTERNAL_SERVER_ERROR
464+ data = response .json ()
465+ assert "Failed to load tool config" in data ["detail" ]
466+
467+ @patch ('apps.tool_config_app.get_current_user_id' )
468+ @patch ('apps.tool_config_app.load_last_tool_config_impl' )
469+ def test_load_last_tool_config_with_authorization_header (self , mock_load_config , mock_get_user_id ):
470+ """Test loading tool config with authorization header"""
471+ mock_get_user_id .return_value = ("user123" , "tenant456" )
472+ mock_load_config .return_value = {"param1" : "value1" }
473+
474+ response = client .get (
475+ "/tool/load_config/123" ,
476+ headers = {"Authorization" : "Bearer test_token" }
477+ )
478+
479+ assert response .status_code == HTTPStatus .OK
480+ mock_get_user_id .assert_called_with ("Bearer test_token" )
481+
482+
404483class TestDataValidation :
405484 """Data validation tests"""
406485
0 commit comments