Skip to content
This repository has been archived by the owner on Dec 15, 2018. It is now read-only.

Commit

Permalink
properly handle a bazel target with no jobstep in serializer
Browse files Browse the repository at this point in the history
Reviewers: anupc

Reviewed By: anupc

Subscribers: changesbot, kylec, wwu

Differential Revision: https://tails.corp.dropbox.com/D232458
  • Loading branch information
Naphat Sanguansin committed Sep 28, 2016
1 parent b47f759 commit 4bfeac1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
6 changes: 4 additions & 2 deletions changes/api/serializer/models/bazeltarget.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
@register(BazelTarget)
class BazelTargetCrumbler(Crumbler):
def crumble(self, instance, attrs):
return {
result = {
'id': instance.id.hex,
'job': {'id': instance.job_id.hex},
'step': {'id': instance.step_id.hex},
'name': instance.name,
'duration': instance.duration or 0,
'status': instance.status,
'result': instance.result,
'dateCreated': instance.date_created,
}
if instance.step_id:
result['step'] = {'id': instance.step_id.hex}
return result
23 changes: 23 additions & 0 deletions tests/changes/api/serializer/models/test_bazeltarget.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,29 @@ def test_simple(self):
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

def test_no_step(self):
project = self.create_project()
build = self.create_build(project=project)
job = self.create_job(build=build)
phase = self.create_jobphase(job)
target = self.create_target(job,
name='target_foo',
duration=134,
result=Result.failed,
status=Status.finished,
date_created=datetime(2013, 9, 19, 22, 15, 22),
)
result = serialize(target)
assert result['id'] == str(target.id.hex)
assert result['job']['id'] == str(job.id.hex)
assert 'step' not in result
assert result['name'] == 'target_foo'
assert result['dateCreated'] == '2013-09-19T22:15:22'
assert result['result']['id'] == 'failed'
Expand Down

0 comments on commit 4bfeac1

Please sign in to comment.