summaryrefslogtreecommitdiff
path: root/servers/gitlab_python/tests/test_server.py
diff options
context:
space:
mode:
authorDawid Rycerz <dawid@rycerz.xyz>2025-07-15 17:43:07 +0300
committerDawid Rycerz <dawid@rycerz.xyz>2025-07-15 17:43:07 +0300
commit9fbb9b43fa81ce04665fddbaaa64ab455158a44e (patch)
treeed69c6257b590acd6942d34eccc6e75231f92b02 /servers/gitlab_python/tests/test_server.py
parentea094d5731ae36db599b9a9803c41db303fc685a (diff)
feat: Add listing and adding comments
Diffstat (limited to 'servers/gitlab_python/tests/test_server.py')
-rw-r--r--servers/gitlab_python/tests/test_server.py142
1 files changed, 142 insertions, 0 deletions
diff --git a/servers/gitlab_python/tests/test_server.py b/servers/gitlab_python/tests/test_server.py
index 244cdd5..94820aa 100644
--- a/servers/gitlab_python/tests/test_server.py
+++ b/servers/gitlab_python/tests/test_server.py
@@ -335,4 +335,146 @@ def test_update_epic_error(mock_gitlab, mock_settings):
mock_gitlab.return_value.groups.get.side_effect = Exception("Group not found")
result = server.update_epic("bad-group", 101, title="Updated Epic")
assert "error" in result
+ assert "Group not found" in result["error"]
+
+@patch("mcp_server_gitlab_python.server.get_gitlab_settings", return_value=("https://gitlab.com", "dummy-token"))
+@patch("gitlab.Gitlab")
+def test_list_issue_comments_success(mock_gitlab, mock_settings):
+ server = GitLabPythonServer(working_directory="/tmp")
+ proj = MagicMock()
+ issue = MagicMock()
+ note1 = MagicMock()
+ note1.id = 1
+ note1.body = "First comment"
+ note1.author = {"id": 2, "name": "Alice"}
+ note1.created_at = "2024-01-01T00:00:00Z"
+ note1.updated_at = "2024-01-01T01:00:00Z"
+ note1.system = False
+ note2 = MagicMock()
+ note2.id = 2
+ note2.body = "Second comment"
+ note2.author = {"id": 3, "name": "Bob"}
+ note2.created_at = "2024-01-02T00:00:00Z"
+ note2.updated_at = "2024-01-02T01:00:00Z"
+ note2.system = True
+ issue.notes.list.return_value = [note1, note2]
+ proj.issues.get.return_value = issue
+ mock_gitlab.return_value.projects.get.return_value = proj
+ result = server.list_issue_comments("project/path", 42)
+ assert "comments" in result
+ assert len(result["comments"]) == 2
+ assert result["comments"][0]["body"] == "First comment"
+ assert result["comments"][1]["author"]["name"] == "Bob"
+ proj.issues.get.assert_called_once_with(42)
+ issue.notes.list.assert_called_once_with(all=True)
+
+@patch("mcp_server_gitlab_python.server.get_gitlab_settings", return_value=("https://gitlab.com", "dummy-token"))
+@patch("gitlab.Gitlab")
+def test_list_issue_comments_error(mock_gitlab, mock_settings):
+ server = GitLabPythonServer(working_directory="/tmp")
+ mock_gitlab.return_value.projects.get.side_effect = Exception("Project not found")
+ result = server.list_issue_comments("bad-project", 42)
+ assert "error" in result
+ assert "Project not found" in result["error"]
+
+@patch("mcp_server_gitlab_python.server.get_gitlab_settings", return_value=("https://gitlab.com", "dummy-token"))
+@patch("gitlab.Gitlab")
+def test_create_issue_comment_success(mock_gitlab, mock_settings):
+ server = GitLabPythonServer(working_directory="/tmp")
+ proj = MagicMock()
+ issue = MagicMock()
+ note = MagicMock()
+ note.id = 123
+ note.body = "A new comment"
+ note.author = {"id": 2, "name": "Alice"}
+ note.created_at = "2024-01-01T00:00:00Z"
+ note.updated_at = "2024-01-01T01:00:00Z"
+ note.system = False
+ issue.notes.create.return_value = note
+ proj.issues.get.return_value = issue
+ mock_gitlab.return_value.projects.get.return_value = proj
+ result = server.create_issue_comment("project/path", 42, "A new comment")
+ assert result["id"] == 123
+ assert result["body"] == "A new comment"
+ assert result["author"]["name"] == "Alice"
+ issue.notes.create.assert_called_once_with({"body": "A new comment"})
+
+@patch("mcp_server_gitlab_python.server.get_gitlab_settings", return_value=("https://gitlab.com", "dummy-token"))
+@patch("gitlab.Gitlab")
+def test_create_issue_comment_error(mock_gitlab, mock_settings):
+ server = GitLabPythonServer(working_directory="/tmp")
+ mock_gitlab.return_value.projects.get.side_effect = Exception("Project not found")
+ result = server.create_issue_comment("bad-project", 42, "A new comment")
+ assert "error" in result
+ assert "Project not found" in result["error"]
+
+@patch("mcp_server_gitlab_python.server.get_gitlab_settings", return_value=("https://gitlab.com", "dummy-token"))
+@patch("gitlab.Gitlab")
+def test_list_epic_comments_success(mock_gitlab, mock_settings):
+ server = GitLabPythonServer(working_directory="/tmp")
+ group = MagicMock()
+ epic = MagicMock()
+ note1 = MagicMock()
+ note1.id = 1
+ note1.body = "Epic comment 1"
+ note1.author = {"id": 2, "name": "Alice"}
+ note1.created_at = "2024-01-01T00:00:00Z"
+ note1.updated_at = "2024-01-01T01:00:00Z"
+ note1.system = False
+ note2 = MagicMock()
+ note2.id = 2
+ note2.body = "Epic comment 2"
+ note2.author = {"id": 3, "name": "Bob"}
+ note2.created_at = "2024-01-02T00:00:00Z"
+ note2.updated_at = "2024-01-02T01:00:00Z"
+ note2.system = True
+ epic.notes.list.return_value = [note1, note2]
+ group.epics.get.return_value = epic
+ mock_gitlab.return_value.groups.get.return_value = group
+ result = server.list_epic_comments("test-group", 101)
+ assert "comments" in result
+ assert len(result["comments"]) == 2
+ assert result["comments"][0]["body"] == "Epic comment 1"
+ assert result["comments"][1]["author"]["name"] == "Bob"
+ group.epics.get.assert_called_once_with(101)
+ epic.notes.list.assert_called_once_with(all=True)
+
+@patch("mcp_server_gitlab_python.server.get_gitlab_settings", return_value=("https://gitlab.com", "dummy-token"))
+@patch("gitlab.Gitlab")
+def test_list_epic_comments_error(mock_gitlab, mock_settings):
+ server = GitLabPythonServer(working_directory="/tmp")
+ mock_gitlab.return_value.groups.get.side_effect = Exception("Group not found")
+ result = server.list_epic_comments("bad-group", 101)
+ assert "error" in result
+ assert "Group not found" in result["error"]
+
+@patch("mcp_server_gitlab_python.server.get_gitlab_settings", return_value=("https://gitlab.com", "dummy-token"))
+@patch("gitlab.Gitlab")
+def test_create_epic_comment_success(mock_gitlab, mock_settings):
+ server = GitLabPythonServer(working_directory="/tmp")
+ group = MagicMock()
+ epic = MagicMock()
+ note = MagicMock()
+ note.id = 456
+ note.body = "A new epic comment"
+ note.author = {"id": 2, "name": "Alice"}
+ note.created_at = "2024-01-01T00:00:00Z"
+ note.updated_at = "2024-01-01T01:00:00Z"
+ note.system = False
+ epic.notes.create.return_value = note
+ group.epics.get.return_value = epic
+ mock_gitlab.return_value.groups.get.return_value = group
+ result = server.create_epic_comment("test-group", 101, "A new epic comment")
+ assert result["id"] == 456
+ assert result["body"] == "A new epic comment"
+ assert result["author"]["name"] == "Alice"
+ epic.notes.create.assert_called_once_with({"body": "A new epic comment"})
+
+@patch("mcp_server_gitlab_python.server.get_gitlab_settings", return_value=("https://gitlab.com", "dummy-token"))
+@patch("gitlab.Gitlab")
+def test_create_epic_comment_error(mock_gitlab, mock_settings):
+ server = GitLabPythonServer(working_directory="/tmp")
+ mock_gitlab.return_value.groups.get.side_effect = Exception("Group not found")
+ result = server.create_epic_comment("bad-group", 101, "A new epic comment")
+ assert "error" in result
assert "Group not found" in result["error"] \ No newline at end of file