84 lines
3.0 KiB
Python
84 lines
3.0 KiB
Python
import pytest
|
|
from unittest.mock import MagicMock, patch
|
|
from pathlib import Path
|
|
|
|
from aider_gitea import push_changes
|
|
|
|
|
|
class TestIssueCommentOnFailure:
|
|
def setup_method(self):
|
|
self.cwd = Path('/tmp/test-repo')
|
|
self.branch_name = 'issue-123-test-branch'
|
|
self.issue_number = '123'
|
|
self.issue_title = 'Test Issue'
|
|
self.base_branch = 'main'
|
|
self.gitea_client = MagicMock()
|
|
self.owner = 'test-owner'
|
|
self.repo = 'test-repo'
|
|
|
|
@patch('aider_gitea.has_commits_on_branch', return_value=True)
|
|
@patch('aider_gitea.get_commit_messages', return_value=['Test commit'])
|
|
@patch('aider_gitea.run_cmd')
|
|
def test_comment_on_push_failure(self, mock_run_cmd, mock_get_commit_messages, mock_has_commits):
|
|
# Setup run_cmd to fail on git push
|
|
mock_run_cmd.return_value = False
|
|
|
|
# Call push_changes
|
|
result = push_changes(
|
|
self.cwd,
|
|
self.branch_name,
|
|
self.issue_number,
|
|
self.issue_title,
|
|
self.base_branch,
|
|
self.gitea_client,
|
|
self.owner,
|
|
self.repo
|
|
)
|
|
|
|
# Verify result is False
|
|
assert result is False
|
|
|
|
# Verify create_issue_comment was called with appropriate message
|
|
self.gitea_client.create_issue_comment.assert_called_once()
|
|
args, _ = self.gitea_client.create_issue_comment.call_args
|
|
assert args[0] == self.owner
|
|
assert args[1] == self.repo
|
|
assert args[2] == self.issue_number
|
|
assert "Failed to push branch" in args[3]
|
|
assert "❌ **Automated Solution Failed**" in args[3]
|
|
|
|
@patch('aider_gitea.has_commits_on_branch', return_value=True)
|
|
@patch('aider_gitea.get_commit_messages', return_value=['Test commit'])
|
|
@patch('aider_gitea.run_cmd')
|
|
def test_comment_on_pr_creation_failure(self, mock_run_cmd, mock_get_commit_messages, mock_has_commits):
|
|
# Setup run_cmd to succeed on git push
|
|
mock_run_cmd.return_value = True
|
|
|
|
# Setup create_pull_request to fail
|
|
self.gitea_client.create_pull_request.side_effect = Exception("PR creation failed")
|
|
|
|
# Call push_changes
|
|
result = push_changes(
|
|
self.cwd,
|
|
self.branch_name,
|
|
self.issue_number,
|
|
self.issue_title,
|
|
self.base_branch,
|
|
self.gitea_client,
|
|
self.owner,
|
|
self.repo
|
|
)
|
|
|
|
# Verify result is False
|
|
assert result is False
|
|
|
|
# Verify create_issue_comment was called with appropriate message
|
|
self.gitea_client.create_issue_comment.assert_called_once()
|
|
args, _ = self.gitea_client.create_issue_comment.call_args
|
|
assert args[0] == self.owner
|
|
assert args[1] == self.repo
|
|
assert args[2] == self.issue_number
|
|
assert "Failed to create pull request" in args[3]
|
|
assert "⚠️ **Partial Automation Success**" in args[3]
|
|
assert self.branch_name in args[3]
|