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 | """Tests for ``composio.toolkits.get_many`` and ``composio.toolkits.changelog``.""" |
| 2 | |
| 3 | from unittest.mock import Mock |
| 4 | |
| 5 | import pytest |
| 6 | from composio_client import omit |
| 7 | |
| 8 | from composio.core.models.toolkits import Toolkits |
| 9 | from tests.conftest import mock_http_client |
| 10 | |
| 11 | |
| 12 | @pytest.fixture |
| 13 | def mock_client() -> Mock: |
| 14 | client = mock_http_client() |
| 15 | client.toolkits = Mock() |
| 16 | client.connected_accounts = Mock() |
| 17 | return client |
| 18 | |
| 19 | |
| 20 | @pytest.fixture |
| 21 | def toolkits(mock_client: Mock) -> Toolkits: |
| 22 | return Toolkits(client=mock_client) |
| 23 | |
| 24 | |
| 25 | class TestToolkitsGetMany: |
| 26 | def test_get_many_by_slugs(self, toolkits, mock_client): |
| 27 | mock_client.toolkits.retrieve_multi.return_value = Mock(items=["gh", "sl"]) |
| 28 | |
| 29 | result = toolkits.get_many(("github", "slack")) |
| 30 | |
| 31 | assert result == ["gh", "sl"] |
| 32 | mock_client.toolkits.retrieve_multi.assert_called_once_with( |
| 33 | toolkits=["github", "slack"], |
| 34 | category=omit, |
| 35 | managed_by=omit, |
| 36 | sort_by=omit, |
| 37 | limit=omit, |
| 38 | cursor=omit, |
| 39 | ) |
| 40 | |
| 41 | def test_get_many_forwards_filters(self, toolkits, mock_client): |
| 42 | toolkits.get_many( |
| 43 | ["github"], |
| 44 | category="developer-tools", |
| 45 | managed_by="composio", |
| 46 | sort_by="usage", |
| 47 | limit=10, |
| 48 | cursor="c1", |
| 49 | ) |
| 50 | |
| 51 | mock_client.toolkits.retrieve_multi.assert_called_once_with( |
| 52 | toolkits=["github"], |
| 53 | category="developer-tools", |
| 54 | managed_by="composio", |
| 55 | sort_by="usage", |
| 56 | limit=10, |
| 57 | cursor="c1", |
| 58 | ) |
| 59 | |
| 60 | |
| 61 | class TestToolkitsChangelog: |
| 62 | def test_changelog(self, toolkits, mock_client): |
| 63 | mock_client.toolkits.retrieve_changelog.return_value = "changelog" |
| 64 | |
| 65 | assert toolkits.changelog() == "changelog" |
| 66 | mock_client.toolkits.retrieve_changelog.assert_called_once_with() |
| 67 | |
| 68 | |
| 69 | class TestToolkitsScopes: |
| 70 | def test_recommend_scopes_passes_params_through(self, toolkits, mock_client): |
| 71 | mock_client.toolkits.recommend_scopes.return_value = "recommendation" |
| 72 | |
| 73 | result = toolkits.recommend_scopes( |
| 74 | "gmail", |
| 75 | tools=["GMAIL_SEND_EMAIL"], |
| 76 | auth_scheme="OAUTH2", |
| 77 | grant_context={"account_type": "Google Workspace"}, |
| 78 | available_scopes=["openid"], |
| 79 | ) |
| 80 | |
| 81 | assert result == "recommendation" |
| 82 | mock_client.toolkits.recommend_scopes.assert_called_once_with( |
| 83 | "gmail", |
| 84 | tools=["GMAIL_SEND_EMAIL"], |
| 85 | auth_scheme="OAUTH2", |
| 86 | grant_context={"account_type": "Google Workspace"}, |
| 87 | available_scopes=["openid"], |
| 88 | ) |
| 89 | |
| 90 | def test_list_grant_contexts_passes_params_through(self, toolkits, mock_client): |
| 91 | mock_client.toolkits.retrieve_scopes_grant_context.return_value = "contexts" |
| 92 | |
| 93 | result = toolkits.list_grant_contexts( |
| 94 | "gmail", auth_scheme="OAUTH2", toolkit_version="20250909_00" |
| 95 | ) |
| 96 | |
| 97 | assert result == "contexts" |
| 98 | mock_client.toolkits.retrieve_scopes_grant_context.assert_called_once_with( |
| 99 | "gmail", auth_scheme="OAUTH2", toolkit_version="20250909_00" |
| 100 | ) |
| 101 | |
| 102 | def test_list_grant_contexts_without_params(self, toolkits, mock_client): |
| 103 | toolkits.list_grant_contexts("gmail") |
| 104 | |
| 105 | mock_client.toolkits.retrieve_scopes_grant_context.assert_called_once_with( |
| 106 | "gmail" |
| 107 | ) |