Beispiel #1
0
    def test_merge(self):
        mocked_strategy = MagicMock()
        mocked_repo = MagicMock()
        upstream = "origin"
        branch = "master"

        worker = SyncWorker("name", "email", "name", "email",
                            strategy=mocked_strategy,
                            repository=mocked_repo,
                            upstream=upstream, branch=branch)
        worker.merge()

        mocked_strategy.assert_called_once_with(branch, branch, upstream)
        assert mocked_repo.commits.update.call_count == 1
Beispiel #2
0
    def test_merge(self):
        mocked_strategy = MagicMock()
        mocked_repo = MagicMock()
        upstream = "origin"
        branch = "master"

        worker = SyncWorker("name", "email", "name", "email",
                            strategy=mocked_strategy,
                            repository=mocked_repo,
                            upstream=upstream, branch=branch)
        worker.merge()

        mocked_strategy.assert_called_once_with(branch, branch, upstream)
        assert mocked_repo.commits.update.call_count == 1
Beispiel #3
0
    def test_sync(self):
        upstream = "origin"
        branch = "master"
        mocked_repo = MagicMock()
        mocked_merge = MagicMock()
        mocked_sync_done = MagicMock()
        mocked_syncing = MagicMock()
        mocked_push_successful = MagicMock()
        mocked_fetch = MagicMock()
        mocked_strategy = MagicMock()

        mocked_repo.behind = True
        mocked_push_successful.set.side_effect = ValueError

        with patch.multiple('gitfs.worker.sync', sync_done=mocked_sync_done,
                            syncing=mocked_syncing,
                            push_successful=mocked_push_successful,
                            fetch=mocked_fetch):
            worker = SyncWorker("name", "email", "name", "email",
                                repository=mocked_repo,
                                strategy=mocked_strategy,
                                upstream=upstream, branch=branch)
            worker.merge = mocked_merge

            worker.sync()

            assert mocked_syncing.clear.call_count == 1
            assert mocked_push_successful.clear.call_count == 1
            assert mocked_sync_done.clear.call_count == 1
            assert mocked_sync_done.set.call_count == 1
            assert mocked_fetch.set.call_count == 1
            assert mocked_push_successful.set.call_count == 1
            assert mocked_repo.behind is False
            mocked_repo.push.assert_called_once_with(upstream, branch)
Beispiel #4
0
    def test_sync(self):
        upstream = "origin"
        branch = "master"
        mocked_repo = MagicMock()
        mocked_merge = MagicMock()
        mocked_sync_done = MagicMock()
        mocked_syncing = MagicMock()
        mocked_push_successful = MagicMock()
        mocked_fetch = MagicMock()
        mocked_strategy = MagicMock()

        mocked_repo.behind = True
        mocked_push_successful.set.side_effect = ValueError

        with patch.multiple('gitfs.worker.sync', sync_done=mocked_sync_done,
                            syncing=mocked_syncing,
                            push_successful=mocked_push_successful,
                            fetch=mocked_fetch):
            worker = SyncWorker("name", "email", "name", "email",
                                repository=mocked_repo,
                                strategy=mocked_strategy,
                                upstream=upstream, branch=branch)
            worker.merge = mocked_merge

            worker.sync()

            assert mocked_syncing.clear.call_count == 1
            assert mocked_push_successful.clear.call_count == 1
            assert mocked_sync_done.clear.call_count == 1
            assert mocked_sync_done.set.call_count == 1
            assert mocked_fetch.set.call_count == 1
            assert mocked_push_successful.set.call_count == 1
            assert mocked_repo.behind is False
            mocked_repo.push.assert_called_once_with(upstream, branch)
Beispiel #5
0
    def test_sync_with_push_conflict(self):
        upstream = "origin"
        branch = "master"
        credentials = "credentials"
        mocked_repo = MagicMock()
        mocked_merge = MagicMock()
        mocked_sync_done = MagicMock()
        mocked_syncing = MagicMock()
        mocked_push_successful = MagicMock()
        mocked_fetch = MagicMock()
        mocked_strategy = MagicMock()

        mocked_repo.behind = True
        mocked_repo.ahead = MagicMock(1)
        mocked_repo.push.side_effect = [GitError("Mocked error"), None]

        with patch.multiple(
                "gitfs.worker.sync",
                sync_done=mocked_sync_done,
                syncing=mocked_syncing,
                push_successful=mocked_push_successful,
                fetch=mocked_fetch,
        ):
            worker = SyncWorker(
                "name",
                "email",
                "name",
                "email",
                repository=mocked_repo,
                strategy=mocked_strategy,
                credentials=credentials,
                upstream=upstream,
                branch=branch,
            )
            worker.merge = mocked_merge

            while not worker.sync():
                pass

            assert mocked_syncing.clear.call_count == 1
            assert mocked_push_successful.clear.call_count == 1
            assert mocked_sync_done.clear.call_count == 2
            assert mocked_sync_done.set.call_count == 1
            assert mocked_fetch.set.call_count == 1
            assert mocked_push_successful.set.call_count == 1
            assert mocked_repo.behind is False
            assert mocked_repo.ahead.call_count == 2

            mocked_repo.push.assert_has_calls([
                call(upstream, branch, credentials),
                call(upstream, branch, credentials),
            ])
Beispiel #6
0
    def test_sync_with_push_conflict(self):
        upstream = "origin"
        branch = "master"
        credentials = "credentials"
        mocked_repo = MagicMock()
        mocked_merge = MagicMock()
        mocked_sync_done = MagicMock()
        mocked_syncing = MagicMock()
        mocked_push_successful = MagicMock()
        mocked_fetch = MagicMock()
        mocked_strategy = MagicMock()

        mocked_repo.behind = True
        mocked_repo.ahead = MagicMock(1)
        mocked_repo.push.side_effect = [GitError("Mocked error"), None]

        with patch.multiple('gitfs.worker.sync', sync_done=mocked_sync_done,
                            syncing=mocked_syncing,
                            push_successful=mocked_push_successful,
                            fetch=mocked_fetch):
            worker = SyncWorker("name", "email", "name", "email",
                                repository=mocked_repo,
                                strategy=mocked_strategy,
                                credentials=credentials,
                                upstream=upstream, branch=branch)
            worker.merge = mocked_merge

            while not worker.sync():
                pass

            assert mocked_syncing.clear.call_count == 1
            assert mocked_push_successful.clear.call_count == 1
            assert mocked_sync_done.clear.call_count == 2
            assert mocked_sync_done.set.call_count == 1
            assert mocked_fetch.set.call_count == 1
            assert mocked_push_successful.set.call_count == 1
            assert mocked_repo.behind is False
            assert mocked_repo.ahead.call_count == 2

            mocked_repo.push.assert_has_calls([call(upstream, branch, credentials),
                                               call(upstream, branch, credentials)])