refactor(tests): adjust formatting for consistency and readability
- Updated line breaks and indentation across test modules to enhance clarity and maintain consistent style. - Applied changes to workspace, provider, server, and GitWrapper-related test cases. No functional changes introduced.
This commit is contained in:
@@ -141,7 +141,9 @@ class TestGitHubProviderConnection:
|
||||
await provider.close()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_authenticated_user(self, github_provider, mock_github_httpx_client):
|
||||
async def test_get_authenticated_user(
|
||||
self, github_provider, mock_github_httpx_client
|
||||
):
|
||||
"""Test getting authenticated user."""
|
||||
mock_github_httpx_client.request.return_value.json = MagicMock(
|
||||
return_value={"login": "test-user"}
|
||||
@@ -210,7 +212,9 @@ class TestGitHubPROperations:
|
||||
assert result.pr_url == "https://github.com/owner/repo/pull/42"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_pr_with_draft(self, github_provider, mock_github_httpx_client):
|
||||
async def test_create_pr_with_draft(
|
||||
self, github_provider, mock_github_httpx_client
|
||||
):
|
||||
"""Test creating a draft PR."""
|
||||
mock_github_httpx_client.request.return_value.json = MagicMock(
|
||||
return_value={
|
||||
@@ -233,15 +237,22 @@ class TestGitHubPROperations:
|
||||
assert result.pr_number == 43
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_pr_with_options(self, github_provider, mock_github_httpx_client):
|
||||
async def test_create_pr_with_options(
|
||||
self, github_provider, mock_github_httpx_client
|
||||
):
|
||||
"""Test creating PR with labels, assignees, reviewers."""
|
||||
mock_responses = [
|
||||
{"number": 44, "html_url": "https://github.com/owner/repo/pull/44"}, # Create PR
|
||||
{
|
||||
"number": 44,
|
||||
"html_url": "https://github.com/owner/repo/pull/44",
|
||||
}, # Create PR
|
||||
[{"name": "enhancement"}], # POST add labels
|
||||
{}, # POST add assignees
|
||||
{}, # POST request reviewers
|
||||
]
|
||||
mock_github_httpx_client.request.return_value.json = MagicMock(side_effect=mock_responses)
|
||||
mock_github_httpx_client.request.return_value.json = MagicMock(
|
||||
side_effect=mock_responses
|
||||
)
|
||||
|
||||
result = await github_provider.create_pr(
|
||||
owner="owner",
|
||||
@@ -258,7 +269,9 @@ class TestGitHubPROperations:
|
||||
assert result.success is True
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_pr(self, github_provider, mock_github_httpx_client, github_pr_data):
|
||||
async def test_get_pr(
|
||||
self, github_provider, mock_github_httpx_client, github_pr_data
|
||||
):
|
||||
"""Test getting a pull request."""
|
||||
mock_github_httpx_client.request.return_value.json = MagicMock(
|
||||
return_value=github_pr_data
|
||||
@@ -274,14 +287,18 @@ class TestGitHubPROperations:
|
||||
async def test_get_pr_not_found(self, github_provider, mock_github_httpx_client):
|
||||
"""Test getting non-existent PR."""
|
||||
mock_github_httpx_client.request.return_value.status_code = 404
|
||||
mock_github_httpx_client.request.return_value.json = MagicMock(return_value=None)
|
||||
mock_github_httpx_client.request.return_value.json = MagicMock(
|
||||
return_value=None
|
||||
)
|
||||
|
||||
result = await github_provider.get_pr("owner", "repo", 999)
|
||||
|
||||
assert result.success is False
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_prs(self, github_provider, mock_github_httpx_client, github_pr_data):
|
||||
async def test_list_prs(
|
||||
self, github_provider, mock_github_httpx_client, github_pr_data
|
||||
):
|
||||
"""Test listing pull requests."""
|
||||
mock_github_httpx_client.request.return_value.json = MagicMock(
|
||||
return_value=[github_pr_data, github_pr_data]
|
||||
@@ -293,20 +310,22 @@ class TestGitHubPROperations:
|
||||
assert len(result.pull_requests) == 2
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_prs_with_state_filter(self, github_provider, mock_github_httpx_client, github_pr_data):
|
||||
async def test_list_prs_with_state_filter(
|
||||
self, github_provider, mock_github_httpx_client, github_pr_data
|
||||
):
|
||||
"""Test listing PRs with state filter."""
|
||||
mock_github_httpx_client.request.return_value.json = MagicMock(
|
||||
return_value=[github_pr_data]
|
||||
)
|
||||
|
||||
result = await github_provider.list_prs(
|
||||
"owner", "repo", state=PRState.OPEN
|
||||
)
|
||||
result = await github_provider.list_prs("owner", "repo", state=PRState.OPEN)
|
||||
|
||||
assert result.success is True
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_merge_pr(self, github_provider, mock_github_httpx_client, github_pr_data):
|
||||
async def test_merge_pr(
|
||||
self, github_provider, mock_github_httpx_client, github_pr_data
|
||||
):
|
||||
"""Test merging a pull request."""
|
||||
# Merge returns sha, then get_pr returns the PR data, then delete branch
|
||||
mock_responses = [
|
||||
@@ -319,7 +338,9 @@ class TestGitHubPROperations:
|
||||
)
|
||||
|
||||
result = await github_provider.merge_pr(
|
||||
"owner", "repo", 42,
|
||||
"owner",
|
||||
"repo",
|
||||
42,
|
||||
merge_strategy=MergeStrategy.SQUASH,
|
||||
)
|
||||
|
||||
@@ -327,7 +348,9 @@ class TestGitHubPROperations:
|
||||
assert result.merge_commit_sha == "merge-commit-sha"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_merge_pr_rebase(self, github_provider, mock_github_httpx_client, github_pr_data):
|
||||
async def test_merge_pr_rebase(
|
||||
self, github_provider, mock_github_httpx_client, github_pr_data
|
||||
):
|
||||
"""Test merging with rebase strategy."""
|
||||
mock_responses = [
|
||||
{"sha": "rebase-commit-sha", "merged": True}, # PUT merge
|
||||
@@ -339,21 +362,27 @@ class TestGitHubPROperations:
|
||||
)
|
||||
|
||||
result = await github_provider.merge_pr(
|
||||
"owner", "repo", 42,
|
||||
"owner",
|
||||
"repo",
|
||||
42,
|
||||
merge_strategy=MergeStrategy.REBASE,
|
||||
)
|
||||
|
||||
assert result.success is True
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_update_pr(self, github_provider, mock_github_httpx_client, github_pr_data):
|
||||
async def test_update_pr(
|
||||
self, github_provider, mock_github_httpx_client, github_pr_data
|
||||
):
|
||||
"""Test updating a pull request."""
|
||||
mock_github_httpx_client.request.return_value.json = MagicMock(
|
||||
return_value=github_pr_data
|
||||
)
|
||||
|
||||
result = await github_provider.update_pr(
|
||||
"owner", "repo", 42,
|
||||
"owner",
|
||||
"repo",
|
||||
42,
|
||||
title="Updated Title",
|
||||
body="Updated body",
|
||||
)
|
||||
@@ -361,7 +390,9 @@ class TestGitHubPROperations:
|
||||
assert result.success is True
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_close_pr(self, github_provider, mock_github_httpx_client, github_pr_data):
|
||||
async def test_close_pr(
|
||||
self, github_provider, mock_github_httpx_client, github_pr_data
|
||||
):
|
||||
"""Test closing a pull request."""
|
||||
github_pr_data["state"] = "closed"
|
||||
mock_github_httpx_client.request.return_value.json = MagicMock(
|
||||
@@ -391,11 +422,15 @@ class TestGitHubBranchOperations:
|
||||
assert result["name"] == "main"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delete_remote_branch(self, github_provider, mock_github_httpx_client):
|
||||
async def test_delete_remote_branch(
|
||||
self, github_provider, mock_github_httpx_client
|
||||
):
|
||||
"""Test deleting a remote branch."""
|
||||
mock_github_httpx_client.request.return_value.status_code = 204
|
||||
|
||||
result = await github_provider.delete_remote_branch("owner", "repo", "old-branch")
|
||||
result = await github_provider.delete_remote_branch(
|
||||
"owner", "repo", "old-branch"
|
||||
)
|
||||
|
||||
assert result is True
|
||||
|
||||
@@ -455,12 +490,12 @@ class TestGitHubLabelOperations:
|
||||
None, # DELETE label
|
||||
{"labels": []}, # GET issue
|
||||
]
|
||||
mock_github_httpx_client.request.return_value.json = MagicMock(side_effect=mock_responses)
|
||||
|
||||
result = await github_provider.remove_label(
|
||||
"owner", "repo", 42, "bug"
|
||||
mock_github_httpx_client.request.return_value.json = MagicMock(
|
||||
side_effect=mock_responses
|
||||
)
|
||||
|
||||
result = await github_provider.remove_label("owner", "repo", 42, "bug")
|
||||
|
||||
assert isinstance(result, list)
|
||||
|
||||
|
||||
@@ -483,7 +518,9 @@ class TestGitHubErrorHandling:
|
||||
"""Tests for error handling in GitHub provider."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_authentication_error(self, github_provider, mock_github_httpx_client):
|
||||
async def test_authentication_error(
|
||||
self, github_provider, mock_github_httpx_client
|
||||
):
|
||||
"""Test handling authentication errors."""
|
||||
mock_github_httpx_client.request.return_value.status_code = 401
|
||||
|
||||
|
||||
Reference in New Issue
Block a user