Beispiel #1
0
    def test_commit_with_more_than_one_job(self):
        mocked_repo = MagicMock()

        message = 'just a simple message'
        jobs = [{
            'params': {
                'message': message,
                'add': ['path1', 'path2'],
                'remove': []
            }
        }, {
            'params': {
                'message': message,
                'remove': ['path2'],
                'add': []
            }
        }]
        author = ("name", "email")

        worker = SyncWorker(author[0],
                            author[1],
                            author[0],
                            author[1],
                            strategy="strategy",
                            repository=mocked_repo)
        worker.commit(jobs)

        asserted_message = "Update 2 items. Added 2 items. Removed 1 items."
        mocked_repo.commit.assert_called_once_with(asserted_message, author,
                                                   author)
        assert mocked_repo.commits.update.call_count == 1

        strategy = pygit2.GIT_CHECKOUT_FORCE
        mocked_repo.checkout_head.assert_called_once_with(strategy=strategy)
Beispiel #2
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 #3
0
    def test_commit_with_just_one_job(self):
        mocked_repo = MagicMock()

        message = 'just a simple message'
        jobs = [{'params': {'message': message}}]
        author = ("name", "email")

        worker = SyncWorker(author[0], author[1], author[0], author[1],
                            strategy="strategy",
                            repository=mocked_repo)
        worker.commit(jobs)

        mocked_repo.commit.assert_called_once_with(message, author, author)
        assert mocked_repo.commits.update.call_count == 1

        strategy = pygit2.GIT_CHECKOUT_FORCE
        mocked_repo.checkout_head.assert_called_once_with(strategy=strategy)
Beispiel #4
0
    def test_commit_with_just_one_job(self):
        mocked_repo = MagicMock()

        message = 'just a simple message'
        jobs = [{'params': {'message': message}}]
        author = ("name", "email")

        worker = SyncWorker(author[0], author[1], author[0], author[1],
                            strategy="strategy",
                            repository=mocked_repo)
        worker.commit(jobs)

        mocked_repo.commit.assert_called_once_with(message, author, author)
        assert mocked_repo.commits.update.call_count == 1

        strategy = pygit2.GIT_CHECKOUT_FORCE
        mocked_repo.checkout_head.assert_called_once_with(strategy=strategy)
Beispiel #5
0
    def test_commit_with_more_than_one_job(self):
        mocked_repo = MagicMock()

        message = 'just a simple message'
        jobs = [{'params': {'message': message, 'add': ['path1', 'path2'],
                            'remove': []}},
                {'params': {'message': message, 'remove': ['path2'],
                            'add': []}}]
        author = ("name", "email")

        worker = SyncWorker(author[0], author[1], author[0], author[1],
                            strategy="strategy",
                            repository=mocked_repo)
        worker.commit(jobs)

        asserted_message = "Update 2 items"
        mocked_repo.commit.assert_called_once_with(asserted_message, author,
                                                   author)
        assert mocked_repo.commits.update.call_count == 1

        strategy = pygit2.GIT_CHECKOUT_FORCE
        mocked_repo.checkout_head.assert_called_once_with(strategy=strategy)
Beispiel #6
0
    def test_commit_with_more_than_one_job(self):
        mocked_repo = MagicMock()

        message = "just a simple message"
        jobs = [
            {
                "params": {
                    "message": message,
                    "add": ["path1", "path2"],
                    "remove": []
                }
            },
            {
                "params": {
                    "message": message,
                    "remove": ["path2"],
                    "add": []
                }
            },
        ]
        author = ("name", "email")

        worker = SyncWorker(
            author[0],
            author[1],
            author[0],
            author[1],
            strategy="strategy",
            repository=mocked_repo,
        )
        worker.commit(jobs)

        asserted_message = "Update 2 items. Added 2 items. Removed 1 items."
        mocked_repo.commit.assert_called_once_with(asserted_message, author,
                                                   author)
        assert mocked_repo.commits.update.call_count == 1

        strategy = pygit2.GIT_CHECKOUT_FORCE
        mocked_repo.checkout_head.assert_called_once_with(strategy=strategy)
Beispiel #7
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