Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | """Tests for the ``composio.logs`` namespace.""" |
| 2 | |
| 3 | from unittest.mock import Mock |
| 4 | |
| 5 | import pytest |
| 6 | |
| 7 | from composio.client.types import ( |
| 8 | log_create_tool_execution_response, |
| 9 | log_retrieve_tool_execution_response, |
| 10 | ) |
| 11 | from composio.core.models.logs import Logs |
| 12 | from tests.conftest import mock_http_client |
| 13 | |
| 14 | |
| 15 | @pytest.fixture |
| 16 | def mock_client() -> Mock: |
| 17 | client = mock_http_client() |
| 18 | client.logs = Mock() |
| 19 | return client |
| 20 | |
| 21 | |
| 22 | @pytest.fixture |
| 23 | def logs(mock_client: Mock) -> Logs: |
| 24 | return Logs(client=mock_client) |
| 25 | |
| 26 | |
| 27 | class TestLogs: |
| 28 | def test_search_preserves_instant_charge(self, logs, mock_client): |
| 29 | mock_client.logs.create_tool_execution.return_value = log_create_tool_execution_response.LogCreateToolExecutionResponse.model_validate( |
| 30 | { |
| 31 | "logs": [ |
| 32 | { |
| 33 | "id": "log_1", |
| 34 | "timestamp": "2026-01-01T00:00:00Z", |
| 35 | "type": "tool.execution", |
| 36 | "status": "success", |
| 37 | "level": "info", |
| 38 | "metadata": {"instant_charge": "0.012"}, |
| 39 | "metrics": {}, |
| 40 | "parent": None, |
| 41 | } |
| 42 | ], |
| 43 | "next_cursor": None, |
| 44 | } |
| 45 | ) |
| 46 | |
| 47 | result = logs.search() |
| 48 | |
| 49 | assert result.logs[0].metadata.instant_charge == "0.012" |
| 50 | |
| 51 | def test_search_passes_params_through(self, logs, mock_client): |
| 52 | mock_client.logs.create_tool_execution.return_value = "page" |
| 53 | |
| 54 | result = logs.search( |
| 55 | limit=20, |
| 56 | cursor="c1", |
| 57 | filters=[{"field": "toolkit_slug", "value": "github"}], |
| 58 | time_range={"from": 1, "to": 2}, |
| 59 | ) |
| 60 | |
| 61 | assert result == "page" |
| 62 | mock_client.logs.create_tool_execution.assert_called_once_with( |
| 63 | limit=20, |
| 64 | cursor="c1", |
| 65 | filters=[{"field": "toolkit_slug", "value": "github"}], |
| 66 | time_range={"from": 1, "to": 2}, |
| 67 | ) |
| 68 | |
| 69 | def test_search_without_params(self, logs, mock_client): |
| 70 | logs.search() |
| 71 | |
| 72 | mock_client.logs.create_tool_execution.assert_called_once_with() |
| 73 | |
| 74 | def test_get(self, logs, mock_client): |
| 75 | mock_client.logs.retrieve_tool_execution.return_value = "log" |
| 76 | |
| 77 | assert logs.get("log_123") == "log" |
| 78 | mock_client.logs.retrieve_tool_execution.assert_called_once_with("log_123") |
| 79 | |
| 80 | def test_get_preserves_instant_charge(self, logs, mock_client): |
| 81 | mock_client.logs.retrieve_tool_execution.return_value = log_retrieve_tool_execution_response.LogRetrieveToolExecutionResponse.model_validate( |
| 82 | { |
| 83 | "id": "log_1", |
| 84 | "timestamp": "2026-01-01T00:00:00Z", |
| 85 | "type": "tool.execution", |
| 86 | "status": "success", |
| 87 | "level": "info", |
| 88 | "metadata": {"instant_charge": "0.012"}, |
| 89 | "metrics": {}, |
| 90 | "parent": None, |
| 91 | "context": {}, |
| 92 | "source": {}, |
| 93 | "data": {}, |
| 94 | } |
| 95 | ) |
| 96 | |
| 97 | result = logs.get("log_1") |
| 98 | |
| 99 | assert result.metadata.instant_charge == "0.012" |