-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'trigger/Api_Crud_Creation' of github.com:sireto/cardano…
…-autonomous-agent into trigger/Api_Crud_Creation issue resolved
- Loading branch information
Showing
4 changed files
with
39 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 36 additions & 36 deletions
72
autonomous_agent_api/tests/unit/app/controllers/agent_router_test/test_create_agent.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters