예제 #1
0
def test_push_changes_dry_run(mocked_config):
    git_mixin = get_git_mixin_consumer()
    mocked_config.settings.dry_run = True

    git_mixin.push_changes()

    assert mocked_config.repo.remotes.origin.push.called is False
예제 #2
0
def test_git_commit_dry_run(mocked_config):
    git_mixin = get_git_mixin_consumer()
    mocked_config.settings.dry_run = True

    git_mixin.git_commit("message")

    assert mocked_config.repo.index.commit.called is False
예제 #3
0
def test_checkout_branch(mocked_config):
    expected_branch_name = "awesome_branch"
    git_mixin = get_git_mixin_consumer()
    mocked_config.settings.dry_run = False
    mocked_config.settings.git_branch_name = expected_branch_name

    mock_remote = Mock()
    mock_remote.name = "origin"

    mock_ref = Mock()
    mock_ref.name = f"{mock_remote.name}/{expected_branch_name}"

    mock_remote.refs = [mock_ref]

    mocked_config.repo.remote.return_value = mock_remote

    git_mixin.checkout_branch()

    mocked_config.repo.git.checkout.assert_called_once_with(
        "HEAD", B=expected_branch_name
    )

    mocked_config.repo.remote.assert_called_once_with()

    mocked_config.repo.git.pull.assert_called_once_with(
        "origin", expected_branch_name
    )
예제 #4
0
def test_git_add_dry_run(mocked_config):
    expected_path = Path("/tmp/path")
    git_mixin = get_git_mixin_consumer()
    mocked_config.settings.dry_run = True

    git_mixin.git_add(expected_path)

    assert mocked_config.repo.git.add.called is False
예제 #5
0
def test_checkout_branch_dry_run(mocked_config):
    git_mixin = get_git_mixin_consumer()
    mocked_config.settings.dry_run = True

    git_mixin.checkout_branch()

    assert mocked_config.repo.git.checkout.called is False
    assert mocked_config.repo.git.pull.called is False
예제 #6
0
def test_git_commit(mocked_config):
    commit_message = "message"
    git_mixin = get_git_mixin_consumer()
    mocked_config.settings.dry_run = False

    git_mixin.git_commit(commit_message)

    mocked_config.repo.index.commit.assert_called_once_with(commit_message)
예제 #7
0
def test_git_add(mocked_config):
    expected_path = Path("/tmp/path")
    git_mixin = get_git_mixin_consumer()
    mocked_config.settings.dry_run = False

    git_mixin.git_add(expected_path)

    mocked_config.repo.is_dirty.assert_called_once_with(untracked_files=True)
    mocked_config.repo.git.add.assert_called_once_with(str(expected_path))
예제 #8
0
def test_checkout_no_repo(mocked_config):
    git_mixin = get_git_mixin_consumer()
    mocked_config.settings.dry_run = False
    mocked_repo_prop = PropertyMock(return_value=None)
    type(mocked_config).repo = mocked_repo_prop

    git_mixin.checkout_branch()

    mocked_repo_prop.assert_called_once_with()
예제 #9
0
def test_push_changes(mocked_config):
    expected_branch_name = "awesome_branch"
    git_mixin = get_git_mixin_consumer()
    mocked_config.settings.dry_run = False
    mocked_config.settings.git_branch_name = expected_branch_name

    git_mixin.push_changes()

    mocked_config.repo.remotes.origin.push.assert_called_once_with(expected_branch_name)
예제 #10
0
def test_git_remove(mocked_config):
    expected_path = Path("/tmp/path")
    git_mixin = get_git_mixin_consumer()
    mocked_config.settings.dry_run = False

    git_mixin.git_remove(expected_path)

    mocked_config.repo.index.remove.assert_called_once_with(
        (str(expected_path), ), ignore_unmatch=True, r=True)
예제 #11
0
def test_git_add_no_repo(mocked_config):
    expected_path = Path("/tmp/path")
    git_mixin = get_git_mixin_consumer()
    mocked_config.settings.dry_run = False
    mocked_repo_prop = PropertyMock(return_value=None)
    type(mocked_config).repo = mocked_repo_prop

    git_mixin.git_add(expected_path)

    mocked_repo_prop.assert_called_once_with()
예제 #12
0
def test_git_commit_no_staged_files(mocked_config):
    commit_message = "message"
    git_mixin = get_git_mixin_consumer()

    git_mixin.git_diff = Mock()
    git_mixin.git_diff.return_value = []

    mocked_config.settings.dry_run = False

    git_mixin.git_commit(commit_message)

    git_mixin.git_diff.assert_called_once_with(staged=True)
    assert mocked_config.repo.index.commit.called is False
예제 #13
0
def test_git_commit(mocked_config):
    commit_message = "message"
    git_mixin = get_git_mixin_consumer()

    git_mixin.git_diff = Mock()
    git_mixin.git_diff.return_value = [
        "git", "diff", "--staged", "a/test", "b/test"
    ]

    mocked_config.settings.dry_run = False

    git_mixin.git_commit(commit_message)

    git_mixin.git_diff.assert_called_once_with(staged=True)
    mocked_config.repo.index.commit.assert_called_once_with(commit_message)