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
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): build = self.create_build(self.project) job = self.create_job(build) ls1 = LogSource(job=job, project=self.project, name='test') db.session.add(ls1) ls2 = LogSource(job=job, project=self.project, name='test2') db.session.add(ls2) db.session.commit() path = '/api/0/jobs/{0}/'.format(job.id.hex) resp = self.client.get(path) assert resp.status_code == 200 data = self.unserialize(resp) assert data['id'] == job.id.hex assert len(data['logs']) == 2 assert data['logs'][0]['id'] == ls1.id.hex assert data['logs'][1]['id'] == ls2.id.hex
def create_logsource(self, step=None, **kwargs): if step: kwargs['job'] = step.job kwargs['project'] = kwargs['job'].project logsource = LogSource(step=step, **kwargs) db.session.add(logsource) db.session.commit() return logsource
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'] == '<span class="ansi36">notice: foo bar</span>' assert result['size'] == 7 assert result['offset'] == 10
def test_simple(): logsource = LogSource( id=UUID(hex='33846695b2774b29a71795a009e8168a'), job_id=UUID(hex='2e18a7cbc0c24316b2ef9d41fea191d6'), job=Job(id=UUID(hex='2e18a7cbc0c24316b2ef9d41fea191d6')), step=JobStep( id=UUID(hex='36c7af5e56aa4a7fbf076e13ac00a866'), phase_id=UUID(hex='46c7af5e56aa4a7fbf076e13ac00a866') ), name='console', date_created=datetime(2013, 9, 19, 22, 15, 22), ) result = serialize(logsource) assert result['id'] == '33846695b2774b29a71795a009e8168a' assert result['name'] == 'console' assert result['dateCreated'] == '2013-09-19T22:15:22' assert result['step']['id'] == '36c7af5e56aa4a7fbf076e13ac00a866'
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() handler = NotificationHandler() result = handler.get_log_clipping(logsource, max_size=200, max_lines=3) assert result == "world\r\nhello\r\nworld" result = handler.get_log_clipping(logsource, max_size=200, max_lines=1) assert result == "world" result = handler.get_log_clipping(logsource, max_size=5, max_lines=3) assert result == "world"
def test_simple(self): project = self.project build = self.create_build(project) job = self.create_job(build) phase_1 = JobPhase( job_id=job.id, project_id=job.project_id, label='Setup', status=Status.finished, result=Result.passed, date_created=datetime(2013, 9, 19, 22, 15, 22), date_started=datetime(2013, 9, 19, 22, 15, 23), date_finished=datetime(2013, 9, 19, 22, 15, 25), ) db.session.add(phase_1) step_1 = JobStep( job_id=job.id, phase_id=phase_1.id, project_id=job.project_id, label='ci/setup', status=Status.finished, result=Result.passed, date_created=datetime(2013, 9, 19, 22, 15, 22), date_started=datetime(2013, 9, 19, 22, 15, 23), date_finished=datetime(2013, 9, 19, 22, 15, 25), ) db.session.add(step_1) phase_2 = JobPhase( job_id=job.id, project_id=job.project_id, label='Test', status=Status.finished, result=Result.failed, date_created=datetime(2013, 9, 19, 22, 15, 23), date_started=datetime(2013, 9, 19, 22, 15, 24), date_finished=datetime(2013, 9, 19, 22, 15, 26), ) db.session.add(phase_2) step_2_a = JobStep( job_id=job.id, phase_id=phase_2.id, project_id=job.project_id, label='test_foo.py', status=Status.finished, result=Result.passed, date_created=datetime(2013, 9, 19, 22, 15, 23), date_started=datetime(2013, 9, 19, 22, 15, 23), date_finished=datetime(2013, 9, 19, 22, 15, 25), ) db.session.add(step_2_a) step_2_b = JobStep( job_id=job.id, phase_id=phase_2.id, project_id=job.project_id, label='test_bar.py', status=Status.finished, result=Result.failed, date_created=datetime(2013, 9, 19, 22, 15, 24), date_started=datetime(2013, 9, 19, 22, 15, 24), date_finished=datetime(2013, 9, 19, 22, 15, 26), ) db.session.add(step_2_b) db.session.commit() logsource_1 = LogSource( job_id=job.id, step_id=step_1.id, project_id=job.project_id, name='test_bar.py', date_created=datetime(2013, 9, 19, 22, 15, 24), ) db.session.add(logsource_1) db.session.commit() path = '/api/0/jobs/{0}/phases/'.format(job.id.hex) resp = self.client.get(path) assert resp.status_code == 200 data = self.unserialize(resp) assert len(data) == 2 assert data[0]['id'] == phase_1.id.hex assert len(data[0]['steps']) == 1 assert data[0]['steps'][0]['id'] == step_1.id.hex assert len(data[0]['steps'][0]['logSources']) == 1 assert data[0]['steps'][0]['logSources'][0]['id'] == logsource_1.id.hex assert data[1]['id'] == phase_2.id.hex assert len(data[1]['steps']) == 2 assert data[1]['steps'][0]['id'] == step_2_a.id.hex assert len(data[1]['steps'][0]['logSources']) == 0 assert data[1]['steps'][1]['id'] == step_2_b.id.hex assert len(data[1]['steps'][1]['logSources']) == 0
def create_new_entry(project): new_change = (random.randint(0, 2) == 1) if not new_change: try: change = Change.query.all()[0] except IndexError: new_change = True if new_change: author = mock.author() revision = mock.revision(project.repository, author) change = create_new_change( project=project, author=author, message=revision.message, ) else: change.date_modified = datetime.utcnow() db.session.add(change) revision = mock.revision(project.repository, change.author) if random.randint(0, 1) == 1: patch = mock.patch(project) else: patch = None source = mock.source(project.repository, revision_sha=revision.sha, patch=patch) date_started = datetime.utcnow() build = mock.build( author=change.author, project=project, source=source, message=change.message, result=Result.unknown, status=Status.in_progress, date_started=date_started, ) db.session.commit() publish_build_update(build) for x in xrange(0, random.randint(1, 3)): job = mock.job( build=build, change=change, status=Status.in_progress, ) db.session.commit() publish_job_update(job) for step in JobStep.query.filter(JobStep.job == job): logsource = LogSource( job=job, project=job.project, step=step, name=step.label, ) db.session.add(logsource) db.session.commit() offset = 0 for x in xrange(30): lc = mock.logchunk(source=logsource, offset=offset) db.session.commit() offset += lc.size return build
def create_new_build(change, source, patch, project): date_started = datetime.utcnow() build = mock.build( author=change.author, project=project, source=source, message=change.message, result=Result.failed if random.randint(0, 3) == 1 else Result.unknown, status=Status.in_progress, date_started=date_started, ) build_task = fixtures.create_task( task_id=build.id, task_name='sync_build', data={'kwargs': { 'build_id': build.id.hex }}, ) db.session.add(ItemStat(item_id=build.id, name='lines_covered', value='5')) db.session.add( ItemStat(item_id=build.id, name='lines_uncovered', value='5')) db.session.add( ItemStat(item_id=build.id, name='diff_lines_covered', value='5')) db.session.add( ItemStat(item_id=build.id, name='diff_lines_uncovered', value='5')) db.session.commit() for x in xrange(0, random.randint(1, 3)): job = mock.job( build=build, change=change, status=Status.in_progress, result=build.result, ) fixtures.create_task( task_id=job.id.hex, parent_id=build_task.task_id, task_name='sync_job', data={'kwargs': { 'job_id': job.id.hex }}, ) db.session.commit() if patch: mock.file_coverage(project, job, patch) for step in JobStep.query.filter(JobStep.job == job): logsource = LogSource( job=job, project=job.project, step=step, name=step.label, ) db.session.add(logsource) db.session.commit() fixtures.create_artifact( step=step, name='junit.xml', ) fixtures.create_artifact( step=step, name='coverage.xml', ) offset = 0 for x in xrange(30): lc = mock.logchunk(source=logsource, offset=offset) db.session.commit() offset += lc.size return build