Files
arc53--docsgpt/tests/agents/test_agent_creator.py
T
wehub-resource-sync fed8b2eed7
Backend release / release (push) Waiting to run
Bandit Security Scan / bandit_scan (push) Waiting to run
Build and push multi-arch DocsGPT Docker image / build (linux/amd64, ubuntu-latest, amd64) (push) Waiting to run
Build and push multi-arch DocsGPT Docker image / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Waiting to run
Build and push multi-arch DocsGPT Docker image / manifest (push) Blocked by required conditions
Build and push DocsGPT FE Docker image for development / build (linux/amd64, ubuntu-latest, amd64) (push) Waiting to run
Build and push DocsGPT FE Docker image for development / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Waiting to run
Build and push DocsGPT FE Docker image for development / manifest (push) Blocked by required conditions
Python linting / ruff (push) Waiting to run
Run python tests with pytest / Run tests and count coverage (3.12) (push) Waiting to run
React Widget Build / build (push) Waiting to run
chore: import upstream snapshot with attribution
2026-07-13 13:28:29 +08:00

53 lines
2.3 KiB
Python

import pytest
from application.agents.agent_creator import AgentCreator
from application.agents.classic_agent import ClassicAgent
@pytest.mark.unit
class TestAgentCreator:
def test_create_classic_agent(self, agent_base_params):
agent = AgentCreator.create_agent("classic", **agent_base_params)
assert isinstance(agent, ClassicAgent)
assert agent.endpoint == agent_base_params["endpoint"]
assert agent.llm_name == agent_base_params["llm_name"]
assert agent.model_id == agent_base_params["model_id"]
def test_create_react_falls_back_to_classic(self, agent_base_params):
agent = AgentCreator.create_agent("react", **agent_base_params)
assert isinstance(agent, ClassicAgent)
def test_create_agent_case_insensitive(self, agent_base_params):
agent_upper = AgentCreator.create_agent("CLASSIC", **agent_base_params)
agent_mixed = AgentCreator.create_agent("ClAsSiC", **agent_base_params)
assert isinstance(agent_upper, ClassicAgent)
assert isinstance(agent_mixed, ClassicAgent)
def test_create_agent_invalid_type(self, agent_base_params):
with pytest.raises(ValueError, match="No agent class found for type"):
AgentCreator.create_agent("invalid_agent_type", **agent_base_params)
def test_agent_registry_contains_expected_agents(self):
assert "classic" in AgentCreator.agents
assert "react" in AgentCreator.agents
assert AgentCreator.agents["classic"] == ClassicAgent
def test_create_agent_with_optional_params(self, agent_base_params):
agent_base_params["user_api_key"] = "user_key_123"
agent_base_params["chat_history"] = [{"prompt": "test", "response": "test"}]
agent_base_params["json_schema"] = {"type": "object"}
agent = AgentCreator.create_agent("classic", **agent_base_params)
assert agent.user_api_key == "user_key_123"
assert len(agent.chat_history) == 1
assert agent.json_schema == {"type": "object"}
def test_create_agent_with_attachments(self, agent_base_params):
attachments = [{"name": "file.txt", "content": "test"}]
agent_base_params["attachments"] = attachments
agent = AgentCreator.create_agent("classic", **agent_base_params)
assert agent.attachments == attachments