Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
from unittest.mock import MagicMock
|
||||
from gitea.client import GiteaClient
|
||||
from gitea.tools.git_tools import GitTools
|
||||
|
||||
|
||||
def test_create_branch_success() -> None:
|
||||
mock_client: MagicMock = MagicMock(spec=GiteaClient)
|
||||
mock_client.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.create_ref.assert_called_once_with("owner", "repo", "ref", "sha")
|
||||
|
||||
|
||||
def test_create_branch_failure() -> None:
|
||||
mock_client: MagicMock = MagicMock(spec=GiteaClient)
|
||||
mock_client.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"
|
||||
Reference in New Issue
Block a user