Bug 1311980 - Gracefully handle invalid job_id in BugJobMapViewSet.list (#2142)

This commit is contained in:
Alisha Aneja 2017-02-28 00:16:37 +11:00 коммит произвёл Ed Morley
Родитель c379de03ab
Коммит 0fb3c8b46a
2 изменённых файлов: 19 добавлений и 1 удалений

Просмотреть файл

@ -148,3 +148,17 @@ def test_bug_job_map_delete(webapp, eleven_jobs_stored, test_repository,
content = json.loads(resp.content)
assert content == {"message": "Bug job map deleted"}
assert BugJobMap.objects.count() == 0
def test_bug_job_map_bad_job_id(webapp, test_repository):
"""
test we have graceful error when we pass an invalid job_id
"""
bad_job_id = "aaaa"
resp = webapp.get(
reverse("bug-job-map-list", kwargs={"project": test_repository.name}),
params={'job_id': bad_job_id}, expect_errors=True)
assert resp.status_code == 400
assert resp.json == {'message': 'Valid job_id required'}

Просмотреть файл

@ -55,7 +55,11 @@ class BugJobMapViewSet(viewsets.ViewSet):
return Response("Object not found", status=HTTP_404_NOT_FOUND)
def list(self, request, project):
job_ids = map(int, request.query_params.getlist('job_id'))
try:
job_ids = map(int, request.query_params.getlist('job_id'))
except ValueError:
return Response({"message": "Valid job_id required"},
status=400)
if not job_ids:
return Response({"message": "At least one job_id is required"},
status=400)