@@ -689,3 +689,120 @@ def test_get_agent_call_relationship_api_exception(mocker, mock_auth_header):
689689
690690 assert resp .status_code == 500
691691 assert "Failed to get agent call relationship" in resp .json ()["detail" ]
692+
693+
694+ def test_check_agent_name_batch_api_success (mocker , mock_auth_header ):
695+ mock_impl = mocker .patch (
696+ "apps.agent_app.check_agent_name_conflict_batch_impl" ,
697+ new_callable = mocker .AsyncMock ,
698+ )
699+ mock_impl .return_value = [{"name_conflict" : True }]
700+
701+ payload = {
702+ "items" : [
703+ {"agent_id" : 1 , "name" : "AgentA" , "display_name" : "Agent A" },
704+ ]
705+ }
706+
707+ resp = config_client .post (
708+ "/agent/check_name/batch" , json = payload , headers = mock_auth_header
709+ )
710+
711+ assert resp .status_code == 200
712+ mock_impl .assert_called_once ()
713+ assert resp .json () == [{"name_conflict" : True }]
714+
715+
716+ def test_check_agent_name_batch_api_bad_request (mocker , mock_auth_header ):
717+ mock_impl = mocker .patch (
718+ "apps.agent_app.check_agent_name_conflict_batch_impl" ,
719+ new_callable = mocker .AsyncMock ,
720+ )
721+ mock_impl .side_effect = ValueError ("bad payload" )
722+
723+ resp = config_client .post (
724+ "/agent/check_name/batch" ,
725+ json = {"items" : [{"agent_id" : 1 , "name" : "AgentA" }]},
726+ headers = mock_auth_header ,
727+ )
728+
729+ assert resp .status_code == 400
730+ assert resp .json ()["detail" ] == "bad payload"
731+
732+
733+ def test_check_agent_name_batch_api_error (mocker , mock_auth_header ):
734+ mock_impl = mocker .patch (
735+ "apps.agent_app.check_agent_name_conflict_batch_impl" ,
736+ new_callable = mocker .AsyncMock ,
737+ )
738+ mock_impl .side_effect = Exception ("unexpected" )
739+
740+ resp = config_client .post (
741+ "/agent/check_name/batch" ,
742+ json = {"items" : [{"agent_id" : 1 , "name" : "AgentA" }]},
743+ headers = mock_auth_header ,
744+ )
745+
746+ assert resp .status_code == 500
747+ assert "Agent name batch check error" in resp .json ()["detail" ]
748+
749+
750+ def test_regenerate_agent_name_batch_api_success (mocker , mock_auth_header ):
751+ mock_impl = mocker .patch (
752+ "apps.agent_app.regenerate_agent_name_batch_impl" ,
753+ new_callable = mocker .AsyncMock ,
754+ )
755+ mock_impl .return_value = [{"name" : "NewName" , "display_name" : "New Display" }]
756+
757+ payload = {
758+ "items" : [
759+ {
760+ "agent_id" : 1 ,
761+ "name" : "AgentA" ,
762+ "display_name" : "Agent A" ,
763+ "task_description" : "desc" ,
764+ }
765+ ]
766+ }
767+
768+ resp = config_client .post (
769+ "/agent/regenerate_name/batch" , json = payload , headers = mock_auth_header
770+ )
771+
772+ assert resp .status_code == 200
773+ mock_impl .assert_called_once ()
774+ assert resp .json () == [{"name" : "NewName" , "display_name" : "New Display" }]
775+
776+
777+ def test_regenerate_agent_name_batch_api_bad_request (mocker , mock_auth_header ):
778+ mock_impl = mocker .patch (
779+ "apps.agent_app.regenerate_agent_name_batch_impl" ,
780+ new_callable = mocker .AsyncMock ,
781+ )
782+ mock_impl .side_effect = ValueError ("invalid" )
783+
784+ resp = config_client .post (
785+ "/agent/regenerate_name/batch" ,
786+ json = {"items" : [{"agent_id" : 1 , "name" : "AgentA" }]},
787+ headers = mock_auth_header ,
788+ )
789+
790+ assert resp .status_code == 400
791+ assert resp .json ()["detail" ] == "invalid"
792+
793+
794+ def test_regenerate_agent_name_batch_api_error (mocker , mock_auth_header ):
795+ mock_impl = mocker .patch (
796+ "apps.agent_app.regenerate_agent_name_batch_impl" ,
797+ new_callable = mocker .AsyncMock ,
798+ )
799+ mock_impl .side_effect = Exception ("boom" )
800+
801+ resp = config_client .post (
802+ "/agent/regenerate_name/batch" ,
803+ json = {"items" : [{"agent_id" : 1 , "name" : "AgentA" }]},
804+ headers = mock_auth_header ,
805+ )
806+
807+ assert resp .status_code == 500
808+ assert "Agent name batch regenerate error" in resp .json ()["detail" ]
0 commit comments