@devries-cameron20 / composio Mirror · read-only
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 03:37 UTC

next
py 44 lines 1.57 KB
Raw
1 """Tests for normalize_tool_arguments (issue #2406)."""
2
3 import pytest
4
5 from composio.exceptions import InvalidParams
6 from composio.utils.shared import normalize_tool_arguments
7
8 pytestmark = pytest.mark.core
9
10
11 class TestNormalizeToolArguments:
12 def test_dict_is_returned_unchanged(self):
13 payload = {"to": "a@b.com", "subject": "hi"}
14 assert normalize_tool_arguments(payload) is payload
15
16 def test_json_string_is_parsed(self):
17 payload = {"to": "a@b.com", "subject": "hi", "body": "Hello"}
18 assert (
19 normalize_tool_arguments(
20 '{"to": "a@b.com", "subject": "hi", "body": "Hello"}'
21 )
22 == payload
23 )
24
25 def test_none_becomes_empty_dict(self):
26 assert normalize_tool_arguments(None) == {}
27
28 @pytest.mark.parametrize("value", ["", " ", "\n\t "])
29 def test_empty_string_becomes_empty_dict(self, value):
30 assert normalize_tool_arguments(value) == {}
31
32 def test_malformed_json_string_raises(self):
33 with pytest.raises(InvalidParams, match="not valid JSON"):
34 normalize_tool_arguments('{"to": "a@b.com"')
35
36 @pytest.mark.parametrize("value", ["[1, 2, 3]", "42", '"hello"'])
37 def test_non_object_json_raises(self, value):
38 with pytest.raises(InvalidParams, match="must resolve to an object"):
39 normalize_tool_arguments(value)
40
41 @pytest.mark.parametrize("value", [[1, 2, 3], 42, True])
42 def test_non_dict_value_raises(self, value):
43 with pytest.raises(InvalidParams, match="must resolve to an object"):
44 normalize_tool_arguments(value)