diff --git a/autonomous_agent_api/backend/app/repositories/agent_repository.py b/autonomous_agent_api/backend/app/repositories/agent_repository.py index e37328bf3..ea9cff560 100644 --- a/autonomous_agent_api/backend/app/repositories/agent_repository.py +++ b/autonomous_agent_api/backend/app/repositories/agent_repository.py @@ -60,4 +60,4 @@ async def remove_agent(self, agent_id: str) -> bool: await self.db.prisma.agstringent.update( where={"id": agent_id}, data={"deleted_at": datetime.now(timezone.utc)} ) - return True + return True \ No newline at end of file diff --git a/autonomous_agent_api/tests/unit/app/controllers/agent_router_test/test_agent_list.py b/autonomous_agent_api/tests/unit/app/controllers/agent_router_test/test_agent_list.py index 6f37e83d6..b99816a41 100644 --- a/autonomous_agent_api/tests/unit/app/controllers/agent_router_test/test_agent_list.py +++ b/autonomous_agent_api/tests/unit/app/controllers/agent_router_test/test_agent_list.py @@ -43,4 +43,4 @@ async def test_list_agents_with_two_agents(agent_service, agent_router): agent_service.list_agents.assert_called_once() # Assert that the returned agents match the mock_agents - assert agents == mock_agents + assert agents == mock_agents \ No newline at end of file diff --git a/autonomous_agent_api/tests/unit/app/controllers/agent_router_test/test_create_agent.py b/autonomous_agent_api/tests/unit/app/controllers/agent_router_test/test_create_agent.py index 18842ad68..b99816a41 100644 --- a/autonomous_agent_api/tests/unit/app/controllers/agent_router_test/test_create_agent.py +++ b/autonomous_agent_api/tests/unit/app/controllers/agent_router_test/test_create_agent.py @@ -1,46 +1,46 @@ -from pydantic import ValidationError +from unittest.mock import MagicMock, AsyncMock + from backend.app.controllers.agent_router import AgentRouter -from backend.app.models.AgentDto.agent_dto import AgentCreateDTO from backend.app.models.AgentDto.response_dto import AgentResponse from backend.app.services.agent_service import AgentService -from unittest.mock import MagicMock, AsyncMock -import pytest - - -@pytest.mark.asyncio -class TestAgentCreateRouter: - @pytest.fixture - def agent_service(self): - return MagicMock(spec=AgentService) - @pytest.fixture - def agent_router(self, agent_service): - return AgentRouter(agent_service) - - async def test_update_agent_with_valid_details(self, agent_service, agent_router): - agent_id = "018e8909-549b-7b9f-8fab-5499f53a8244" - agent_data = AgentCreateDTO(name="Updated Agent", action=["Test Description"]) - updated_agent = AgentResponse(id=agent_id, name="Updated Agent", action=["Test Description"]) - - agent_service.update_agent = AsyncMock(return_value=updated_agent) - - result = await agent_router.update_agent(agent_id, agent_data) - - agent_service.update_agent.assert_called_once_with(agent_id, agent_data) +import pytest - assert result == updated_agent - async def test_update_agent_should_fail_with_invalid_details(self, agent_service, agent_router): - with pytest.raises(ValidationError): - # Mock data - agent_id = "018e8909-549b-7b9f-8fab-5499f53a8244" - agent_data = AgentCreateDTO(name="", action=["Test Description"]) - updated_agent = AgentResponse(id=agent_id, name="Agent", action=["Test Description"]) +@pytest.fixture +def agent_service(): + mock_service = MagicMock(spec=AgentService) + return mock_service - agent_service.update_agent = AsyncMock(return_value=updated_agent) - result = await agent_router.update_agent(agent_id, agent_data) +@pytest.fixture +def agent_router(agent_service): + return AgentRouter(agent_service) - agent_service.update_agent.assert_called_once_with(agent_id, agent_data) - assert result == updated_agent +# test for listing the agents +@pytest.mark.asyncio +async def test_list_agents_with_two_agents(agent_service, agent_router): + # Mocking the list_agents method to return a list of mock agents + mock_agents = [ + AgentResponse( + id="018e8908-5dc9-78c9-b71a-37ebd2149394", + name="Agent 1", + action=["Description 1"], + ), + AgentResponse( + id="018e8908-7563-7e8a-b87c-b33ac6e6c872", + name="Agent 2", + action=["Description 2"], + ), + ] + agent_service.list_agents = AsyncMock(return_value=mock_agents) + + # Call the list_agents method + agents = await agent_router.list_agents() + + # calling method + agent_service.list_agents.assert_called_once() + + # Assert that the returned agents match the mock_agents + assert agents == mock_agents \ No newline at end of file diff --git a/autonomous_agent_api/tests/unit/app/controllers/agent_router_test/test_editing_agent.py b/autonomous_agent_api/tests/unit/app/controllers/agent_router_test/test_editing_agent.py index 0b5d15bcc..f8c152d29 100644 --- a/autonomous_agent_api/tests/unit/app/controllers/agent_router_test/test_editing_agent.py +++ b/autonomous_agent_api/tests/unit/app/controllers/agent_router_test/test_editing_agent.py @@ -46,4 +46,4 @@ async def test_update_agent_should_fail_with_invalid_details(self, agent_service agent_service.update_agent.assert_called_once_with(agent_id, agent_data) - assert result == updated_agent + assert result == updated_agent \ No newline at end of file