52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
import pytest
|
|
from unittest.mock import patch, AsyncMock
|
|
from src.api.github import GitHubClient
|
|
|
|
|
|
class TestGitHubClient:
|
|
@pytest.mark.asyncio
|
|
async def test_get_pull_requests(self):
|
|
client = GitHubClient(token="test_token")
|
|
mock_prs = [{"number": 1, "title": "Test PR"}]
|
|
|
|
with patch("httpx.AsyncClient.get", new_callable=AsyncMock) as mock_get:
|
|
mock_response = AsyncMock()
|
|
mock_response.json.return_value = mock_prs
|
|
mock_response.raise_for_status = AsyncMock()
|
|
mock_get.return_value = mock_response
|
|
|
|
prs = await client.get_pull_requests("owner", "repo")
|
|
|
|
assert len(prs) == 1
|
|
assert prs[0]["number"] == 1
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_get_issues(self):
|
|
client = GitHubClient(token="test_token")
|
|
mock_issues = [{"number": 1, "title": "Test Issue"}]
|
|
|
|
with patch("httpx.AsyncClient.get", new_callable=AsyncMock) as mock_get:
|
|
mock_response = AsyncMock()
|
|
mock_response.json.return_value = mock_issues
|
|
mock_response.raise_for_status = AsyncMock()
|
|
mock_get.return_value = mock_response
|
|
|
|
issues = await client.get_issues("owner", "repo")
|
|
|
|
assert len(issues) == 1
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_get_workflows(self):
|
|
client = GitHubClient(token="test_token")
|
|
mock_workflows = {"workflows": [{"id": 1, "name": "CI"}]}
|
|
|
|
with patch("httpx.AsyncClient.get", new_callable=AsyncMock) as mock_get:
|
|
mock_response = AsyncMock()
|
|
mock_response.json.return_value = mock_workflows
|
|
mock_response.raise_for_status = AsyncMock()
|
|
mock_get.return_value = mock_response
|
|
|
|
workflows = await client.get_workflows("owner", "repo")
|
|
|
|
assert len(workflows) == 1
|