summaryrefslogtreecommitdiff
path: root/servers/gitlab_glab/tests/test_server.py
diff options
context:
space:
mode:
Diffstat (limited to 'servers/gitlab_glab/tests/test_server.py')
-rw-r--r--servers/gitlab_glab/tests/test_server.py154
1 files changed, 153 insertions, 1 deletions
diff --git a/servers/gitlab_glab/tests/test_server.py b/servers/gitlab_glab/tests/test_server.py
index 0c7ce64..ab93026 100644
--- a/servers/gitlab_glab/tests/test_server.py
+++ b/servers/gitlab_glab/tests/test_server.py
@@ -278,7 +278,11 @@ class TestGitLabServer:
assert "error" in result
assert "not found" in result["error"]
mock_execute.assert_called_once_with(
- ["api", "/projects?search_namespaces=true&search=nonexistent-project"], working_dir
+ [
+ "api",
+ "/projects?search_namespaces=true&search=nonexistent-project",
+ ],
+ working_dir
)
@patch.object(GitLabServer, "execute_glab_command")
@@ -298,6 +302,154 @@ class TestGitLabServer:
)
@patch.object(GitLabServer, "execute_glab_command")
+ def test_search_issues_success(self, mock_execute: MagicMock) -> None:
+ """Test successful issue search with default parameters."""
+ # Mock successful command execution with JSON output
+ mock_execute.return_value = (
+ True,
+ [
+ {
+ "id": 1,
+ "iid": 101,
+ "title": "Test Issue 1",
+ "web_url": "https://gitlab.com/group/project/issues/101",
+ "state": "opened",
+ "created_at": "2025-01-01T00:00:00Z",
+ "updated_at": "2025-01-02T00:00:00Z",
+ },
+ {
+ "id": 2,
+ "iid": 102,
+ "title": "Test Issue 2",
+ "web_url": "https://gitlab.com/group/project/issues/102",
+ "state": "closed",
+ "created_at": "2025-01-03T00:00:00Z",
+ "updated_at": "2025-01-04T00:00:00Z",
+ },
+ ],
+ )
+
+ server = GitLabServer()
+ working_dir = "/test/directory"
+ result = server.search_issues(working_directory=working_dir)
+
+ assert "issues" in result
+ assert len(result["issues"]) == 2
+ assert result["issues"][0]["id"] == 1
+ assert result["issues"][0]["title"] == "Test Issue 1"
+ assert result["issues"][1]["id"] == 2
+ assert result["issues"][1]["title"] == "Test Issue 2"
+
+ # Verify command was called with correct arguments
+ mock_execute.assert_called_once_with(
+ ["issue", "list", "-O", "json"],
+ working_dir,
+ )
+
+ @patch.object(GitLabServer, "execute_glab_command")
+ def test_search_issues_with_filters(self, mock_execute: MagicMock) -> None:
+ """Test issue search with various filters."""
+ # Mock successful command execution with JSON output
+ mock_execute.return_value = (
+ True,
+ [
+ {
+ "id": 1,
+ "iid": 101,
+ "title": "Test Issue 1",
+ "web_url": "https://gitlab.com/group/project/issues/101",
+ "state": "opened",
+ "created_at": "2025-01-01T00:00:00Z",
+ "updated_at": "2025-01-02T00:00:00Z",
+ },
+ ],
+ )
+
+ server = GitLabServer()
+ working_dir = "/test/directory"
+ result = server.search_issues(
+ working_directory=working_dir,
+ author="user1",
+ assignee="user2",
+ closed=True,
+ confidential=True,
+ group="test-group",
+ issue_type="incident",
+ iteration=123,
+ label=["bug", "critical"],
+ milestone="v1.0",
+ not_assignee="user3",
+ not_author="user4",
+ not_label=["wontfix"],
+ page=2,
+ per_page=10,
+ project="group/project",
+ )
+
+ assert "issues" in result
+ assert len(result["issues"]) == 1
+ assert result["issues"][0]["id"] == 1
+ assert result["issues"][0]["title"] == "Test Issue 1"
+
+ # Verify command was called with correct arguments
+ mock_execute.assert_called_once_with(
+ [
+ "issue", "list", "-O", "json",
+ "--author", "user1",
+ "-a", "user2",
+ "-c",
+ "-C",
+ "-g", "test-group",
+ "-t", "incident",
+ "-i", "123",
+ "-l", "bug",
+ "-l", "critical",
+ "-m", "v1.0",
+ "--not-assignee", "user3",
+ "--not-author", "user4",
+ "--not-label", "wontfix",
+ "-p", "2",
+ "-P", "10",
+ "-R", "group/project",
+ ],
+ working_dir,
+ )
+
+ @patch.object(GitLabServer, "execute_glab_command")
+ def test_search_issues_failure(self, mock_execute: MagicMock) -> None:
+ """Test failed issue search."""
+ # Mock failed command execution
+ mock_execute.return_value = (False, {"error": "Failed to list issues"})
+
+ server = GitLabServer()
+ working_dir = "/test/directory"
+ result = server.search_issues(working_directory=working_dir)
+
+ assert "error" in result
+ assert result["error"] == "Failed to list issues"
+ mock_execute.assert_called_once_with(
+ ["issue", "list", "-O", "json"],
+ working_dir,
+ )
+
+ @patch.object(GitLabServer, "execute_glab_command")
+ def test_search_issues_invalid_json(self, mock_execute: MagicMock) -> None:
+ """Test issue search with invalid JSON response."""
+ # Mock successful command execution but with invalid JSON
+ mock_execute.return_value = (True, "invalid json")
+
+ server = GitLabServer()
+ working_dir = "/test/directory"
+ result = server.search_issues(working_directory=working_dir)
+
+ assert "error" in result
+ assert result["error"] == "Failed to parse issues list"
+ mock_execute.assert_called_once_with(
+ ["issue", "list", "-O", "json"],
+ working_dir,
+ )
+
+ @patch.object(GitLabServer, "execute_glab_command")
def test_create_issue_success(self, mock_execute: MagicMock) -> None:
"""Test successful issue creation with required parameters."""
# Mock successful command execution with actual glab output format