def test_with_messages(self):
        project = self.create_project()
        build = self.create_build(project=project)
        job = self.create_job(build=build)
        phase = self.create_jobphase(job)
        step = self.create_jobstep(phase)
        target = self.create_target(
            job,
            step,
            name='target_foo',
            duration=134,
            result=Result.failed,
            status=Status.finished,
            date_created=datetime(2013, 9, 19, 22, 15, 22),
        )
        message1 = self.create_target_message(target=target)
        message2 = self.create_target_message(target=target)
        result = serialize(
            target,
            {BazelTarget: BazelTargetWithMessagesCrumbler(max_messages=1)})
        assert len(result['messages']) == 1
        assert result['messages'][0]['id'] == message1.id.hex

        result = serialize(
            target,
            {BazelTarget: BazelTargetWithMessagesCrumbler(max_messages=2)})
        assert len(result['messages']) == 2
        assert [m['id'] for m in result['messages']
                ] == [message1.id.hex, message2.id.hex]
Пример #2
0
    def get_attrs(self, item_list):
        image_list = sorted(SnapshotImage.query.options(
            joinedload('plan'), ).filter(
                SnapshotImage.snapshot_id.in_(j.id for j in item_list), ),
                            key=lambda x: x.date_created)
        image_map = defaultdict(list)
        for image in image_list:
            image_map[image.snapshot_id].append(serialize(image))

        active_snapshots = set(
            (x[0] for x in db.session.query(ProjectOption.value, ).filter(
                ProjectOption.project_id.in_(
                    set(s.project_id for s in item_list)),
                ProjectOption.name == 'snapshot.current',
            )))

        build_list = list(
            Build.query.options(
                joinedload('project'),
                joinedload('author'),
                joinedload('source').joinedload('revision'),
            ).filter(Build.id.in_(j.build_id for j in item_list), ))
        build_map = dict(
            (b.id, d) for b, d in zip(build_list, serialize(build_list)))

        result = {}
        for item in item_list:
            result[item] = {
                'images': image_map.get(item.id, []),
                'active': item.id.hex in active_snapshots,
                'build': build_map.get(item.build_id),
            }

        return result
Пример #3
0
    def test_simple(self):
        from changes.models import TestCase

        project = self.create_project()
        build = self.create_build(project=project)
        job = self.create_job(build=build)
        testcase = self.create_test(job=job, )

        result = serialize(testcase, {TestCase: TestCaseWithOriginCrumbler()})
        assert result['origin'] is None

        testcase.origin = 'foobar'
        result = serialize(testcase, {TestCase: TestCaseWithOriginCrumbler()})
        assert result['origin'] == 'foobar'
 def test_no_result_source(self):
     project = self.create_project()
     build = self.create_build(project=project)
     job = self.create_job(build=build)
     phase = self.create_jobphase(job)
     step = self.create_jobstep(phase)
     target = self.create_target(
         job,
         step,
         name='target_foo',
         duration=134,
         result=Result.failed,
         status=Status.finished,
         date_created=datetime(2013, 9, 19, 22, 15, 22),
     )
     target.result_source = None
     result = serialize(target)
     assert result['id'] == str(target.id.hex)
     assert result['job']['id'] == str(job.id.hex)
     assert result['step']['id'] == str(step.id.hex)
     assert result['name'] == 'target_foo'
     assert result['dateCreated'] == '2013-09-19T22:15:22'
     assert result['result']['id'] == 'failed'
     assert result['status']['id'] == 'finished'
     assert result['duration'] == 134
     assert result['resultSource']['id'] == 'from_self'
Пример #5
0
    def test_simple(self):
        from changes.models import TestCase

        project = self.create_project()
        build = self.create_build(project=project)
        job = self.create_job(build=build)
        testcase = self.create_test(
            job=job,
        )

        result = serialize(testcase, {TestCase: TestCaseWithOriginSerializer()})
        assert result['origin'] is None

        testcase.origin = 'foobar'
        result = serialize(testcase, {TestCase: TestCaseWithOriginSerializer()})
        assert result['origin'] == 'foobar'
