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
| 1 | """Request body sent by ``Tools.proxy``.""" |
| 2 | |
| 3 | import json |
| 4 | import typing as t |
| 5 | from unittest.mock import Mock |
| 6 | |
| 7 | import httpx |
| 8 | import pytest |
| 9 | from composio_client import ProjectAuth |
| 10 | |
| 11 | from composio.client import HttpClient |
| 12 | from composio.core.models.base import allow_tracking |
| 13 | from composio.core.models.tools import Tools |
| 14 | |
| 15 | |
| 16 | @pytest.fixture(autouse=True) |
| 17 | def disable_telemetry(): |
| 18 | token = allow_tracking.set(False) |
| 19 | yield |
| 20 | allow_tracking.reset(token) |
| 21 | |
| 22 | |
| 23 | def _proxy_body(**kwargs: t.Any) -> t.Dict[str, t.Any]: |
| 24 | requests: t.List[httpx.Request] = [] |
| 25 | |
| 26 | def handler(request: httpx.Request) -> httpx.Response: |
| 27 | requests.append(request) |
| 28 | return httpx.Response(200, json={"status": 200, "data": {}}) |
| 29 | |
| 30 | client = HttpClient( |
| 31 | provider="test", |
| 32 | auth=ProjectAuth("sk-test"), |
| 33 | base_url="https://backend.invalid", |
| 34 | http_client=httpx.Client(transport=httpx.MockTransport(handler)), |
| 35 | ) |
| 36 | Tools(client=client, provider=Mock()).proxy( |
| 37 | endpoint="/any", method="GET", connected_account_id="ca_123", **kwargs |
| 38 | ) |
| 39 | assert len(requests) == 1 |
| 40 | return json.loads(requests[0].content) |
| 41 | |
| 42 | |
| 43 | def test_proxy_forwards_user_id() -> None: |
| 44 | body = _proxy_body(user_id="user-123") |
| 45 | |
| 46 | assert body["connected_account_id"] == "ca_123" |
| 47 | assert body["user_id"] == "user-123" |
| 48 | |
| 49 | |
| 50 | def test_proxy_omits_user_id_when_not_passed() -> None: |
| 51 | assert "user_id" not in _proxy_body() |