-
Notifications
You must be signed in to change notification settings - Fork 253
Expand file tree
/
Copy pathtest_issue_commenter_tool.py
More file actions
132 lines (125 loc) · 6.32 KB
/
test_issue_commenter_tool.py
File metadata and controls
132 lines (125 loc) · 6.32 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
#
# SPDX-License-Identifier: Apache-2.0
from haystack.utils import Secret
from haystack_integrations.prompts.github.issue_commenter_prompt import ISSUE_COMMENTER_PROMPT, ISSUE_COMMENTER_SCHEMA
from haystack_integrations.tools.github.issue_commenter_tool import GitHubIssueCommenterTool
from haystack_integrations.tools.github.utils import message_handler
class TestGitHubIssueCommenterTool:
def test_init(self, monkeypatch):
monkeypatch.setenv("GITHUB_TOKEN", "test-token")
tool = GitHubIssueCommenterTool()
assert tool.name == "issue_commenter"
assert tool.description == ISSUE_COMMENTER_PROMPT
assert tool.parameters == ISSUE_COMMENTER_SCHEMA
assert tool.retry_attempts == 2
assert tool.outputs_to_string is None
assert tool.inputs_from_state is None
assert tool.outputs_to_state is None
def test_from_dict(self, monkeypatch):
monkeypatch.setenv("GITHUB_TOKEN", "test-token")
tool_dict = {
"type": "haystack_integrations.tools.github.issue_commenter_tool.GitHubIssueCommenterTool",
"data": {
"name": "issue_commenter",
"description": ISSUE_COMMENTER_PROMPT,
"parameters": ISSUE_COMMENTER_SCHEMA,
"github_token": {"env_vars": ["GITHUB_TOKEN"], "strict": True, "type": "env_var"},
"raise_on_failure": True,
"retry_attempts": 2,
"outputs_to_string": None,
"inputs_from_state": None,
"outputs_to_state": None,
},
}
tool = GitHubIssueCommenterTool.from_dict(tool_dict)
assert tool.name == "issue_commenter"
assert tool.description == ISSUE_COMMENTER_PROMPT
assert tool.parameters == ISSUE_COMMENTER_SCHEMA
assert tool.github_token == Secret.from_env_var("GITHUB_TOKEN")
assert tool.raise_on_failure
assert tool.retry_attempts == 2
assert tool.outputs_to_string is None
assert tool.inputs_from_state is None
assert tool.outputs_to_state is None
def test_to_dict(self, monkeypatch):
monkeypatch.setenv("GITHUB_TOKEN", "test-token")
tool = GitHubIssueCommenterTool()
tool_dict = tool.to_dict()
assert tool_dict["type"] == "haystack_integrations.tools.github.issue_commenter_tool.GitHubIssueCommenterTool"
assert tool_dict["data"]["name"] == "issue_commenter"
assert tool_dict["data"]["description"] == ISSUE_COMMENTER_PROMPT
assert tool_dict["data"]["parameters"] == ISSUE_COMMENTER_SCHEMA
assert tool_dict["data"]["github_token"] == {
"env_vars": ["GITHUB_TOKEN"],
"strict": True,
"type": "env_var",
}
assert tool_dict["data"]["raise_on_failure"]
assert tool_dict["data"]["retry_attempts"] == 2
assert tool_dict["data"]["outputs_to_string"] is None
assert tool_dict["data"]["inputs_from_state"] is None
assert tool_dict["data"]["outputs_to_state"] is None
def test_to_dict_with_extra_params(self, monkeypatch):
monkeypatch.setenv("GITHUB_TOKEN", "test-token")
tool = GitHubIssueCommenterTool(
name="test_issue_commenter",
description="Test description",
parameters={"type": "object", "properties": {}},
github_token=None,
raise_on_failure=False,
retry_attempts=3,
outputs_to_string={"handler": message_handler},
inputs_from_state={"repository": "repo"},
outputs_to_state={"documents": {"source": "success", "handler": message_handler}},
)
tool_dict = tool.to_dict()
assert tool_dict["type"] == "haystack_integrations.tools.github.issue_commenter_tool.GitHubIssueCommenterTool"
assert tool_dict["data"]["name"] == "test_issue_commenter"
assert tool_dict["data"]["description"] == "Test description"
assert tool_dict["data"]["parameters"] == {"type": "object", "properties": {}}
assert tool_dict["data"]["github_token"] is None
assert tool_dict["data"]["raise_on_failure"] is False
assert tool_dict["data"]["retry_attempts"] == 3
assert (
tool_dict["data"]["outputs_to_string"]["handler"]
== "haystack_integrations.tools.github.utils.message_handler"
)
assert tool_dict["data"]["inputs_from_state"] == {"repository": "repo"}
assert tool_dict["data"]["outputs_to_state"]["documents"]["source"] == "success"
assert (
tool_dict["data"]["outputs_to_state"]["documents"]["handler"]
== "haystack_integrations.tools.github.utils.message_handler"
)
def test_from_dict_with_extra_params(self, monkeypatch):
monkeypatch.setenv("GITHUB_TOKEN", "test-token")
tool_dict = {
"type": "haystack_integrations.tools.github.issue_commenter_tool.GitHubIssueCommenterTool",
"data": {
"name": "test_issue_commenter",
"description": "Test description",
"parameters": {"type": "object", "properties": {}},
"github_token": None,
"raise_on_failure": False,
"retry_attempts": 3,
"outputs_to_string": {"handler": "haystack_integrations.tools.github.utils.message_handler"},
"inputs_from_state": {"repository": "repo"},
"outputs_to_state": {
"documents": {
"source": "success",
"handler": "haystack_integrations.tools.github.utils.message_handler",
}
},
},
}
tool = GitHubIssueCommenterTool.from_dict(tool_dict)
assert tool.name == "test_issue_commenter"
assert tool.description == "Test description"
assert tool.parameters == {"type": "object", "properties": {}}
assert tool.github_token is None
assert tool.raise_on_failure is False
assert tool.retry_attempts == 3
assert tool.outputs_to_string["handler"] == message_handler
assert tool.inputs_from_state == {"repository": "repo"}
assert tool.outputs_to_state["documents"]["source"] == "success"
assert tool.outputs_to_state["documents"]["handler"] == message_handler