def test_simple(self): node = self.create_node() build = self.create_build(self.project) job = self.create_job(build) phase = JobPhase( job=job, project=self.project, label='test', ) db.session.add(phase) jobstep = JobStep( job=job, project=self.project, phase=phase, node=node, label='test', ) db.session.add(jobstep) db.session.commit() path = '/api/0/nodes/{0}/jobs/'.format(node.id.hex) resp = self.client.get(path) assert resp.status_code == 200 data = self.unserialize(resp) assert len(data) == 1 assert data[0]['id'] == job.id.hex
def test_result_generation(): jobstep = JobStep( id=uuid.uuid4(), project_id=uuid.uuid4(), job_id=uuid.uuid4(), ) fp = StringIO(SAMPLE_XUNIT) handler = XunitHandler(jobstep) results = handler.get_tests(fp) assert len(results) == 2 r1 = results[0] assert type(r1) == TestResult assert r1.step == jobstep assert r1.package is None assert r1.name == 'tests.test_report' assert r1.duration == 0.0 assert r1.result == Result.failed assert r1.message == """tests/test_report.py:1: in <module> > import mock E ImportError: No module named mock""" r2 = results[1] assert type(r2) == TestResult assert r2.step == jobstep assert r2.package is None assert r2.name == 'tests.test_report.ParseTestResultsTest.test_simple' assert r2.duration == 1.65796279907 assert r2.result == Result.passed assert r2.message == '' assert r2.reruns == 1
def test_empty_cobertura_file(self): jobstep = JobStep( id=uuid.uuid4(), job=Job(id=uuid.uuid4(), project_id=uuid.uuid4()) ) fp = StringIO('') handler = CoverageHandler(jobstep) results = handler.get_coverage(fp) # most importantly, it shouldn't crash assert len(results) == 0
def create_jobstep(self, phase, **kwargs): kwargs.setdefault('label', phase.label) kwargs.setdefault('result', phase.result) kwargs.setdefault('status', phase.status) step = JobStep(job=phase.job, project=phase.project, phase=phase, **kwargs) db.session.add(step) db.session.commit() return step
def test_result_generation_when_a_quarantined_test_has_two_cases(): jobstep = JobStep( id=uuid.uuid4(), project_id=uuid.uuid4(), job_id=uuid.uuid4(), ) fp = StringIO( SAMPLE_XUNIT_DOUBLE_CASES.replace( '<testcase c', '<testcase quarantined="1" c', 1).replace('<testcase c', '<testcase quarantined="1" c', 1)) handler = XunitHandler(jobstep) results = handler.get_tests(fp) assert len(results) == 2 r1 = results[0] assert type(r1) is TestResult assert r1.step == jobstep assert r1.package is None assert r1.name == 'test_simple.SampleTest.test_falsehood' assert r1.duration == 750.0 assert r1.result == Result.quarantined_failed assert r1.message == """\ test_simple.py:8: in test_falsehood assert False E AssertionError: assert False test_simple.py:4: in tearDown 1/0 E ZeroDivisionError: integer division or modulo by zero""" assert r1.reruns == 0 r2 = results[1] assert type(r2) is TestResult assert r2.step == jobstep assert r2.package is None assert r2.name == 'test_simple.SampleTest.test_truth' assert r2.duration == 1250.0 assert r2.result == Result.failed assert r2.message == """\ test_simple.py:4: in tearDown 1/0 E ZeroDivisionError: integer division or modulo by zero""" assert r2.reruns == 0
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_jacoco_result_generation(self): jobstep = JobStep( id=uuid.uuid4(), job=Job(id=uuid.uuid4(), project_id=uuid.uuid4()) ) handler = CoverageHandler(jobstep) with open(os.path.join(os.path.dirname(__file__), 'fixtures', 'jacoco-coverage.xml')) as fp: results = handler.get_coverage(fp) assert len(results) == 1 r1 = results[0] assert type(r1) == FileCoverage assert r1.job_id == jobstep.job.id assert r1.project_id == jobstep.job.project_id assert r1.filename == 'src/main/java/com/dropbox/apx/onyx/api/resource/stats/StatsResource.java' assert r1.data == 'NNNNCCCCNNCCUU'
def test_result_generation(): jobstep = JobStep(id=uuid.uuid4(), job=Job(id=uuid.uuid4(), project_id=uuid.uuid4())) fp = StringIO(SAMPLE_COVERAGE) handler = CoverageHandler(jobstep) results = handler.get_coverage(fp) assert len(results) == 2 r1 = results[0] assert type(r1) == FileCoverage assert r1.job_id == jobstep.job.id assert r1.project_id == jobstep.job.project_id assert r1.filename == 'setup.py' assert r1.data == 'NUNNNNNNNNNUCCNU' r2 = results[1] assert type(r2) == FileCoverage assert r2.job_id == jobstep.job.id assert r2.project_id == jobstep.job.project_id assert r2.data == 'CCCNNNU'
def job(build, change=None, **kwargs): kwargs.setdefault('project', build.project) kwargs.setdefault('label', get_sentences(1)[0][:128]) kwargs.setdefault('status', Status.finished) kwargs.setdefault('result', Result.passed) kwargs.setdefault('duration', random.randint(10000, 100000)) kwargs['source'] = build.source kwargs['source_id'] = kwargs['source'].id kwargs['project_id'] = kwargs['project'].id kwargs['build_id'] = build.id if change: kwargs['change_id'] = change.id job = Job( build=build, change=change, **kwargs ) db.session.add(job) node, created = get_or_create(Node, where={ 'label': get_sentences(1)[0][:32], }) if created: cluster, _ = get_or_create(Cluster, where={ 'label': get_sentences(1)[0][:32], }) clusternode = ClusterNode(cluster=cluster, node=node) db.session.add(clusternode) jobplan = JobPlan.build_jobplan(plan(build.project), job) db.session.add(jobplan) phase1_setup = JobPhase( project=job.project, job=job, date_started=job.date_started, date_finished=job.date_finished, status=Status.finished, result=Result.passed, label='Setup', ) db.session.add(phase1_setup) phase1_compile = JobPhase( project=job.project, job=job, date_started=job.date_started, date_finished=job.date_finished, status=Status.finished, result=Result.passed, label='Compile', ) db.session.add(phase1_compile) phase1_test = JobPhase( project=job.project, job=job, date_started=job.date_started, date_finished=job.date_finished, status=kwargs['status'], result=kwargs['result'], label='Test', ) db.session.add(phase1_test) step = JobStep( project=job.project, job=job, phase=phase1_setup, status=phase1_setup.status, result=phase1_setup.result, label='Setup', node=node, ) db.session.add(step) command = Command( jobstep=step, script="echo 1", label="echo 1", ) db.session.add(command) step = JobStep( project=job.project, job=job, phase=phase1_compile, status=phase1_compile.status, result=phase1_compile.result, label='Compile', node=node, ) db.session.add(step) command = Command( jobstep=step, script="echo 2", label="echo 2", ) db.session.add(command) step = JobStep( project=job.project, job=job, phase=phase1_test, status=phase1_test.status, result=phase1_test.result, label=TEST_STEP_LABELS.next(), node=node, ) db.session.add(step) command = Command( jobstep=step, script="echo 3", label="echo 3", ) db.session.add(command) step = JobStep( project=job.project, job=job, phase=phase1_test, status=phase1_test.status, result=phase1_test.result, label=TEST_STEP_LABELS.next(), node=node, ) db.session.add(step) command = Command( jobstep=step, script="echo 4", label="echo 4", ) db.session.add(command) if phase1_test.result == Result.failed: db.session.add(FailureReason( reason='test_failures', build_id=build.id, job_id=job.id, step_id=step.id, project_id=job.project_id )) return job
def _sync_step(self, job, phase, stage, step=None): if step is None: try: entity = RemoteEntity.query.filter_by(type="step", provider=self.provider, remote_id=str(stage["id"]))[ 0 ] except IndexError: step, entity = None, None else: step = JobStep.query.get(entity.internal_id) create_entity = entity is None else: create_entity = False if step is None: step = JobStep() node = self._get_node(stage["buildNode"]) step.job_id = job.id step.project_id = job.project_id step.phase_id = phase.id step.node_id = node.id step.label = stage["name"] step.date_started = self._get_start_time([stage]) step.date_finished = self._get_end_time([stage]) if step.date_started and step.date_finished: if stage["status"] == "passed": step.result = Result.passed else: step.result = Result.failed step.status = Status.finished elif step.date_started: if stage["status"] == "failed": step.result = Result.failed else: step.result = Result.unknown step.status = Status.in_progress else: step.status = Status.queued step.result = Result.unknown if create_entity: entity = RemoteEntity(provider=self.provider, remote_id=str(stage["id"]), internal_id=step.id, type="step") db.session.add(entity) db.session.add(step) return step
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 _sync_step(self, job, phase, stage, step=None): if step is None: try: entity = RemoteEntity.query.filter_by( type='step', provider=self.provider, remote_id=str(stage['id']), )[0] except IndexError: step, entity = None, None else: step = JobStep.query.get(entity.internal_id) create_entity = entity is None else: create_entity = False if step is None: step = JobStep() node = self._get_node(stage['buildNode']) step.job_id = job.id step.project_id = job.project_id step.phase_id = phase.id step.node_id = node.id step.label = stage['name'] step.date_started = self._get_start_time([stage]) step.date_finished = self._get_end_time([stage]) if step.date_started and step.date_finished: if stage['status'] == 'passed': step.result = Result.passed else: step.result = Result.failed step.status = Status.finished elif step.date_started: if stage['status'] == 'failed': step.result = Result.failed else: step.result = Result.unknown step.status = Status.in_progress else: step.status = Status.queued step.result = Result.unknown if create_entity: entity = RemoteEntity( provider=self.provider, remote_id=str(stage['id']), internal_id=step.id, type='step', ) db.session.add(entity) db.session.add(step) return step
def job(build, change=None, **kwargs): kwargs.setdefault('project', build.project) kwargs.setdefault('label', get_sentences(1)[0][:128]) kwargs.setdefault('status', Status.finished) kwargs.setdefault('result', Result.passed) kwargs.setdefault('duration', random.randint(10000, 100000)) if 'source' not in kwargs: kwargs['source'] = source(build.repository) kwargs['source_id'] = kwargs['source'].id kwargs['project_id'] = kwargs['project'].id kwargs['build_id'] = build.id if change: kwargs['change_id'] = change.id job = Job(build=build, change=change, **kwargs) db.session.add(job) node, _ = get_or_create(Node, where={ 'label': get_sentences(1)[0][:32], }) jobplan = JobPlan( plan=plan(), build=build, project=job.project, job=job, ) db.session.add(jobplan) phase1_setup = JobPhase( project=job.project, job=job, status=Status.finished, result=Result.passed, label='Setup', ) db.session.add(phase1_setup) phase1_compile = JobPhase( project=job.project, job=job, status=Status.finished, result=Result.passed, label='Compile', ) db.session.add(phase1_compile) phase1_test = JobPhase( project=job.project, job=job, status=kwargs['status'], result=kwargs['result'], label='Test', ) db.session.add(phase1_test) step = JobStep( project=job.project, job=job, phase=phase1_setup, status=phase1_setup.status, result=phase1_setup.result, label='Setup', node=node, ) db.session.add(step) step = JobStep( project=job.project, job=job, phase=phase1_compile, status=phase1_compile.status, result=phase1_compile.result, label='Compile', node=node, ) db.session.add(step) step = JobStep( project=job.project, job=job, phase=phase1_test, status=phase1_test.status, result=phase1_test.result, label=TEST_STEP_LABELS.next(), node=node, ) db.session.add(step) step = JobStep( project=job.project, job=job, phase=phase1_test, status=phase1_test.status, result=phase1_test.result, label=TEST_STEP_LABELS.next(), node=node, ) db.session.add(step) return job