import pytest from unittest.mock import MagicMock, patch from aider_gitea.gitea_client import GiteaClient class TestGiteaClientPRLabels: def setup_method(self): self.client = GiteaClient("https://gitea.example.com", "fake_token") @patch('requests.Session.post') def test_create_pull_request_with_labels(self, mock_post): # Mock the PR creation response pr_response = MagicMock() pr_response.status_code = 201 pr_response.json.return_value = { 'number': 123, 'title': 'Test PR', 'html_url': 'https://gitea.example.com/owner/repo/pulls/123' } # Mock the label addition response label_response = MagicMock() label_response.status_code = 200 # Set up the mock to return different responses for different calls mock_post.side_effect = [pr_response, label_response] # Call the method with labels result = self.client.create_pull_request( owner="owner", repo="repo", title="Test PR", body="Test body", head="feature-branch", base="main", labels=["aider"] ) # Verify PR creation call assert mock_post.call_count == 2 pr_call_args = mock_post.call_args_list[0] assert pr_call_args[0][0] == 'https://gitea.example.com/api/v1/repos/owner/repo/pulls' assert pr_call_args[1]['json']['title'] == 'Test PR' # Verify label addition call label_call_args = mock_post.call_args_list[1] assert label_call_args[0][0] == 'https://gitea.example.com/api/v1/repos/owner/repo/issues/123/labels' assert label_call_args[1]['json']['labels'] == ['aider'] # Verify the result assert result['number'] == 123 assert result['title'] == 'Test PR' @patch('requests.Session.post') def test_add_labels_to_pull_request(self, mock_post): # Mock the response mock_response = MagicMock() mock_response.status_code = 200 mock_post.return_value = mock_response # Call the method result = self.client.add_labels_to_pull_request( owner="owner", repo="repo", pull_number=123, labels=["aider", "bug"] ) # Verify the call mock_post.assert_called_once() call_args = mock_post.call_args assert call_args[0][0] == 'https://gitea.example.com/api/v1/repos/owner/repo/issues/123/labels' assert call_args[1]['json']['labels'] == ['aider', 'bug'] # Verify the result assert result is True