Skip to content

Commit

Permalink
Merge branch 'trigger/Api_Crud_Creation' of github.com:sireto/cardano…
Browse files Browse the repository at this point in the history
…-autonomous-agent into trigger/Api_Crud_Creation

issue resolved
  • Loading branch information
roshan00017 committed Apr 4, 2024
2 parents 7b35b4c + 9097ce3 commit 012fa5a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 012fa5a

Please sign in to comment.