Spaces:
Running
Running
File size: 1,040 Bytes
79df050 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | import json
from unittest.mock import AsyncMock, patch
import pytest
from features.mcp.tools.environment.context_tool import EnvironmentContextTool
@pytest.mark.asyncio
async def test_environment_context_tool_requires_injected_user_id():
tool = EnvironmentContextTool()
result = await tool.execute({})
assert result["success"] is False
assert "_user_id" in result["error"]
@pytest.mark.asyncio
async def test_environment_context_tool_reads_real_user_context():
tool = EnvironmentContextTool()
fetcher = AsyncMock(
return_value={
"success": True,
"context": {"city": "Taipei", "tz": "Asia/Taipei"},
}
)
with patch("core.database.get_user_env_current", fetcher):
result = await tool.execute({"_user_id": "user-1"})
assert result["success"] is True
assert result["data"] == {"city": "Taipei", "tz": "Asia/Taipei"}
assert json.loads(result["content"]) == {"city": "Taipei", "tz": "Asia/Taipei"}
fetcher.assert_awaited_once_with("user-1")
|