Пример #6
0
def test_simple():
    build = Build(
        id=UUID(hex='33846695b2774b29a71795a009e8168a'),
        label='Hello world',
        target='D1234',
        message='Foo bar',
        project=Project(
            slug='test', name='test', id=UUID('1e7958a368f44b0eb5a57372a9910d50'),
        ),
        project_id=UUID('1e7958a368f44b0eb5a57372a9910d50'),
        source=Source(
            revision_sha='1e7958a368f44b0eb5a57372a9910d50',
        ),
        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, 33),
    )
    result = serialize(build)
    assert result['name'] == 'Hello world'
    assert result['id'] == '33846695b2774b29a71795a009e8168a'
    assert result['source']['id'] == build.source.id.hex
    assert result['target'] == 'D1234'
    assert result['message'] == 'Foo bar'
    assert result['dateCreated'] == '2013-09-19T22:15:22'
    assert result['dateStarted'] == '2013-09-19T22:15:23'
    assert result['dateFinished'] == '2013-09-19T22:15:33'
    assert result['duration'] == 10000
    assert result['link'] == 'http://example.com/projects/test/builds/{0}/'.format(build.id.hex)
Пример #7
0
def test_simple():
    project = Project(
        id=UUID(hex='3a038b4000114157a9a8174344ff6164'),
        slug='test',
        name='test',
    )
    build = Job(id=UUID(hex='1e7958a368f44b0eb5a57372a9910d50'))

    parent = AggregateTestGroup(
        id=UUID(hex='33846695b2774b29a71745a009e8168a'),
        name='test.group',
        first_job=build,
        project=project,
        project_id=project.id,
        date_created=datetime(2013, 9, 19, 22, 15, 22),
    )
    test = AggregateTestGroup(
        id=UUID(hex='33846695b2774b29a71795a009e8168a'),
        name='test.group.ClassName',
        first_job=build,
        project=project,
        project_id=project.id,
        date_created=datetime(2013, 9, 19, 22, 15, 22),
        parent=parent,
    )
    result = serialize(test)
    assert result['name'] == 'test.group.ClassName'
    assert result['shortName'] == 'ClassName'
    assert result['id'] == '33846695b2774b29a71795a009e8168a'
    # assert result['firstBuild']['id'] == '1e7958a368f44b0eb5a57372a9910d50'
    assert result['dateCreated'] == '2013-09-19T22:15:22'
Пример #8
0
    def test_simple(self):
        build = self.create_build(self.create_project())
        revision_result = self.create_revision_result(build=build, revision_sha=build.source.revision_sha, project_id=build.project_id)

        data = serialize(revision_result)
        assert data['id'] == revision_result.id.hex
        assert data['revisionSha'] == revision_result.revision_sha
        assert data['build']['id'] == build.id.hex
        assert data['result']['id'] == 'unknown'
Пример #9
0
    def test_simple(self):
        from changes.models import TestCase

        project = self.create_project()
        build = self.create_build(project=project)
        job = self.create_job(build=build)
        testcase = self.create_test(job=job, )
        result = serialize(testcase, {TestCase: TestCaseWithJobCrumbler()})
        assert result['job']['id'] == str(job.id.hex)
Пример #10
0
    def test_no_build(self):
        project = self.create_project()
        revision_result = self.create_revision_result(revision_sha='a' * 40, project_id=project.id)

        data = serialize(revision_result)
        assert data['id'] == revision_result.id.hex
        assert data['revisionSha'] == 'a' * 40
        assert data['build'] is None
        assert data['result']['id'] == 'unknown'
Пример #11
0
 def test_implicit_package_only_name(self):
     project = self.create_project()
     build = self.create_build(project=project)
     job = self.create_job(build=build)
     testcase = self.create_test(name='test_foo', package=None, job=job)
     result = serialize(testcase)
     assert result['shortName'] == 'test_foo'
     assert result['name'] == 'test_foo'
     assert result['package'] is None
Пример #12
0
    def test_simple(self):
        from changes.models import TestCase

        project = self.create_project()
        build = self.create_build(project=project)
        job = self.create_job(build=build)
        testcase = self.create_test(
            job=job,
        )
        result = serialize(testcase, {TestCase: TestCaseWithJobSerializer()})
        assert result['job']['id'] == str(job.id.hex)
