Skip to content

Commit

Permalink
mock openai in test image gen (Significant-Gravitas#3285)
Browse files Browse the repository at this point in the history
  • Loading branch information
waynehamadi authored Apr 26, 2023
1 parent 3ae6c1b commit 4241fbb
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions tests/test_agent_manager.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from typing import List

import pytest

from autogpt.agent.agent_manager import AgentManager
from tests.utils import requires_api_key
from autogpt.llm_utils import create_chat_completion


@pytest.fixture
Expand All @@ -29,31 +27,37 @@ def model():
return "gpt-3.5-turbo"


@requires_api_key("OPENAI_API_KEY")
@pytest.fixture(autouse=True)
def mock_create_chat_completion(mocker):
mock_create_chat_completion = mocker.patch(
"autogpt.agent.agent_manager.create_chat_completion",
wraps=create_chat_completion,
)
mock_create_chat_completion.return_value = "irrelevant"
return mock_create_chat_completion


def test_create_agent(agent_manager, task, prompt, model):
key, agent_reply = agent_manager.create_agent(task, prompt, model)
assert isinstance(key, int)
assert isinstance(agent_reply, str)
assert key in agent_manager.agents


@requires_api_key("OPENAI_API_KEY")
def test_message_agent(agent_manager, task, prompt, model):
key, _ = agent_manager.create_agent(task, prompt, model)
user_message = "Please translate 'Good morning' to French."
agent_reply = agent_manager.message_agent(key, user_message)
assert isinstance(agent_reply, str)


@requires_api_key("OPENAI_API_KEY")
def test_list_agents(agent_manager, task, prompt, model):
key, _ = agent_manager.create_agent(task, prompt, model)
agents_list = agent_manager.list_agents()
assert isinstance(agents_list, list)
assert (key, task) in agents_list


@requires_api_key("OPENAI_API_KEY")
def test_delete_agent(agent_manager, task, prompt, model):
key, _ = agent_manager.create_agent(task, prompt, model)
success = agent_manager.delete_agent(key)
Expand Down

0 comments on commit 4241fbb

Please sign in to comment.