|
23 | 23 | import pytest_asyncio
|
24 | 24 | from aiohttp import ClientSession
|
25 | 25 | from aioresponses import aioresponses
|
26 |
| -from pydantic import ValidationError |
| 26 | +from pydantic import BaseModel, ValidationError |
27 | 27 |
|
28 | 28 | from toolbox_core.protocol import ParameterSchema
|
29 | 29 | from toolbox_core.tool import ToolboxTool, create_func_docstring, resolve_value
|
@@ -578,6 +578,24 @@ def test_toolbox_tool_underscore_client_headers_property(toolbox_tool: ToolboxTo
|
578 | 578 | client_headers["new_header"] = "new_value"
|
579 | 579 |
|
580 | 580 |
|
| 581 | +def test_toolbox_tool_underscore_pydantic_model_property(toolbox_tool: ToolboxTool): |
| 582 | + """Tests the _pydantic_model property returns the correct Pydantic model.""" |
| 583 | + pydantic_model = toolbox_tool._pydantic_model |
| 584 | + assert issubclass(pydantic_model, BaseModel) |
| 585 | + assert pydantic_model.__name__ == TEST_TOOL_NAME |
| 586 | + |
| 587 | + # Test that the model can validate expected data |
| 588 | + valid_data = {"message": "test", "count": 10} |
| 589 | + validated_data = pydantic_model.model_validate(valid_data) |
| 590 | + assert validated_data.message == "test" |
| 591 | + assert validated_data.count == 10 |
| 592 | + |
| 593 | + # Test that the model raises ValidationError for invalid data |
| 594 | + invalid_data = {"message": 123, "count": "not_an_int"} |
| 595 | + with pytest.raises(ValidationError): |
| 596 | + pydantic_model.model_validate(invalid_data) |
| 597 | + |
| 598 | + |
581 | 599 | # --- Test for the HTTP Warning ---
|
582 | 600 | @pytest.mark.parametrize(
|
583 | 601 | "trigger_condition_params",
|
|
0 commit comments