@devries-cameron20 / composio Mirror · read-only / commits / 80e09ad0f
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, 18:30 UTC

test: add unit tests for pydantic utils (none_to_omit, parse_pydantic_error) (#3784)

## Description `composio/utils/pydantic.py` had no dedicated test module. This adds `tests/test_pydantic_utils.py` covering: - `none_to_omit` converting `None` to the `omit` sentinel while passing through other values (including falsy `0`/`""`) - `parse_pydantic_error` listing missing fields, reporting type errors with the offending parameter, and handling both together No source changes. ## Verification `pytest tests/test_pydantic_utils.py` - 5 passed. `ruff check` / `ruff format --check` clean. Co-authored-by: Alberto Schiabel <jkomyno@users.noreply.github.com>

eeshsaxena committed Jul 28, 2026 at 13:05 UTC 80e09ad0f0392874c4a0bea7d866c594f48e670b
1 file changed +50
python/tests/test_pydantic_utils.py new
+50
@@ -0,0 +1,50 @@
1 +"""Tests for the pydantic utility module."""
2 +
3 +import pydantic
4 +import pytest
5 +from composio_client import omit
6 +
7 +from composio.utils.pydantic import none_to_omit, parse_pydantic_error
8 +
9 +
10 +class _Model(pydantic.BaseModel):
11 + name: str
12 + age: int
13 +
14 +
15 +def test_none_to_omit_converts_none():
16 + assert none_to_omit(None) is omit
17 +
18 +
19 +def test_none_to_omit_passes_values_through():
20 + assert none_to_omit("hello") == "hello"
21 + assert none_to_omit(42) == 42
22 + # Falsy-but-not-None values are preserved (not converted to omit).
23 + assert none_to_omit(0) == 0
24 + assert none_to_omit("") == ""
25 +
26 +
27 +def _validation_error(**kwargs) -> pydantic.ValidationError:
28 + with pytest.raises(pydantic.ValidationError) as exc_info:
29 + _Model(**kwargs)
30 + return exc_info.value
31 +
32 +
33 +def test_parse_pydantic_error_lists_missing_fields():
34 + message = parse_pydantic_error(_validation_error(age=5))
35 + assert "Invalid request data provided" in message
36 + assert "missing" in message
37 + assert "name" in message
38 +
39 +
40 +def test_parse_pydantic_error_reports_type_errors_with_param():
41 + message = parse_pydantic_error(_validation_error(name="a", age="not-an-int"))
42 + # A non-missing error names the offending parameter.
43 + assert "age" in message
44 + assert "missing" not in message
45 +
46 +
47 +def test_parse_pydantic_error_handles_missing_and_other_together():
48 + message = parse_pydantic_error(_validation_error(age="not-an-int"))
49 + assert "name" in message # missing
50 + assert "age" in message # type error