Skip to content

Commit d98d3ec

Browse files
committed
add tests for four more tools
1 parent eb7a267 commit d98d3ec

4 files changed

Lines changed: 206 additions & 0 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
from haystack.utils import Secret
5+
6+
from haystack_integrations.prompts.github.issue_commenter_prompt import ISSUE_COMMENTER_PROMPT, ISSUE_COMMENTER_SCHEMA
7+
from haystack_integrations.tools.github.issue_commenter_tool import GitHubIssueCommenterTool
8+
9+
10+
class TestGitHubIssueCommenterTool:
11+
def test_init(self, monkeypatch):
12+
monkeypatch.setenv("GITHUB_TOKEN", "test-token")
13+
tool = GitHubIssueCommenterTool()
14+
assert tool.name == "issue_commenter"
15+
assert tool.description == ISSUE_COMMENTER_PROMPT
16+
assert tool.parameters == ISSUE_COMMENTER_SCHEMA
17+
assert tool.retry_attempts == 2
18+
19+
def test_from_dict(self, monkeypatch):
20+
monkeypatch.setenv("GITHUB_TOKEN", "test-token")
21+
tool_dict = {
22+
"type": "haystack_integrations.tools.github.issue_commenter_tool.GitHubIssueCommenterTool",
23+
"init_parameters": {
24+
"name": "issue_commenter",
25+
"description": ISSUE_COMMENTER_PROMPT,
26+
"parameters": ISSUE_COMMENTER_SCHEMA,
27+
"github_token": {"env_vars": ["GITHUB_TOKEN"], "strict": True, "type": "env_var"},
28+
"raise_on_failure": True,
29+
"retry_attempts": 2,
30+
},
31+
}
32+
tool = GitHubIssueCommenterTool.from_dict(tool_dict)
33+
assert tool.name == "issue_commenter"
34+
assert tool.description == ISSUE_COMMENTER_PROMPT
35+
assert tool.parameters == ISSUE_COMMENTER_SCHEMA
36+
assert tool.github_token == Secret.from_env_var("GITHUB_TOKEN")
37+
assert tool.raise_on_failure
38+
assert tool.retry_attempts == 2
39+
40+
def test_to_dict(self, monkeypatch):
41+
monkeypatch.setenv("GITHUB_TOKEN", "test-token")
42+
tool = GitHubIssueCommenterTool()
43+
tool_dict = tool.to_dict()
44+
assert tool_dict["type"] == "haystack_integrations.tools.github.issue_commenter_tool.GitHubIssueCommenterTool"
45+
assert tool_dict["init_parameters"]["name"] == "issue_commenter"
46+
assert tool_dict["init_parameters"]["description"] == ISSUE_COMMENTER_PROMPT
47+
assert tool_dict["init_parameters"]["parameters"] == ISSUE_COMMENTER_SCHEMA
48+
assert tool_dict["init_parameters"]["github_token"] == {
49+
"env_vars": ["GITHUB_TOKEN"],
50+
"strict": True,
51+
"type": "env_var",
52+
}
53+
assert tool_dict["init_parameters"]["raise_on_failure"]
54+
assert tool_dict["init_parameters"]["retry_attempts"] == 2
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
from haystack_integrations.prompts.github.issue_viewer_prompt import ISSUE_VIEWER_PROMPT, ISSUE_VIEWER_SCHEMA
5+
from haystack_integrations.tools.github.issue_viewer_tool import GitHubIssueViewerTool
6+
7+
8+
class TestGitHubIssueViewerTool:
9+
def test_init(self, monkeypatch):
10+
monkeypatch.setenv("GITHUB_TOKEN", "test-token")
11+
tool = GitHubIssueViewerTool()
12+
assert tool.name == "issue_viewer"
13+
assert tool.description == ISSUE_VIEWER_PROMPT
14+
assert tool.parameters == ISSUE_VIEWER_SCHEMA
15+
assert tool.retry_attempts == 2
16+
17+
def test_from_dict(self, monkeypatch):
18+
monkeypatch.setenv("GITHUB_TOKEN", "test-token")
19+
tool_dict = {
20+
"type": "haystack_integrations.tools.github.issue_viewer_tool.GitHubIssueViewerTool",
21+
"init_parameters": {
22+
"name": "issue_viewer",
23+
"description": ISSUE_VIEWER_PROMPT,
24+
"parameters": ISSUE_VIEWER_SCHEMA,
25+
"github_token": None,
26+
"raise_on_failure": True,
27+
"retry_attempts": 2,
28+
},
29+
}
30+
tool = GitHubIssueViewerTool.from_dict(tool_dict)
31+
assert tool.name == "issue_viewer"
32+
assert tool.description == ISSUE_VIEWER_PROMPT
33+
assert tool.parameters == ISSUE_VIEWER_SCHEMA
34+
assert tool.github_token is None
35+
assert tool.raise_on_failure
36+
assert tool.retry_attempts == 2
37+
38+
def test_to_dict(self, monkeypatch):
39+
monkeypatch.setenv("GITHUB_TOKEN", "test-token")
40+
tool = GitHubIssueViewerTool()
41+
tool_dict = tool.to_dict()
42+
assert tool_dict["type"] == "haystack_integrations.tools.github.issue_viewer_tool.GitHubIssueViewerTool"
43+
assert tool_dict["init_parameters"]["name"] == "issue_viewer"
44+
assert tool_dict["init_parameters"]["description"] == ISSUE_VIEWER_PROMPT
45+
assert tool_dict["init_parameters"]["parameters"] == ISSUE_VIEWER_SCHEMA
46+
assert tool_dict["init_parameters"]["github_token"] is None
47+
assert tool_dict["init_parameters"]["raise_on_failure"]
48+
assert tool_dict["init_parameters"]["retry_attempts"] == 2
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
from haystack.utils import Secret
5+
6+
from haystack_integrations.prompts.github.pr_creator_prompt import PR_CREATOR_PROMPT, PR_CREATOR_SCHEMA
7+
from haystack_integrations.tools.github.pr_creator_tool import GitHubPRCreatorTool
8+
9+
10+
class TestGitHubPRCreatorTool:
11+
def test_init(self, monkeypatch):
12+
monkeypatch.setenv("GITHUB_TOKEN", "test-token")
13+
tool = GitHubPRCreatorTool()
14+
assert tool.name == "pr_creator"
15+
assert tool.description == PR_CREATOR_PROMPT
16+
assert tool.parameters == PR_CREATOR_SCHEMA
17+
18+
def test_from_dict(self, monkeypatch):
19+
monkeypatch.setenv("GITHUB_TOKEN", "test-token")
20+
tool_dict = {
21+
"type": "haystack_integrations.tools.github.pr_creator_tool.GitHubPRCreatorTool",
22+
"init_parameters": {
23+
"name": "pr_creator",
24+
"description": PR_CREATOR_PROMPT,
25+
"parameters": PR_CREATOR_SCHEMA,
26+
"github_token": {"env_vars": ["GITHUB_TOKEN"], "strict": True, "type": "env_var"},
27+
"raise_on_failure": True,
28+
},
29+
}
30+
tool = GitHubPRCreatorTool.from_dict(tool_dict)
31+
assert tool.name == "pr_creator"
32+
assert tool.description == PR_CREATOR_PROMPT
33+
assert tool.parameters == PR_CREATOR_SCHEMA
34+
assert tool.github_token == Secret.from_env_var("GITHUB_TOKEN")
35+
assert tool.raise_on_failure
36+
37+
def test_to_dict(self, monkeypatch):
38+
monkeypatch.setenv("GITHUB_TOKEN", "test-token")
39+
tool = GitHubPRCreatorTool()
40+
tool_dict = tool.to_dict()
41+
assert tool_dict["type"] == "haystack_integrations.tools.github.pr_creator_tool.GitHubPRCreatorTool"
42+
assert tool_dict["init_parameters"]["name"] == "pr_creator"
43+
assert tool_dict["init_parameters"]["description"] == PR_CREATOR_PROMPT
44+
assert tool_dict["init_parameters"]["parameters"] == PR_CREATOR_SCHEMA
45+
assert tool_dict["init_parameters"]["github_token"] == {
46+
"env_vars": ["GITHUB_TOKEN"],
47+
"strict": True,
48+
"type": "env_var",
49+
}
50+
assert tool_dict["init_parameters"]["raise_on_failure"]
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
from haystack_integrations.prompts.github.repo_viewer_prompt import REPO_VIEWER_PROMPT, REPO_VIEWER_SCHEMA
5+
from haystack_integrations.tools.github.repo_viewer_tool import GitHubRepoViewerTool
6+
7+
8+
class TestGitHubRepoViewerTool:
9+
def test_init(self, monkeypatch):
10+
monkeypatch.setenv("GITHUB_TOKEN", "test-token")
11+
tool = GitHubRepoViewerTool()
12+
assert tool.name == "repo_viewer"
13+
assert tool.description == REPO_VIEWER_PROMPT
14+
assert tool.parameters == REPO_VIEWER_SCHEMA
15+
assert tool.max_file_size == 1_000_000
16+
17+
def test_from_dict(self, monkeypatch):
18+
monkeypatch.setenv("GITHUB_TOKEN", "test-token")
19+
tool_dict = {
20+
"type": "haystack_integrations.tools.github.repo_viewer_tool.GitHubRepoViewerTool",
21+
"init_parameters": {
22+
"name": "repo_viewer",
23+
"description": REPO_VIEWER_PROMPT,
24+
"parameters": REPO_VIEWER_SCHEMA,
25+
"github_token": None,
26+
"repo": None,
27+
"branch": "main",
28+
"raise_on_failure": True,
29+
"max_file_size": 1_000_000,
30+
},
31+
}
32+
tool = GitHubRepoViewerTool.from_dict(tool_dict)
33+
assert tool.name == "repo_viewer"
34+
assert tool.description == REPO_VIEWER_PROMPT
35+
assert tool.parameters == REPO_VIEWER_SCHEMA
36+
assert tool.github_token is None
37+
assert tool.repo is None
38+
assert tool.branch == "main"
39+
assert tool.raise_on_failure
40+
assert tool.max_file_size == 1_000_000
41+
42+
def test_to_dict(self, monkeypatch):
43+
monkeypatch.setenv("GITHUB_TOKEN", "test-token")
44+
tool = GitHubRepoViewerTool()
45+
tool_dict = tool.to_dict()
46+
assert tool_dict["type"] == "haystack_integrations.tools.github.repo_viewer_tool.GitHubRepoViewerTool"
47+
assert tool_dict["init_parameters"]["name"] == "repo_viewer"
48+
assert tool_dict["init_parameters"]["description"] == REPO_VIEWER_PROMPT
49+
assert tool_dict["init_parameters"]["parameters"] == REPO_VIEWER_SCHEMA
50+
assert tool_dict["init_parameters"]["github_token"] is None
51+
assert tool_dict["init_parameters"]["repo"] is None
52+
assert tool_dict["init_parameters"]["branch"] == "main"
53+
assert tool_dict["init_parameters"]["raise_on_failure"]
54+
assert tool_dict["init_parameters"]["max_file_size"] == 1_000_000

0 commit comments

Comments
 (0)