Пример #13
0
def test_simple():
    project = Project(
        id=UUID(hex='33846695b2774b29a71795a009e8168a'),
        slug='hello-world',
        name='Hello world',
        date_created=datetime(2013, 9, 19, 22, 15, 22),
    )
    result = serialize(project)
    assert result['name'] == 'Hello world'
    assert result['id'] == '33846695b2774b29a71795a009e8168a'
    assert result['slug'] == 'hello-world'
    assert result['dateCreated'] == '2013-09-19T22:15:22'
 def test_simple(self):
     message = AdminMessage(
         id=UUID(hex='33846695b2774b29a71795a009e8168a'),
         message='Foo bar',
         user=self.create_user(email='*****@*****.**', ),
         date_created=datetime(2013, 9, 19, 22, 15, 22),
     )
     result = serialize(message)
     assert result['id'] == '33846695b2774b29a71795a009e8168a'
     assert result['user']['id'] == message.user.id.hex
     assert result['message'] == 'Foo bar'
     assert result['dateCreated'] == '2013-09-19T22:15:22'
Пример #15
0
    def test_with_messages(self):
        project = self.create_project()
        build = self.create_build(project=project)
        job = self.create_job(build=build)
        phase = self.create_jobphase(job)
        step = self.create_jobstep(phase)
        target = self.create_target(job, step,
            name='target_foo',
            duration=134,
            result=Result.failed,
            status=Status.finished,
            date_created=datetime(2013, 9, 19, 22, 15, 22),
        )
        message1 = self.create_target_message(target=target)
        message2 = self.create_target_message(target=target)
        result = serialize(target, {BazelTarget: BazelTargetWithMessagesCrumbler(max_messages=1)})
        assert len(result['messages']) == 1
        assert result['messages'][0]['id'] == message1.id.hex

        result = serialize(target, {BazelTarget: BazelTargetWithMessagesCrumbler(max_messages=2)})
        assert len(result['messages']) == 2
        assert [m['id'] for m in result['messages']] == [message1.id.hex, message2.id.hex]
Пример #16
0
    def test_correct(self):
        build = self.create_build(self.create_project())
        message = self.create_build_message(
            build,
            text="Test message",
            date_created=datetime(2013, 9, 19, 22, 15, 22),
        )

        result = serialize(message)
        assert result['id'] == message.id.hex
        assert result['build']['id'] == message.build_id.hex
        assert result['text'] == message.text
        assert result['dateCreated'] == '2013-09-19T22:15:22'
Пример #17
0
    def test_list(self, get_crumbler):
        foo_crumbler, bar_crumbler = self._setup_crumblers(get_crumbler)

        item1 = SerializeTest._Foo('foo')
        item2 = SerializeTest._Bar('bar')
        item3 = SerializeTest._Foo('foo2')
        ret = serialize([item1, item2, item3, 'passthrough'])
        assert ret == ['foo', 'bar', 'foo2', 'passthrough']
        foo_crumbler.get_extra_attrs_from_db.assert_called_once_with({item1, item3})
        bar_crumbler.get_extra_attrs_from_db.assert_called_once_with({item2})

        self._assert_crumble_called_for(foo_crumbler, [item1, item3])
        self._assert_crumble_called_for(bar_crumbler, [item2])
Пример #18
0
 def test_implicit_package_only_name(self):
     project = self.create_project()
     build = self.create_build(project=project)
     job = self.create_job(build=build)
     testcase = self.create_test(
         name='test_foo',
         package=None,
         job=job
     )
     result = serialize(testcase)
     assert result['shortName'] == 'test_foo'
     assert result['name'] == 'test_foo'
     assert result['package'] is None
Пример #19
0
def test_identity():
    """Verify that serialize returns what we gave it in basic cases."""
    passthrough = [
        None,
        44.2,
        "string",
        [1, 2, 3],
        ["one", 2, 3],
        {'x': 11, 'y': 22},
        {'x': ['yes', 'no'], 'y': {'k': [1, 2, 3]}}
    ]
    for val in passthrough:
        assert serialize(val) == val
Пример #20
0
    def test_correct(self):
        build = self.create_build(self.create_project())
        message = self.create_build_message(
            build,
            text="Test message",
            date_created=datetime(2013, 9, 19, 22, 15, 22),
        )

        result = serialize(message)
        assert result['id'] == message.id.hex
        assert result['build']['id'] == message.build_id.hex
        assert result['text'] == message.text
        assert result['dateCreated'] == '2013-09-19T22:15:22'
