e91780169e
- Create gitea/issues_client.py with IssuesClient class (9 methods) - Create gitea/prs_client.py with PullRequestsClient class (17 methods) - Create gitea/files_client.py with FilesClient class (4 methods) - Create gitea/notifications_client.py with NotificationsClient class (2 methods) - Create gitea/repos_client.py with ReposClient class (2 methods) - Create gitea/__init__.py to export all client classes - Remove delegation methods from GiteaClient (now ~70 lines) - Update all callers to use sub-clients (client.issues, client.prs, etc.) - Update test files to mock sub-client attributes GiteaClient is now a facade that provides access to focused sub-clients: - repos: Repository operations (ReposClient) - issues: Issue operations (IssuesClient) - prs: Pull request operations (PullRequestsClient) - files: File and git ref operations (FilesClient) - notifications: Notification operations (NotificationsClient) Refs: #godclass-refactor
30 lines
1.0 KiB
Python
30 lines
1.0 KiB
Python
from unittest.mock import MagicMock
|
|
from gitea.client import GiteaClient
|
|
from gitea.tools.git_tools import GitTools
|
|
|
|
|
|
def _create_mock_client() -> MagicMock:
|
|
"""Create a mock GiteaClient with sub-client attributes."""
|
|
mock_client: MagicMock = MagicMock(spec=GiteaClient)
|
|
mock_client.files = MagicMock()
|
|
return mock_client
|
|
|
|
|
|
def test_create_branch_success() -> None:
|
|
mock_client = _create_mock_client()
|
|
mock_client.files.create_ref.return_value = {}
|
|
|
|
git_tools: GitTools = GitTools(mock_client)
|
|
res: str = git_tools.create_branch("owner", "repo", "ref", "sha")
|
|
assert res == "Branch 'ref' created successfully in owner/repo."
|
|
mock_client.files.create_ref.assert_called_once_with("owner", "repo", "ref", "sha")
|
|
|
|
|
|
def test_create_branch_failure() -> None:
|
|
mock_client = _create_mock_client()
|
|
mock_client.files.create_ref.side_effect = Exception("API Error")
|
|
|
|
git_tools: GitTools = GitTools(mock_client)
|
|
res: str = git_tools.create_branch("owner", "repo", "ref", "sha")
|
|
assert res == "Error creating branch: API Error"
|