Skip to content

Commit

Permalink
Bug 1343329 - Add push_id filtering support to the /jobdetail/ API
Browse files Browse the repository at this point in the history
This will allow the test-centric UI prototype to more easily fetch the
URLs for all "artifact uploaded" JobDetails associated with a push.
  • Loading branch information
Ed Morley committed Mar 1, 2017
1 parent d37cece commit bf8591a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
15 changes: 14 additions & 1 deletion tests/webapp/api/test_job_details_api.py
Expand Up @@ -38,12 +38,14 @@ def test_job_details(test_repository, failure_classifications,
for (job_guid, params) in details.iteritems():
if i < 3:
repository = test_repository
push_id = 1
else:
# renumber last
repository = test_repository2
push_id = 2
i = 1
print (i, repository)
job = create_generic_job(job_guid, repository, 1, i,
job = create_generic_job(job_guid, repository, push_id, i,
generic_reference_data)
JobDetail.objects.create(
job=job, **params)
Expand Down Expand Up @@ -121,3 +123,14 @@ def test_job_details(test_repository, failure_classifications,
'url': None,
'value': 'value1'
}]

# Should be able to filter by push_id
resp = webapp.get(reverse('jobdetail-list') + '?push_id=2')
assert resp.status_int == 200
assert resp.json['results'] == [{
'job_guid': 'ijkl',
'job_id': 3,
'title': 'title3',
'url': 'https://localhost/foo',
'value': 'value3'
}]
5 changes: 3 additions & 2 deletions treeherder/webapp/api/jobs.py
Expand Up @@ -642,12 +642,13 @@ class NumberInFilter(django_filters.filters.BaseInFilter,
job__guid = django_filters.CharFilter(name='job__guid') # for backwards compat
title = django_filters.CharFilter(name='title')
value = django_filters.CharFilter(name='value')
push_id = django_filters.NumberFilter(name='job__push')
repository = django_filters.CharFilter(name='job__repository__name')

class Meta:
model = JobDetail
fields = ['job_id', 'job_guid', 'job__guid', 'job_id__in', 'title',
'value', 'repository']
'value', 'push_id', 'repository']

filter_backends = [filters.DjangoFilterBackend]
filter_class = JobDetailFilter
Expand All @@ -661,7 +662,7 @@ class JobDetailPagination(pagination.IdPagination):
pagination_class = JobDetailPagination

# one of these is required
required_filters = ['job_guid', 'job__guid', 'job_id', 'job_id__in']
required_filters = ['job_guid', 'job__guid', 'job_id', 'job_id__in', 'push_id']

def list(self, request):
query_param_keys = request.query_params.keys()
Expand Down

0 comments on commit bf8591a

Please sign in to comment.