Пример #21
0
 def test_identity(self):
     """Verify that serialize returns what we gave it in basic cases."""
     passthrough = [
         None,
         44.2,
         "string",
         [1, 2, 3],
         ["one", 2, 3],
         {'x': 11, 'y': 22},
         {'x': ['yes', 'no'], 'y': {'k': [1, 2, 3]}}
     ]
     for val in passthrough:
         assert serialize(val) == val
Пример #22
0
    def get_extra_attrs_from_db(self, item_list):
        image_list = sorted(SnapshotImage.query.options(
            joinedload('plan'),
        ).filter(
            SnapshotImage.snapshot_id.in_(j.id for j in item_list),
        ), key=lambda x: x.date_created)
        image_map = defaultdict(list)
        for image in image_list:
            image_map[image.snapshot_id].append(serialize(image))

        active_snapshots = set((
            x[0] for x in db.session.query(
                ProjectOption.value,
            ).filter(
                ProjectOption.project_id.in_(set(s.project_id for s in item_list)),
                ProjectOption.name == 'snapshot.current',
            )
        ))

        build_list = list(Build.query.options(
            joinedload('project'),
            joinedload('author'),
            joinedload('source').joinedload('revision'),
        ).filter(
            Build.id.in_(j.build_id for j in item_list),
        ))
        build_map = dict(
            (b.id, d) for b, d in zip(build_list, serialize(build_list))
        )

        result = {}
        for item in item_list:
            result[item] = {
                'images': image_map.get(item.id, []),
                'active': item.id.hex in active_snapshots,
                'build': build_map.get(item.build_id),
            }

        return result
Пример #23
0
def test_simple():
    change = Change(
        id=UUID(hex='33846695b2774b29a71795a009e8168a'),
        label='Hello world',
        project=Project(slug='test', name='test'),
        date_created=datetime(2013, 9, 19, 22, 15, 22),
        date_modified=datetime(2013, 9, 19, 22, 15, 23),
    )
    result = serialize(change)
    assert result['name'] == 'Hello world'
    assert result['link'] == 'http://example.com/changes/33846695b2774b29a71795a009e8168a/'
    assert result['id'] == '33846695b2774b29a71795a009e8168a'
    assert result['dateCreated'] == '2013-09-19T22:15:22'
    assert result['dateModified'] == '2013-09-19T22:15:23'
Пример #24
0
    def test_embedded(self, get_crumbler):
        foo_crumbler, bar_crumbler = self._setup_crumblers(get_crumbler)

        item1 = SerializeTest._Bar('bar')
        item2 = SerializeTest._Foo({'foo': item1})
        item3 = SerializeTest._Bar('baz')
        item4 = SerializeTest._Foo({'fuzz': item3})
        ret = serialize([item2, item4])
        assert ret == [{'foo': 'bar'}, {'fuzz': 'baz'}]
        foo_crumbler.get_extra_attrs_from_db.assert_called_once_with({item2, item4})
        bar_crumbler.get_extra_attrs_from_db.assert_called_once_with({item1, item3})

        self._assert_crumble_called_for(foo_crumbler, [item2, item4])
        self._assert_crumble_called_for(bar_crumbler, [item1, item3])
Пример #25
0
 def test_simple(self):
     message = AdminMessage(
         id=UUID(hex='33846695b2774b29a71795a009e8168a'),
         message='Foo bar',
         user=self.create_user(
                 email='*****@*****.**',
         ),
         date_created=datetime(2013, 9, 19, 22, 15, 22),
     )
     result = serialize(message)
     assert result['id'] == '33846695b2774b29a71795a009e8168a'
     assert result['user']['id'] == message.user.id.hex
     assert result['message'] == 'Foo bar'
     assert result['dateCreated'] == '2013-09-19T22:15:22'
Пример #26
0
def test_simple():
    change = Change(
        id=UUID(hex='33846695b2774b29a71795a009e8168a'),
        label='Hello world',
        project=Project(slug='test', name='test'),
        date_created=datetime(2013, 9, 19, 22, 15, 22),
        date_modified=datetime(2013, 9, 19, 22, 15, 23),
    )
    result = serialize(change)
    assert result['name'] == 'Hello world'
    assert result[
        'link'] == 'http://example.com/changes/33846695b2774b29a71795a009e8168a/'
    assert result['id'] == '33846695b2774b29a71795a009e8168a'
    assert result['dateCreated'] == '2013-09-19T22:15:22'
    assert result['dateModified'] == '2013-09-19T22:15:23'
