File tree Expand file tree Collapse file tree 3 files changed +23
-0
lines changed Expand file tree Collapse file tree 3 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 5
5
6
6
import email .parser
7
7
8
+ from django .http import Http404
8
9
from rest_framework .generics import ListAPIView
9
10
from rest_framework .serializers import SerializerMethodField
10
11
11
12
from patchwork .api .base import BaseHyperlinkedModelSerializer
12
13
from patchwork .api .base import PatchworkPermission
13
14
from patchwork .api .embedded import PersonSerializer
14
15
from patchwork .models import Comment
16
+ from patchwork .models import Submission
15
17
16
18
17
19
class CommentListSerializer (BaseHyperlinkedModelSerializer ):
@@ -64,6 +66,9 @@ class CommentList(ListAPIView):
64
66
lookup_url_kwarg = 'pk'
65
67
66
68
def get_queryset (self ):
69
+ if not Submission .objects .filter (pk = self .kwargs ['pk' ]).exists ():
70
+ raise Http404
71
+
67
72
return Comment .objects .filter (
68
73
submission = self .kwargs ['pk' ]
69
74
).select_related ('submitter' )
Original file line number Diff line number Diff line change @@ -61,6 +61,12 @@ def test_list(self):
61
61
with self .assertRaises (NoReverseMatch ):
62
62
self .client .get (self .api_url (cover_obj , version = '1.0' ))
63
63
64
+ def test_list_invalid_cover (self ):
65
+ """Ensure we get a 404 for a non-existent cover letter."""
66
+ resp = self .client .get (
67
+ reverse ('api-cover-comment-list' , kwargs = {'pk' : '99999' }))
68
+ self .assertEqual (status .HTTP_404_NOT_FOUND , resp .status_code )
69
+
64
70
65
71
@unittest .skipUnless (settings .ENABLE_REST_API , 'requires ENABLE_REST_API' )
66
72
class TestPatchComments (APITestCase ):
@@ -99,3 +105,9 @@ def test_list(self):
99
105
# check we can't access comments using the old version of the API
100
106
with self .assertRaises (NoReverseMatch ):
101
107
self .client .get (self .api_url (patch_obj , version = '1.0' ))
108
+
109
+ def test_list_invalid_patch (self ):
110
+ """Ensure we get a 404 for a non-existent patch."""
111
+ resp = self .client .get (
112
+ reverse ('api-patch-comment-list' , kwargs = {'pk' : '99999' }))
113
+ self .assertEqual (status .HTTP_404_NOT_FOUND , resp .status_code )
Original file line number Diff line number Diff line change
1
+ ---
2
+ fixes :
3
+ - |
4
+ Showing comments for a non-existant patch or cover letter was returning an
5
+ empty response instead of a HTTP 404. This issue is resolved for both
6
+ resources.
You can’t perform that action at this time.
0 commit comments