Exemplo n.º 1
0
    def get_fake_vcs(self, log_results=None):
        def _log_results(parent=None, branch=None, offset=0, limit=1):
            assert not branch
            return iter([
                RevisionResult(
                    id='a' * 40,
                    message='hello world',
                    author='Foo <*****@*****.**>',
                    author_date=datetime.utcnow(),
                )
            ])

        if log_results is None:
            log_results = _log_results
        # Fake having a VCS and stub the returned commit log
        fake_vcs = mock.Mock(spec=Vcs)
        fake_vcs.read_file.side_effect = CommandError(cmd="test command",
                                                      retcode=128)
        fake_vcs.exists.return_value = True
        fake_vcs.log.side_effect = UnknownRevision(cmd="test command",
                                                   retcode=128)
        fake_vcs.export.side_effect = UnknownRevision(cmd="test command",
                                                      retcode=128)
        fake_vcs.get_patch_hash.return_value = 'a' * 40

        def fake_update():
            # this simulates the effect of calling update() on a repo,
            # mainly that `export` and `log` now works.
            fake_vcs.log.side_effect = log_results
            fake_vcs.export.side_effect = None
            fake_vcs.export.return_value = SAMPLE_DIFF_BYTES

        fake_vcs.update.side_effect = fake_update

        return fake_vcs
Exemplo n.º 2
0
    def test_simple(self, get_vcs_backend):
        vcs_backend = mock.MagicMock(spec=Vcs)
        get_vcs_backend.return_value = vcs_backend
        vcs_backend.update = mock.Mock()

        num_active_repos = 2
        for i in range(num_active_repos):
            self.create_repo(backend=RepositoryBackend.git)

        inactive_repo = self.create_repo(backend=RepositoryBackend.git)
        inactive_repo.status = RepositoryStatus.inactive
        unknown_backend_repo = self.create_repo(
            backend=RepositoryBackend.unknown)
        unknown_backend_repo.get_vcs = lambda: None
        db.session.commit()

        update_local_repos()
        assert vcs_backend.update.call_count == num_active_repos

        # Even if an update fails, make sure we still try to update for each repo
        vcs_backend = mock.MagicMock(spec=Vcs)
        get_vcs_backend.return_value = vcs_backend
        vcs_backend.update = mock.Mock(side_effect=CommandError('xyz', 1))

        update_local_repos()
        assert vcs_backend.update.call_count == num_active_repos
Exemplo n.º 3
0
 def _log_results(parent=None, branch=None, offset=0, limit=1):
     assert not branch
     if parent not in (None, _VALID_SHA):
         raise CommandError(cmd="test command", retcode=128)
     return iter([
         RevisionResult(
             id=_VALID_SHA,
             message='hello world',
             author='Foo <*****@*****.**>',
             author_date=datetime.utcnow(),
         )
     ])
Exemplo n.º 4
0
 def throw(*args, **kwargs):
     raise CommandError('test command', 128)