Пример #27
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')),
        name='console',
        date_created=datetime(2013, 9, 19, 22, 15, 22),
    )
    result = serialize(logsource)
    assert result['id'] == '33846695b2774b29a71795a009e8168a'
    assert result['name'] == 'console'
    assert result['link'] == 'http://example.com/jobs/2e18a7cbc0c24316b2ef9d41fea191d6/logs/33846695b2774b29a71795a009e8168a/'
    assert result['dateCreated'] == '2013-09-19T22:15:22'
    assert result['step']['id'] == '36c7af5e56aa4a7fbf076e13ac00a866'
Пример #28
0
 def test_simple(self):
     repo = self.create_repo()
     revision = self.create_revision(repository=repo)
     source = Source(
         repository=repo,
         repository_id=repo.id,
         revision=revision,
         revision_sha=revision.sha,
         date_created=datetime(2013, 9, 19, 22, 15, 22),
     )
     db.session.add(source)
     result = serialize(source)
     assert result['id'] == source.id.hex
     assert result['dateCreated'] == '2013-09-19T22:15:22'
     assert result['revision']['id'] == revision.sha
Пример #29
0
 def test_simple(self):
     repo = self.create_repo()
     revision = self.create_revision(repository=repo)
     source = Source(
         repository=repo,
         repository_id=repo.id,
         revision=revision,
         revision_sha=revision.sha,
         date_created=datetime(2013, 9, 19, 22, 15, 22),
     )
     db.session.add(source)
     result = serialize(source)
     assert result['id'] == source.id.hex
     assert result['dateCreated'] == '2013-09-19T22:15:22'
     assert result['revision']['id'] == revision.sha
Пример #30
0
def test_simple():
    patch = Patch(
        id=UUID(hex='33846695b2774b29a71795a009e8168a'),
        diff=SAMPLE_DIFF,
        parent_revision_sha='1e7958a368f44b0eb5a57372a9910d50',
        date_created=datetime(2013, 9, 19, 22, 15, 22),
    )
    result = serialize(patch)
    assert result['link'] == 'http://example.com/patches/33846695b2774b29a71795a009e8168a/'
    assert result['id'] == '33846695b2774b29a71795a009e8168a'
    assert result['parentRevision'] == {
        'sha': '1e7958a368f44b0eb5a57372a9910d50',
    }
    assert result['dateCreated'] == '2013-09-19T22:15:22'
    assert result['diff'] == SAMPLE_DIFF
Пример #31
0
    def get_attrs(self, item_list):
        result = super(JobWithBuildSerializer, self).get_attrs(item_list)

        build_list = list(
            Build.query.options(
                joinedload('project'),
                joinedload('author'),
                joinedload('source').joinedload('revision'),
            ).filter(Build.id.in_(j.build_id for j in item_list), ))
        build_map = dict(
            (b.id, d) for b, d in zip(build_list, serialize(build_list)))

        for item in item_list:
            result[item]['build'] = build_map.get(item.build_id)

        return result
Пример #32
0
    def test_correct(self):
        project = self.create_project()
        build = self.create_build(project)
        job = self.create_job(build)
        target = self.create_target(job)
        message = self.create_target_message(
            target,
            text="Test message",
            date_created=datetime(2013, 9, 19, 22, 15, 22),
        )

        result = serialize(message)
        assert result['id'] == message.id.hex
        assert result['target']['id'] == message.target_id.hex
        assert result['text'] == message.text
        assert result['dateCreated'] == '2013-09-19T22:15:22'
