Skip to content

Commit

Permalink
commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
author committed Dec 12, 2024
1 parent 9a1cbac commit 2d961e8
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions tests/plugins/github/handlers/test_git_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from pytest_mock import MockerFixture


async def test_checkout_branch(mocker: MockerFixture):
from src.plugins.github.handlers.git import GitHandler

mock_run_shell_command = mocker.patch("src.plugins.github.utils.run_shell_command")

git_handler = GitHandler()
git_handler.checkout_branch("main")

mock_run_shell_command.assert_called_once_with(["git", "checkout", "main"])


async def test_checkout_remote_branch(mocker: MockerFixture):
from src.plugins.github.handlers.git import GitHandler

mock_run_shell_command = mocker.patch("src.plugins.github.utils.run_shell_command")

git_handler = GitHandler()
git_handler.checkout_remote_branch("main")

mock_run_shell_command.assert_any_call(["git", "fetch", "origin", "main"])
mock_run_shell_command.assert_any_call(["git", "checkout", "main"])


async def test_commit_and_push(mocker: MockerFixture):
from src.plugins.github.handlers.git import GitHandler

mock_run_shell_command = mocker.patch("src.plugins.github.utils.run_shell_command")

git_handler = GitHandler()
git_handler.commit_and_push("commit message", "main", "author")

mock_run_shell_command.assert_any_call(
["git", "config", "--global", "user.name", "author"]
)
mock_run_shell_command.assert_any_call(
["git", "config", "--global", "user.email", "[email protected]"]
)
mock_run_shell_command.assert_any_call(["git", "add", "-A"])
mock_run_shell_command.assert_any_call(["git", "commit", "-m", "commit message"])
mock_run_shell_command.assert_any_call(["git", "fetch", "origin"])
mock_run_shell_command.assert_any_call(["git", "diff", "origin/main", "main"])
mock_run_shell_command.assert_any_call(["git", "push", "origin", "main", "-f"])


async def test_delete_origin_branch(mocker: MockerFixture):
from src.plugins.github.handlers.git import GitHandler

mock_run_shell_command = mocker.patch("src.plugins.github.utils.run_shell_command")

git_handler = GitHandler()
git_handler.delete_origin_branch("main")

mock_run_shell_command.assert_called_once_with(
["git", "push", "origin", "--delete", "main"]
)


async def test_switch_branch(mocker: MockerFixture):
from src.plugins.github.handlers.git import GitHandler

mock_run_shell_command = mocker.patch("src.plugins.github.utils.run_shell_command")

git_handler = GitHandler()
git_handler.switch_branch("main")

mock_run_shell_command.assert_called_once_with(["git", "switch", "-C", "main"])

0 comments on commit 2d961e8

Please sign in to comment.