forked from ComposioHQ/composio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_actions.py
77 lines (62 loc) · 2.41 KB
/
test_actions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
Test actions command group.
"""
import typing as t
from unittest import mock
import pytest
from composio.client.collections import Actions
from tests.test_cli.base import BaseCliTest
class TestListActions(BaseCliTest):
"""Test list actions."""
@pytest.mark.parametrize(
argnames="arguments,exptected_outputs,unexptected_outputs",
argvalues=(
(tuple(), ("GMAIL_", "GITHUB_"), tuple()), # List all apps
(
("--app", "SLACK"),
("SLACK_",),
("GMAIL_", "GITHUB_"),
), # Filter by a specific app
(
("--tag", "repos"),
("GITHUB_",),
("GMAIL_",),
), # Filter by a specific app
),
)
@mock.patch("click.prompt", return_value="n")
def test_list_all( # pylint: disable=unused-argument
self,
patch: t.Any,
arguments: t.Tuple[str, ...],
exptected_outputs: t.Tuple[str, ...],
unexptected_outputs: t.Tuple[str, ...],
) -> None:
"""Test list all actions."""
result = self.run("actions", *arguments)
assert result.exit_code == 0, result.stderr
for output in exptected_outputs:
assert output in result.stdout
for output in unexptected_outputs:
assert output not in result.stdout
def test_tag_not_found(self) -> None:
"""Test list all actions."""
with mock.patch.object(Actions, "get", return_value=[]):
self.run("actions", "--tag", "repo")
self.assert_exit_code(code=1)
self.assert_stderr("Could not find actions with following tags {'repo'}")
@pytest.mark.skip(reason="Limit filter is not working atm!")
@mock.patch("click.prompt", return_value="n")
def test_limit(self, patch: t.Any) -> None: # pylint: disable=unused-argument
"""Test limit flag."""
result = self.run("actions", "--use-case", "github", "--limit", "5")
assert result.exit_code == 0
assert len(result.output.splitlines()) == 6
def test_copy(self) -> None:
"""Test copy flag."""
def _assert_copy(text: str) -> None:
"""Assert copy function call."""
assert "Action.GITHUB" in text
assert "Action.SLACK" not in text
with mock.patch("pyperclip.copy", new=_assert_copy):
self.run("actions", "--app", "--github", "--copy")