Пример #33
0
def test_simple():
    patch = Patch(
        id=UUID(hex='33846695b2774b29a71795a009e8168a'),
        diff=SAMPLE_DIFF,
        parent_revision_sha='1e7958a368f44b0eb5a57372a9910d50',
        date_created=datetime(2013, 9, 19, 22, 15, 22),
    )
    result = serialize(patch)
    assert result[
        'link'] == 'http://example.com/patches/33846695b2774b29a71795a009e8168a/'
    assert result['id'] == '33846695b2774b29a71795a009e8168a'
    assert result['parentRevision'] == {
        'sha': '1e7958a368f44b0eb5a57372a9910d50',
    }
    assert result['dateCreated'] == '2013-09-19T22:15:22'
    assert result['diff'] == SAMPLE_DIFF
    def test_correct(self):
        project = self.create_project()
        build = self.create_build(project)
        job = self.create_job(build)
        target = self.create_target(job)
        message = self.create_target_message(
            target,
            text="Test message",
            date_created=datetime(2013, 9, 19, 22, 15, 22),
        )

        result = serialize(message)
        assert result['id'] == message.id.hex
        assert result['target']['id'] == message.target_id.hex
        assert result['text'] == message.text
        assert result['dateCreated'] == '2013-09-19T22:15:22'
Пример #35
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'] == '<span class="ansi36">notice: foo bar</span>'
    assert result['size'] == 7
    assert result['offset'] == 10
Пример #36
0
    def test_dict(self, get_crumbler):
        foo_crumbler, bar_crumbler = self._setup_crumblers(get_crumbler)

        item1 = SerializeTest._Foo('foo')
        item2 = SerializeTest._Bar('bar')
        item3 = SerializeTest._Foo('foo2')
        item4 = SerializeTest._Bar('baz')
        ret = serialize({item1: item2, 'otherkey': item3, item4: 'otherval'})
        assert ret == {'foo': 'bar', 'otherkey': 'foo2', 'baz': 'otherval'}
        foo_crumbler.get_extra_attrs_from_db.assert_called_once_with({item1, item3})
        bar_crumbler.get_extra_attrs_from_db.assert_called_once_with({item4, item2})

        # in the current implementation, keys are crumbled before values, so these
        # have a defined order, but doesn't seem worth relying on that behavior
        # in our tests.
        self._assert_crumble_called_for(foo_crumbler, [item1, item3], any_order=True)
        self._assert_crumble_called_for(bar_crumbler, [item4, item2], any_order=True)
Пример #37
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'
Пример #38
0
    def get_attrs(self, item_list):
        build_list = list(Build.query.options(
            joinedload('project'),
            joinedload('author'),
            joinedload('source').joinedload('revision'),
        ).filter(
            Build.id.in_(j.build_id for j in item_list),
        ))
        build_map = dict(
            (b.id, d) for b, d in zip(build_list, serialize(build_list))
        )

        result = {}
        for item in item_list:
            result[item] = {'build': build_map.get(item.build_id)}

        return result
Пример #39
0
def test_implicit_package_only_name():
    testcase = TestCase(
        id=UUID(hex='33846695b2774b29a71795a009e8168a'),
        name='test_foo',
        job=Job(id=UUID(hex='1e7958a368f44b0eb5a57372a9910d50')),
        project=Project(slug='test', name='test'),
        duration=134,
        result=Result.failed,
        date_created=datetime(2013, 9, 19, 22, 15, 22),
    )
    result = serialize(testcase)
    assert result['id'] == '33846695b2774b29a71795a009e8168a'
    assert result['name'] == 'test_foo'
    assert result['package'] is None
    assert result['dateCreated'] == '2013-09-19T22:15:22'
    assert result['result']['id'] == 'failed'
    assert result['duration'] == 134
Пример #40
0
def test_simple():
    revision = Revision(
        sha='33846695b2774b29a71795a009e8168a',
        repository=Repository(),
        author=Author(
            name='Foo Bar',
            email='*****@*****.**',
        ),
        message='hello world',
        date_created=datetime(2013, 9, 19, 22, 15, 22),
    )
    result = serialize(revision)
    assert result['id'] == '33846695b2774b29a71795a009e8168a'
    assert result['author']['name'] == 'Foo Bar'
    assert result['author']['email'] == '*****@*****.**'
    assert result['message'] == 'hello world'
    assert result['dateCreated'] == '2013-09-19T22:15:22'
Пример #41
0
    def test_phabricator_links(self):
        repository = self.create_repo()
        self.create_option(
            item_id=repository.id,
            name='phabricator.callsign',
            value='TEST',
        )

        revision = self.create_revision(
            sha='33846695b2774b29a71795a009e8168a',
            repository=repository,
        )
        result = serialize(revision)
        assert result['external'] == {
            'label': 'rTEST33846695b277',
            'link': 'http://phabricator.example.com/rTEST33846695b277',
        }
