def test_raw(self):
        project = self.create_project()
        build = self.create_build(project)
        job = self.create_job(build)
        source = LogSource(job=job, project=project, name='test')
        db.session.add(source)

        lc1 = LogChunk(
            job=job,
            project=project,
            source=source,
            offset=0,
            size=100,
            text='a' * 100,
        )
        db.session.add(lc1)
        lc2 = LogChunk(
            job=job,
            project=project,
            source=source,
            offset=100,
            size=100,
            text='b' * 100,
        )
        db.session.add(lc2)
        db.session.commit()

        path = '/api/0/jobs/{0}/logs/{1}/?raw=1'.format(
            job.id.hex, source.id.hex)

        resp = self.client.get(path)
        assert resp.status_code == 200
        assert resp.headers['Content-Type'] == 'text/plain; charset=utf-8'
        assert resp.data == lc1.text + lc2.text
    def test_simple(self):
        project = self.create_project()
        build = self.create_build(project)
        job = self.create_job(build)

        logsource = LogSource(
            project=project,
            job=job,
            name='console',
        )
        db.session.add(logsource)

        logchunk = LogChunk(
            project=project,
            job=job,
            source=logsource,
            offset=0,
            size=11,
            text='hello\nworld\n',
        )
        db.session.add(logchunk)
        logchunk = LogChunk(
            project=project,
            job=job,
            source=logsource,
            offset=11,
            size=11,
            text='hello\nworld\n',
        )
        db.session.add(logchunk)
        db.session.commit()

        result = build_context_lib._get_log_clipping(logsource,
                                                     max_size=200,
                                                     max_lines=3)
        assert result == "world\r\nhello\r\nworld"

        result = build_context_lib._get_log_clipping(logsource,
                                                     max_size=200,
                                                     max_lines=1)
        assert result == "world"

        result = build_context_lib._get_log_clipping(logsource,
                                                     max_size=5,
                                                     max_lines=3)
        assert result == "world"
Exemplo n.º 3
0
    def create_logchunk(self, source, text=None, **kwargs):
        # TODO(dcramer): we should default offset to previous entry in LogSource
        kwargs.setdefault('offset', 0)
        kwargs['job'] = source.job
        kwargs['project'] = source.project

        if text is None:
            text = '\n'.join(get_sentences(4))

        logchunk = LogChunk(source=source, text=text, size=len(text), **kwargs)
        db.session.add(logchunk)
        db.session.commit()

        return logchunk
Exemplo n.º 4
0
def logchunk(source, **kwargs):
    # TODO(dcramer): we should default offset to previous entry in LogSource
    kwargs.setdefault('offset', 0)

    text = kwargs.pop('text', None) or '\n'.join(get_sentences(4))

    logchunk = LogChunk(source=source,
                        job=source.job,
                        project=source.project,
                        text=text,
                        size=len(text),
                        **kwargs)
    db.session.add(logchunk)
    return logchunk
    def test_simple(self):
        project = self.create_project()
        build = self.create_build(project)
        job = self.create_job(build)
        source = LogSource(job=job, project=project, name='test')
        db.session.add(source)

        lc1 = LogChunk(
            job=job,
            project=project,
            source=source,
            offset=0,
            size=100,
            text='a' * 100,
        )
        db.session.add(lc1)
        lc2 = LogChunk(
            job=job,
            project=project,
            source=source,
            offset=100,
            size=100,
            text='b' * 100,
        )
        db.session.add(lc2)
        db.session.commit()

        path = '/api/0/jobs/{0}/logs/{1}/'.format(job.id.hex, source.id.hex)

        resp = self.client.get(path)
        assert resp.status_code == 200
        data = self.unserialize(resp)
        assert data['source']['id'] == source.id.hex
        assert data['nextOffset'] == 201
        assert len(data['chunks']) == 2
        assert data['chunks'][0]['text'] == lc1.text
        assert data['chunks'][1]['text'] == lc2.text
Exemplo n.º 6
0
def test_simple():
    logchunk = LogChunk(
        id=UUID(hex='33846695b2774b29a71795a009e8168a'),
        source_id=UUID(hex='0b61b8a47ec844918d372d5741187b1c'),
        source=LogSource(id=UUID(hex='0b61b8a47ec844918d372d5741187b1c')),
        offset=10,
        size=7,
        text='\x1b[0;36mnotice: foo bar',
        date_created=datetime(2013, 9, 19, 22, 15, 22),
    )
    result = serialize(logchunk)
    assert result['id'] == '33846695b2774b29a71795a009e8168a'
    assert result['source']['id'] == '0b61b8a47ec844918d372d5741187b1c'
    assert result['text'] == '\x1b[0;36mnotice: foo bar'
    assert result['size'] == 7
    assert result['offset'] == 10