Beispiel #1
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 #2
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 #3
0
    def test_on_idle_with_commits_and_merges(self):
        mocked_sync = MagicMock()
        mocked_syncing = MagicMock()
        mocked_commit = MagicMock()

        mocked_syncing.is_set.return_value = False

        with patch.multiple("gitfs.worker.sync",
                            syncing=mocked_syncing,
                            writers=MagicMock(value=0)):
            worker = SyncWorker("name",
                                "email",
                                "name",
                                "email",
                                strategy="strategy")
            worker.commits = "commits"
            worker.commit = mocked_commit
            worker.sync = mocked_sync

            commits = worker.on_idle()

            mocked_commit.assert_called_once_with("commits")
            assert mocked_syncing.set.call_count == 1
            assert mocked_sync.call_count == 1
            assert commits is None
Beispiel #4
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 #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_on_idle_with_commits_and_merges(self):
        mocked_sync = MagicMock()
        mocked_syncing = MagicMock()
        mocked_commit = MagicMock()

        mocked_syncing.is_set.return_value = False

        with patch.multiple("gitfs.worker.sync", syncing=mocked_syncing,
                            writers=0):
            worker = SyncWorker("name", "email", "name", "email",
                                strategy="strategy")
            worker.commits = "commits"
            worker.commit = mocked_commit
            worker.sync = mocked_sync

            commits = worker.on_idle()

            mocked_commit.assert_called_once_with("commits")
            assert mocked_syncing.set.call_count == 1
            assert mocked_sync.call_count == 1
            assert commits is None