Пример #42
0
def test_simple():
    testgroup = TestGroup(
        id=UUID(hex='33846695b2774b29a71795a009e8168a'),
        name='test.group.ClassName',
        job=Job(id=UUID(hex='1e7958a368f44b0eb5a57372a9910d50')),
        project=Project(slug='test', name='test'),
        duration=134,
        num_tests=5,
        num_failed=2,
        date_created=datetime(2013, 9, 19, 22, 15, 22),
    )
    result = serialize(testgroup)
    assert result['name'] == 'test.group.ClassName'
    assert result['id'] == '33846695b2774b29a71795a009e8168a'
    assert result['numTests'] == 5
    assert result['numFailures'] == 2
    assert result['dateCreated'] == '2013-09-19T22:15:22'
    assert result['duration'] == 134
Пример #43
0
    def get_extra_attrs_from_db(self, item_list):
        result = super(JobWithBuildCrumbler, self).get_extra_attrs_from_db(item_list)

        build_list = list(Build.query.options(
            joinedload('project'),
            joinedload('author'),
            joinedload('source').joinedload('revision'),
        ).filter(
            Build.id.in_(j.build_id for j in item_list),
        ))
        build_map = dict(
            (b.id, d) for b, d in zip(build_list, serialize(build_list))
        )

        for item in item_list:
            result[item]['build'] = build_map.get(item.build_id)

        return result
Пример #44
0
    def test_associated_snapshot_image(self):
        project = self.create_project()
        build = self.create_build(project=project)
        plan = self.create_plan(project)
        job = self.create_job(build=build)
        snapshot = self.create_snapshot(project)
        image = self.create_snapshot_image(plan=plan, snapshot=snapshot)
        self.create_option(item_id=plan.id, name='snapshot.allow', value='1')
        db.session.add(ProjectOption(project_id=project.id,
                                     name='snapshot.current',
                                     value=snapshot.id.hex))
        db.session.commit()
        self.create_job_plan(job=job, plan=plan, snapshot_id=snapshot.id)
        phase = self.create_jobphase(job)
        jobstep = self.create_jobstep(phase)

        result = serialize(jobstep)
        assert result['image']['id'] == image.id.hex
Пример #45
0
    def test_simple(self):
        from changes.models import TestCase

        project = self.create_project()
        build = self.create_build(project=project)
        job = self.create_job(build=build)
        testcase = self.create_test(
            job=job,
            package='test.group.ClassName',
            name='test_foo',
            duration=43,
        )
        result = serialize(testcase, {TestCase: GeneralizedTestCase()})
        assert result['hash'] == testcase.name_sha
        assert result['project']['id'] == str(project.id.hex)
        assert result['shortName'] == testcase.short_name
        assert result['name'] == testcase.name
        assert result['package'] == testcase.package
        assert result['duration'] == testcase.duration
Пример #46
0
    def test_simple(self):
        from changes.models import TestCase

        project = self.create_project()
        build = self.create_build(project=project)
        job = self.create_job(build=build)
        testcase = self.create_test(
            job=job,
            package='test.group.ClassName',
            name='test_foo',
            duration=43,
        )
        result = serialize(testcase, {TestCase: GeneralizedTestCase()})
        assert result['hash'] == testcase.name_sha
        assert result['project']['id'] == str(project.id.hex)
        assert result['shortName'] == testcase.short_name
        assert result['name'] == testcase.name
        assert result['package'] == testcase.package
        assert result['duration'] == testcase.duration
Пример #47
0
    def test_associated_snapshot_image(self):
        project = self.create_project()
        build = self.create_build(project=project)
        plan = self.create_plan(project)
        job = self.create_job(build=build)
        snapshot = self.create_snapshot(project)
        image = self.create_snapshot_image(plan=plan, snapshot=snapshot)
        self.create_option(item_id=plan.id, name='snapshot.allow', value='1')
        db.session.add(
            ProjectOption(project_id=project.id,
                          name='snapshot.current',
                          value=snapshot.id.hex))
        db.session.commit()
        self.create_job_plan(job=job, plan=plan, snapshot_id=snapshot.id)
        phase = self.create_jobphase(job)
        jobstep = self.create_jobstep(phase)

        result = serialize(jobstep)
        assert result['image']['id'] == image.id.hex
