Exemplo n.º 1
0
    def test_process_behavior(self):
        handler = Mock()

        manager = Manager()
        manager.register(handler, ['coverage.xml'])

        project = self.create_project()
        build = self.create_build(project)
        job = self.create_job(build)
        jobphase = self.create_jobphase(job)
        jobstep = self.create_jobstep(jobphase)

        artifact = self.create_artifact(
            step=jobstep,
            name='junit.xml',
        )
        artifact.file.save(StringIO(), artifact.name)
        manager.process(artifact)

        assert not handler.called

        artifact = self.create_artifact(
            step=jobstep,
            name='coverage.xml',
        )
        artifact.file.save(StringIO(), artifact.name)
        manager.process(artifact)

        handler.assert_called_once_with(jobstep)
        handler.return_value.process.assert_called_once()
Exemplo n.º 2
0
    def test_process_too_large(self, report_malformed, process):
        max_artifact_bytes = 500

        # artifact name => [size, expected to be processed]
        file_sizes = {
            'very_large/size.xml': (max_artifact_bytes * 2, False),
            'large/size.xml': (max_artifact_bytes, True),
            'small/size.xml': (max_artifact_bytes / 2, True),
        }

        class _Handler(ArtifactHandler):
            FILENAMES = ('size.xml',)

            def __init__(self, step):
                super(_Handler, self).__init__(step)
                self.max_artifact_bytes = max_artifact_bytes

        manager = Manager([_Handler])
        jobstep = self.create_any_jobstep()

        for name, (size, expected_process) in file_sizes.iteritems():
            process.reset_mock()
            report_malformed.reset_mock()
            artifact = self.create_artifact(
                step=jobstep,
                name=name,
            )
            artifact.file.save(StringIO('a' * size), artifact.name)
            manager.process(artifact)
            assert expected_process == process.called, \
                "Incorrectly handled %s." % (artifact.name,)
            assert expected_process != report_malformed.called, \
                "Incorrectly handled %s." % (artifact.name,)
Exemplo n.º 3
0
 def get_artifact_manager(self, jobstep):
     handlers = [
         CoverageHandler, XunitHandler, ManifestJsonHandler,
         AnalyticsJsonHandler
     ]
     if self.debug_config.get('fetch_jenkins_logs'):
         handlers.append(DummyLogFileHandler)
     return Manager(handlers)
Exemplo n.º 4
0
    def test_process_behavior(self, process):
        class _CovHandler(ArtifactHandler):
            FILENAMES = ('coverage.xml',)

        class _OtherHandler(ArtifactHandler):
            FILENAMES = ('/other.xml',)

        manager = Manager([_CovHandler, _OtherHandler])
        jobstep = self.create_any_jobstep()

        artifact = self.create_artifact(
            step=jobstep,
            name='junit.xml',
        )
        artifact.file.save(StringIO(), artifact.name)
        manager.process(artifact)

        assert not process.called

        artifact = self.create_artifact(
            step=jobstep,
            name='coverage.xml',
        )
        artifact.file.save(StringIO(), artifact.name)
        manager.process(artifact)

        artifact = self.create_artifact(
            step=jobstep,
            name='foo/coverage.xml',
        )
        artifact.file.save(StringIO(), artifact.name)
        manager.process(artifact)

        assert process.call_count == 2

        artifact = self.create_artifact(
            step=jobstep,
            name='artifactstore/other.xml'
        )
        artifact.file.save(StringIO(), artifact.name)
        manager.process(artifact)

        assert process.call_count == 3

        # shouldn't process this
        artifact = self.create_artifact(
            step=jobstep,
            name='artifactstore/foo/other.xml'
        )
        artifact.file.save(StringIO(), artifact.name)
        manager.process(artifact)

        assert process.call_count == 3
Exemplo n.º 5
0
    def test_can_process(self):
        class _CovHandler(ArtifactHandler):
            FILENAMES = ('coverage.xml',)

        class _OtherHandler(ArtifactHandler):
            FILENAMES = ('other.xml',)

        manager = Manager()
        manager.register(_CovHandler)
        manager.register(_OtherHandler)

        assert manager.can_process('foo/coverage.xml')
        assert manager.can_process('other.xml')
        assert not manager.can_process('service.log')
Exemplo n.º 6
0
    def test_can_process(self):
        class _CovHandler(ArtifactHandler):
            FILENAMES = ('coverage.xml',)

        class _OtherHandler(ArtifactHandler):
            FILENAMES = ('/other.xml', 'foo/*/weird.json')

        manager = Manager([_CovHandler, _OtherHandler])

        assert manager.can_process('foo/coverage.xml')
        assert manager.can_process('other.xml')
        assert manager.can_process('artifactstore/other.xml')
        assert manager.can_process('foo/bar/weird.json')
        assert manager.can_process('artifactstore/foo/bar/weird.json')
        assert not manager.can_process('foo/other.xml')
        assert not manager.can_process('bar/foo/baz/weird.json')
        assert not manager.can_process('service.log')
Exemplo n.º 7
0
    def test_process_behavior(self, process):
        handler = ArtifactHandler
        handler.FILENAMES = ('coverage.xml', )

        manager = Manager()
        manager.register(handler)

        project = self.create_project()
        build = self.create_build(project)
        job = self.create_job(build)
        jobphase = self.create_jobphase(job)
        jobstep = self.create_jobstep(jobphase)

        artifact = self.create_artifact(
            step=jobstep,
            name='junit.xml',
        )
        artifact.file.save(StringIO(), artifact.name)
        manager.process(artifact)

        assert not process.called

        artifact = self.create_artifact(
            step=jobstep,
            name='coverage.xml',
        )
        artifact.file.save(StringIO(), artifact.name)
        manager.process(artifact)

        artifact = self.create_artifact(
            step=jobstep,
            name='foo/coverage.xml',
        )
        artifact.file.save(StringIO(), artifact.name)
        manager.process(artifact)

        assert process.call_count == 2
Exemplo n.º 8
0
 def get_artifact_manager(self, jobstep):
     return Manager([CoverageHandler, XunitHandler])
Exemplo n.º 9
0
 def get_artifact_manager(self, jobstep):
     if jobstep.data.get('expanded'):
         return super(JenkinsTestCollectorBuilder,
                      self).get_artifact_manager(jobstep)
     else:
         return Manager([self.get_required_handler(), ManifestJsonHandler])
Exemplo n.º 10
0
 def get_artifact_manager(self, jobstep):
     return Manager([
         CoverageHandler, BazelTargetHandler, XunitHandler,
         AnalyticsJsonHandler
     ])