aider-gitea/test/test_push_changes_assignee_reviewer.py
Jon Michael Aanes 66b2da8461
Some checks failed
Run Python tests (through Pytest) / Test (push) Failing after 25s
Verify Python project can be installed, loaded and have version checked / Test (push) Successful in 23s
Ruff after Claude Code
2025-06-09 13:48:50 +02:00

183 lines
5.9 KiB
Python

from pathlib import Path
from unittest.mock import MagicMock, patch
from aider_gitea import RepositoryConfig, push_changes
class TestPushChangesAssigneeReviewer:
def setup_method(self):
self.repository_config = RepositoryConfig(
gitea_url='https://gitea.example.com',
owner='testowner',
repo='testrepo',
base_branch='main',
assignee='john_doe',
reviewer='jane_smith',
)
self.cwd = Path('/tmp/test')
self.branch_name = 'issue-123-test-branch'
self.issue_number = '123'
self.issue_title = 'Test Issue'
@patch('aider_gitea.run_cmd')
@patch('aider_gitea.has_commits_on_branch')
@patch('aider_gitea.get_commit_messages')
def test_push_changes_with_assignee_and_reviewer(
self,
mock_get_commit_messages,
mock_has_commits,
mock_run_cmd,
):
"""Test that push_changes correctly assigns assignee and reviewer."""
# Setup mocks
mock_has_commits.return_value = True
mock_get_commit_messages.return_value = ['Initial commit', 'Fix bug']
mock_run_cmd.return_value = True
# Mock gitea client
mock_client = MagicMock()
pr_response = {
'number': 123,
'html_url': 'https://gitea.example.com/testowner/testrepo/pulls/123',
}
mock_client.create_pull_request.return_value = pr_response
mock_client.assign_reviewers.return_value = True
# Call the function
result = push_changes(
self.repository_config,
self.cwd,
self.branch_name,
self.issue_number,
self.issue_title,
mock_client,
)
# Verify PR creation was called with assignees
mock_client.create_pull_request.assert_called_once()
create_pr_args = mock_client.create_pull_request.call_args
assert create_pr_args[1]['assignees'] == ['john_doe']
# Verify reviewer assignment was called
mock_client.assign_reviewers.assert_called_once_with(
owner='testowner',
repo='testrepo',
pull_number=123,
reviewers=['jane_smith'],
)
# Verify result
assert result.success is True
assert result.pull_request_id == 123
assert (
result.pull_request_url
== 'https://gitea.example.com/testowner/testrepo/pulls/123'
)
@patch('aider_gitea.run_cmd')
@patch('aider_gitea.has_commits_on_branch')
@patch('aider_gitea.get_commit_messages')
def test_push_changes_without_assignee_and_reviewer(
self,
mock_get_commit_messages,
mock_has_commits,
mock_run_cmd,
):
"""Test that push_changes works when no assignee or reviewer is specified."""
# Setup repository config without assignee/reviewer
config_no_assign = RepositoryConfig(
gitea_url='https://gitea.example.com',
owner='testowner',
repo='testrepo',
base_branch='main',
)
# Setup mocks
mock_has_commits.return_value = True
mock_get_commit_messages.return_value = ['Initial commit']
mock_run_cmd.return_value = True
# Mock gitea client
mock_client = MagicMock()
pr_response = {
'number': 124,
'html_url': 'https://gitea.example.com/testowner/testrepo/pulls/124',
}
mock_client.create_pull_request.return_value = pr_response
# Call the function
result = push_changes(
config_no_assign,
self.cwd,
self.branch_name,
self.issue_number,
self.issue_title,
mock_client,
)
# Verify PR creation was called without assignees
mock_client.create_pull_request.assert_called_once()
create_pr_args = mock_client.create_pull_request.call_args
assert create_pr_args[1]['assignees'] is None
# Verify reviewer assignment was NOT called
mock_client.assign_reviewers.assert_not_called()
# Verify result
assert result.success is True
assert result.pull_request_id == 124
@patch('aider_gitea.run_cmd')
@patch('aider_gitea.has_commits_on_branch')
@patch('aider_gitea.get_commit_messages')
def test_push_changes_with_only_assignee(
self,
mock_get_commit_messages,
mock_has_commits,
mock_run_cmd,
):
"""Test that push_changes works with only assignee specified."""
# Setup repository config with only assignee
config_assignee_only = RepositoryConfig(
gitea_url='https://gitea.example.com',
owner='testowner',
repo='testrepo',
base_branch='main',
assignee='john_doe',
)
# Setup mocks
mock_has_commits.return_value = True
mock_get_commit_messages.return_value = ['Initial commit']
mock_run_cmd.return_value = True
# Mock gitea client
mock_client = MagicMock()
pr_response = {
'number': 125,
'html_url': 'https://gitea.example.com/testowner/testrepo/pulls/125',
}
mock_client.create_pull_request.return_value = pr_response
# Call the function
result = push_changes(
config_assignee_only,
self.cwd,
self.branch_name,
self.issue_number,
self.issue_title,
mock_client,
)
# Verify PR creation was called with assignees
mock_client.create_pull_request.assert_called_once()
create_pr_args = mock_client.create_pull_request.call_args
assert create_pr_args[1]['assignees'] == ['john_doe']
# Verify reviewer assignment was NOT called
mock_client.assign_reviewers.assert_not_called()
# Verify result
assert result.success is True