Пример #48
0
    def test_recursive(self, get_crumbler):
        foo_crumbler, bar_crumbler = self._setup_crumblers(get_crumbler)

        item1 = SerializeTest._Bar(['baz'])
        item2 = SerializeTest._Foo(item1)
        item3 = SerializeTest._Foo({'foo': ['thing', item2, 'other'],
                                   'otherkey': 'otherval'})
        item4 = SerializeTest._Bar('bar')
        ret = serialize([item3, item4])
        assert ret == [{'foo': ['thing', ['baz'], 'other'], 'otherkey': 'otherval'}, 'bar']
        # We won't be able to see item2 until we've unwrapped item3, so in this
        # case, we do expect separate calls to `get_extra_attrs_from_db`.
        foo_crumbler.get_extra_attrs_from_db.assert_has_calls([mock.call({item3}),
                                                               mock.call({item2})])
        bar_crumbler.get_extra_attrs_from_db.assert_has_calls([mock.call({item4}),
                                                               mock.call({item1})])

        self._assert_crumble_called_for(foo_crumbler, [item3, item2])
        self._assert_crumble_called_for(bar_crumbler, [item4, item1])
Пример #49
0
def test_simple():
    revision = Revision(
        sha='33846695b2774b29a71795a009e8168a',
        repository=Repository(),
        author=Author(
            name='Foo Bar',
            email='*****@*****.**',
        ),
        parents=['a' * 40],
        branches=['master'],
        message='hello world',
        date_created=datetime(2013, 9, 19, 22, 15, 22),
    )
    result = serialize(revision)
    assert result['id'] == '33846695b2774b29a71795a009e8168a'
    assert result['author']['name'] == 'Foo Bar'
    assert result['author']['email'] == '*****@*****.**'
    assert result['message'] == 'hello world'
    assert result['dateCreated'] == '2013-09-19T22:15:22'
    assert result['parents'] == ['a' * 40]
    assert result['branches'] == ['master']
Пример #50
0
    def test_embedded_get_extra_attrs(self, get_crumbler):
        foo_crumbler, bar_crumbler = self._setup_crumblers(get_crumbler)

        item1 = SerializeTest._Bar('bar')
        item2 = SerializeTest._Foo('foo')
        item3 = SerializeTest._Foo('fuzz')

        foo_crumbler.crumble.side_effect = lambda item, attrs: [item.inner, attrs['foo']]
        attrs = {'foo': item1}
        foo_crumbler.get_extra_attrs_from_db.return_value = {item2: attrs,
                                                             item3: attrs}

        ret = serialize([item2, item3])
        assert ret == [['foo', 'bar'], ['fuzz', 'bar']]
        foo_crumbler.get_extra_attrs_from_db.assert_called_once_with({item2, item3})
        bar_crumbler.get_extra_attrs_from_db.assert_called_once_with({item1})

        self._assert_crumble_called_for(foo_crumbler, [item2, item3], attrs=attrs)
        # we don't currently batch crumble() calls for the same object, so
        # crumble() will actually get called twice here. The assumption is that
        # crumble() itself is cheap, while get_extra_attrs_from_db() is not.
        self._assert_crumble_called_for(bar_crumbler, [item1, item1])
Пример #51
0
def test_simple():
    job = Job(
        id=UUID(hex='33846695b2774b29a71795a009e8168a'),
        label='Hello world',
        project=Project(slug='test', name='test'),
        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, 33),
        build=Build(id=UUID('1e7958a368f44b0eb5a57372a9910d50'), ),
        build_id=UUID('1e7958a368f44b0eb5a57372a9910d50'),
        change=Change(
            id=UUID(hex='2e18a7cbc0c24316b2ef9d41fea191d6'),
            label='Hello world',
        ),
    )
    result = serialize(job)
    assert result['name'] == 'Hello world'
    assert result['id'] == '33846695b2774b29a71795a009e8168a'
    assert result['dateCreated'] == '2013-09-19T22:15:22'
    assert result['dateStarted'] == '2013-09-19T22:15:23'
    assert result['dateFinished'] == '2013-09-19T22:15:33'
    assert result['duration'] == 10000