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
        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 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 == 1
        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 the result
        assert result == expected_result