Files
cleveragents-core/tests/features/steps/network_steps.py
T

60 lines
1.9 KiB
Python

import asyncio
import os
from pathlib import Path
from unittest.mock import AsyncMock
from unittest.mock import patch
import yaml
from behave import given
from behave import then
from behave import when
from cleveragents.core.application import CleverAgentsApp
@given('a configuration file "{config_file}"')
def step_impl_config_file(context, config_file):
# Create a minimal but valid CleverAgents configuration file
config_data = {
"version": "1.0",
"cleveragents": {"default_router": "default_router"},
"agents": {
"dummy": {
"type": "llm",
"config": {
"provider": "openai",
"model": "test-model",
"api_key": "mock-api-key",
},
}
},
"routes": {
"default_router": [
{"source": "input", "destination": "dummy"},
{"source": "dummy", "destination": "output"},
]
},
}
config_path = Path(config_file)
config_path.parent.mkdir(parents=True, exist_ok=True)
with open(config_path, "w", encoding="utf-8") as f:
yaml.dump(config_data, f)
context.config_file_path = config_file
@when('I process the message "{message}"')
def step_impl_process_message(context, message):
# Patch the router's process_message method to isolate the app logic
with patch(
"cleveragents.routing.router.Router.process_message",
new=AsyncMock(return_value="Test Response"),
):
app = CleverAgentsApp([Path(context.config_file_path)], verbose=False)
context.response = asyncio.run(app.run_single_shot(message))
@then("I should receive a non-empty network response")
def step_impl_check_response(context):
assert hasattr(context, "response"), "Response not found in context."
assert context.response, "Received an empty response."