aider-gitea/test/test_assignee_reviewer.py
Jon Michael Aanes 9e0adccdf4
All checks were successful
Run Python tests (through Pytest) / Test (push) Successful in 26s
Verify Python project can be installed, loaded and have version checked / Test (push) Successful in 23s
Ruff after Claude Code
2025-06-09 18:31:04 +02:00

129 lines
4.2 KiB
Python

from unittest.mock import MagicMock, patch
from aider_gitea.gitea_client import GiteaClient
class TestAssigneeReviewer:
def setup_method(self):
self.client = GiteaClient('https://gitea.example.com', 'fake_token')
@patch('requests.Session.post')
def test_create_pull_request_with_assignee_and_reviewer(self, mock_post):
"""Test that pull requests can be created with assignee and reviewer."""
# Mock the PR creation response
pr_response = MagicMock()
pr_response.status_code = 201
expected_result = {
'number': 123,
'title': 'Test PR',
'html_url': 'https://gitea.example.com/owner/repo/pulls/123',
}
pr_response.json.return_value = expected_result
mock_post.return_value = pr_response
# Call the method with assignee and reviewer
result = self.client.create_pull_request(
owner='owner',
repo='repo',
title='Test PR',
body='Test body',
head='feature-branch',
base='main',
assignee='john_doe',
reviewer='jane_smith',
)
# Verify PR creation call
assert mock_post.call_count == 1
pr_call_args = mock_post.call_args_list[0]
# Check URL
assert (
pr_call_args[0][0]
== 'https://gitea.example.com/api/v1/repos/owner/repo/pulls'
)
# Check request body
json_data = pr_call_args[1]['json']
assert json_data['title'] == 'Test PR'
assert json_data['assignee'] == 'john_doe'
assert json_data['reviewers'] == ['jane_smith']
# Verify the result
assert result == expected_result
@patch('requests.Session.post')
def test_create_pull_request_without_assignee_reviewer(self, mock_post):
"""Test that pull requests can be created without assignee/reviewer."""
# Mock the PR creation response
pr_response = MagicMock()
pr_response.status_code = 201
expected_result = {
'number': 124,
'title': 'Test PR',
'html_url': 'https://gitea.example.com/owner/repo/pulls/124',
}
pr_response.json.return_value = expected_result
mock_post.return_value = pr_response
# Call the method without assignee and reviewer
result = self.client.create_pull_request(
owner='owner',
repo='repo',
title='Test PR',
body='Test body',
head='feature-branch',
base='main',
)
# Verify PR creation call
assert mock_post.call_count == 1
pr_call_args = mock_post.call_args_list[0]
# Check request body
json_data = pr_call_args[1]['json']
assert json_data['title'] == 'Test PR'
assert 'assignee' not in json_data
assert 'reviewers' not in json_data
# Verify the result
assert result == expected_result
@patch('requests.Session.post')
def test_create_pull_request_with_only_assignee(self, mock_post):
"""Test that pull requests can be created with only assignee."""
# Mock the PR creation response
pr_response = MagicMock()
pr_response.status_code = 201
expected_result = {
'number': 125,
'title': 'Test PR',
'html_url': 'https://gitea.example.com/owner/repo/pulls/125',
}
pr_response.json.return_value = expected_result
mock_post.return_value = pr_response
# Call the method with only assignee
result = self.client.create_pull_request(
owner='owner',
repo='repo',
title='Test PR',
body='Test body',
head='feature-branch',
base='main',
assignee='john_doe',
)
# Verify PR creation call
assert mock_post.call_count == 1
pr_call_args = mock_post.call_args_list[0]
# Check request body
json_data = pr_call_args[1]['json']
assert json_data['title'] == 'Test PR'
assert json_data['assignee'] == 'john_doe'
assert 'reviewers' not in json_data
# Verify the result
assert result == expected_result