Exemplo n.º 1
0
def test_commit_succesfully_with_multiple_objects():
    mock_repo = MagicMock()

    mock_os = MagicMock()
    mock_env = MagicMock()
    mock_os.environ.copy.return_value = mock_env

    mock_git = MagicMock()

    with patch.multiple('pyolite.git', os=mock_os, git=mock_git):
        git = Git(mock_repo)

        objects = ['simple_object', 'more_complex_one']
        commit_message = 'simple commit message'

        git.commit(objects, commit_message)

    mock_os.environ.copy.assert_called_once_with()
    mock_env.update.assert_called_once_with({
        'GIT_WORK_TREE': mock_repo,
        'GIT_DIR': '%s/.git' % mock_repo
    })
    mock_git.gc.assert_called_once_with('--force', '--prune', _env=mock_env)
    mock_git.checkout.assert_called_once_with('HEAD', _env=mock_env)
    mock_git.pull("origin", "master", _env=mock_env)

    mock_git.add.assert_has_calls([
        call('-A', objects[0], _env=mock_env),
        call('-A', objects[1], _env=mock_env)
    ])

    mock_git.commit.assert_called_once_with('-m',
                                            commit_message,
                                            _env=mock_env)
    mock_git.push.assert_called_once_with(_env=mock_env)
Exemplo n.º 2
0
def test_commit_with_no_message():
    mock_repo = MagicMock()

    git = Git(mock_repo)
    objects = ['simple_object', 'more_complex_one']
    with pytest.raises(ValueError):
        git.commit(objects, '')
Exemplo n.º 3
0
def test_commit_succesfully_with_multiple_objects():
    mock_repo = MagicMock()

    mock_os = MagicMock()
    mock_env = MagicMock()
    mock_os.environ.copy.return_value = mock_env

    mock_git = MagicMock()

    with patch.multiple('pyolite.git', os=mock_os, git=mock_git):
        git = Git(mock_repo)

        objects = ['simple_object', 'more_complex_one']
        commit_message = 'simple commit message'

        git.commit(objects, commit_message)

    mock_os.environ.copy.assert_called_once_with()
    mock_env.update.assert_called_once_with({'GIT_WORK_TREE': mock_repo,
                                             'GIT_DIR': '%s/.git' % mock_repo})
    mock_git.gc.assert_called_once_with('--force', '--prune', _env=mock_env)
    mock_git.checkout.assert_called_once_with('HEAD', _env=mock_env)
    mock_git.pull("origin", "master", _env=mock_env)

    mock_git.add.assert_has_calls([call('-A', objects[0], _env=mock_env),
                                   call('-A', objects[1], _env=mock_env)])

    mock_git.commit.assert_called_once_with('-m', commit_message, _env=mock_env)
    mock_git.push.assert_called_once_with(_env=mock_env)
Exemplo n.º 4
0
    def test_commit_with_no_message(self):
        mock_repo = MagicMock()

        git = Git(mock_repo)
        objects = ['simple_object', 'more_complex_one']

        git.commit(objects, '')
Exemplo n.º 5
0
def test_commit_with_no_message():
    mock_repo = MagicMock()

    with pytest.raises(ValueError):
        git = Git(mock_repo)
        objects = ['simple_object', 'more_complex_one']

        git.commit(objects, '')
Exemplo n.º 6
0
    def test_commit_with_no_message(self):
        mock_repo = MagicMock()
        mock_index = MagicMock()
        mock_remotes = MagicMock()

        mock_repo.index = mock_index
        mock_repo.remotes.origin = mock_remotes

        with patch.multiple('pyolite.repo', Repo=mock_repo):
            git = Git('~/path/to/repo')
            objects = ['simple_object', 'more_complex_one']

            git.commit(objects, '')
Exemplo n.º 7
0
    def test_commit_succesfully_with_multiple_objects(self):
        mock_repo = MagicMock()
        mock_index = MagicMock()
        mock_remotes = MagicMock()

        mock_repo.index = mock_index
        mock_repo.remotes.origin = mock_remotes

        with patch.multiple('pyolite.repo', Repo=MagicMock(return_value=mock_repo)):
            git = Git('~/path/to/repo')

            objects = ['simple_object', 'more_complex_one']
            commit_message = 'simple commit message'

            git.commit(objects, commit_message)
            git.commit(objects, commit_message, action='remove')

        mock_index.add.assert_called_once_with(objects)
        mock_index.remove.assert_called_once_with(objects)
        mock_index.commit.has_calls([call(commit_message), call(commit_message)])

        eq_(mock_remotes.fetch.call_count, 2)
        eq_(mock_remotes.pull.call_count, 2)
        eq_(mock_remotes.push.call_count, 2)
Exemplo n.º 8
0
    def __init__(self, admin_repository):
        self.path = Path(admin_repository)
        self.git = Git(admin_repository)

        if not self.path.isdir():
            raise ValueError('Admin repository path should point to directory')