From patchwork Tue Oct 30 11:19:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 990734 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42kpxN2YmWz9s8F for ; Tue, 30 Oct 2018 22:23:20 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="C+xleL9x"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42kpxM5JWkzDrSM for ; Tue, 30 Oct 2018 22:23:19 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="C+xleL9x"; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=that.guru (client-ip=185.234.75.14; helo=relay014.mxrelay.co; envelope-from=stephen@that.guru; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="C+xleL9x"; dkim-atps=neutral Received: from relay014.mxrelay.co (relay014.mxrelay.co [185.234.75.14]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42kpsX5jNQzDrRP for ; Tue, 30 Oct 2018 22:20:00 +1100 (AEDT) Received: from filter001.mxrelay.co (filter001.mxrelay.co [64.52.23.203]) by relay014.mxrelay.co (Postfix) with ESMTP id 2DF6B3F1C6 for ; Tue, 30 Oct 2018 11:19:27 +0000 (UTC) Received: from one.mxroute.com (one.mxroute.com [195.201.59.211]) by filter001.mxrelay.co (Postfix) with ESMTPS id 5571B1000C0 for ; Tue, 30 Oct 2018 11:19:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=c1i8T9ZHEeLD0vjsWGbmxLDi6L9Po7ChbLQzZn+PTPM=; b=C+xleL9xCW5dk76H+rgEQCFxJa u7ztw2zPIcWFs3bdyRTiZlqyGkTv2Zvz1JF8WFyOPERvFiNtHmM04hCd18ecqgjFebWe4EapWsY54 xkZnR056qDvt027x4oa16YKMmWvoloXK0wzB4FoUEeUyhdAl3pXaMGWf6GkmGma3ujRb6gTUq6boH Mz+eW4lh276wjP9K8ZFRY9xFKgXjawqIuGdWDfLYIIuhmdQWmUeRdq89p3OmdrTS9YP5rQiH/bbd1 aMqiZobH8Z0qIEi8kr5qipCKRbh1UaU0BBjHx545Dg6jBoc6PXPwESC0BQJ+GoFkfvNY8lcpYDDdt Kainq5UQ==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH 04/17] REST: Ensure submission exists for comment listing Date: Tue, 30 Oct 2018 11:19:03 +0000 Message-Id: <20181030111916.7342-5-stephen@that.guru> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181030111916.7342-1-stephen@that.guru> References: <20181030111916.7342-1-stephen@that.guru> X-AuthUser: stephen@that.guru X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" Signed-off-by: Stephen Finucane Closes: #225 --- patchwork/api/comment.py | 5 +++++ patchwork/tests/api/test_comment.py | 13 +++++++++++++ releasenotes/notes/issue-225-94215600c1b23f6e.yaml | 6 ++++++ 3 files changed, 24 insertions(+) create mode 100644 releasenotes/notes/issue-225-94215600c1b23f6e.yaml diff --git a/patchwork/api/comment.py b/patchwork/api/comment.py index 214a9438..57b37111 100644 --- a/patchwork/api/comment.py +++ b/patchwork/api/comment.py @@ -5,6 +5,7 @@ import email.parser +from django.http import Http404 from rest_framework.generics import ListAPIView from rest_framework.serializers import SerializerMethodField @@ -12,6 +13,7 @@ from patchwork.api.base import BaseHyperlinkedModelSerializer from patchwork.api.base import PatchworkPermission from patchwork.api.embedded import PersonSerializer from patchwork.models import Comment +from patchwork.models import Submission class CommentListSerializer(BaseHyperlinkedModelSerializer): @@ -64,6 +66,9 @@ class CommentList(ListAPIView): lookup_url_kwarg = 'pk' def get_queryset(self): + if not Submission.objects.filter(pk=self.kwargs['pk']).exists(): + raise Http404 + return Comment.objects.filter( submission=self.kwargs['pk'] ).select_related('submitter') diff --git a/patchwork/tests/api/test_comment.py b/patchwork/tests/api/test_comment.py index a0aec594..06fe2de3 100644 --- a/patchwork/tests/api/test_comment.py +++ b/patchwork/tests/api/test_comment.py @@ -5,6 +5,7 @@ import unittest +from django.http import Http404 from django.conf import settings from django.urls import NoReverseMatch from django.urls import reverse @@ -61,6 +62,12 @@ class TestCoverComments(APITestCase): with self.assertRaises(NoReverseMatch): self.client.get(self.api_url(cover_obj, version='1.0')) + def test_list_invalid_cover(self): + """Ensure we get a 404 for a non-existent cover letter.""" + resp = self.client.get( + reverse('api-cover-comment-list', kwargs={'pk': '99999'})) + self.assertEqual(status.HTTP_404_NOT_FOUND, resp.status_code) + @unittest.skipUnless(settings.ENABLE_REST_API, 'requires ENABLE_REST_API') class TestPatchComments(APITestCase): @@ -99,3 +106,9 @@ class TestPatchComments(APITestCase): # check we can't access comments using the old version of the API with self.assertRaises(NoReverseMatch): self.client.get(self.api_url(patch_obj, version='1.0')) + + def test_list_invalid_patch(self): + """Ensure we get a 404 for a non-existent patch.""" + resp = self.client.get( + reverse('api-patch-comment-list', kwargs={'pk': '99999'})) + self.assertEqual(status.HTTP_404_NOT_FOUND, resp.status_code) diff --git a/releasenotes/notes/issue-225-94215600c1b23f6e.yaml b/releasenotes/notes/issue-225-94215600c1b23f6e.yaml new file mode 100644 index 00000000..035e38d8 --- /dev/null +++ b/releasenotes/notes/issue-225-94215600c1b23f6e.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Showing comments for a non-existant patch or cover letter was returning an + empty response instead of a HTTP 404. This issue is resolved for both + resources.