]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
api: change <pk> parameter to <patch_id> for comments endpoint
authorRaxel Gutierrez <raxel@google.com>
Fri, 13 Aug 2021 05:31:18 +0000 (05:31 +0000)
committerStephen Finucane <stephen@that.guru>
Fri, 13 Aug 2021 09:25:34 +0000 (10:25 +0100)
Refactor patch lookup parameter `pk` to `patch_id` for the comments list
endpoint to disambiguate from the lookup parameter `comment_id` in an
upcoming patch which introduces the comments detail endpoint. This
doesn't affect the user-facing API.

Signed-off-by: Raxel Gutierrez <raxel@google.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
patchwork/api/comment.py
patchwork/api/patch.py
patchwork/tests/api/test_comment.py
patchwork/urls.py

index 43b26c6138a6f6a1fc40b1cbbcd03cfa92229690..0c578b44f1cb6ec84c2ee1a54b7f1d347e741e45 100644 (file)
@@ -102,12 +102,12 @@ class PatchCommentList(ListAPIView):
     search_fields = ('subject',)
     ordering_fields = ('id', 'subject', 'date', 'submitter')
     ordering = 'id'
-    lookup_url_kwarg = 'pk'
+    lookup_url_kwarg = 'patch_id'
 
     def get_queryset(self):
-        if not Patch.objects.filter(pk=self.kwargs['pk']).exists():
+        if not Patch.objects.filter(id=self.kwargs['patch_id']).exists():
             raise Http404
 
         return PatchComment.objects.filter(
-            patch=self.kwargs['pk']
+            patch=self.kwargs['patch_id']
         ).select_related('submitter')
index 9d222754412ed2919b909191f6b1b610b5df1e7b..a97a8820cd65b3c53bd9bf59af2ca9325178e390 100644 (file)
@@ -97,7 +97,7 @@ class PatchListSerializer(BaseHyperlinkedModelSerializer):
 
     def get_comments(self, patch):
         return self.context.get('request').build_absolute_uri(
-            reverse('api-patch-comment-list', kwargs={'pk': patch.id}))
+            reverse('api-patch-comment-list', kwargs={'patch_id': patch.id}))
 
     def get_check(self, instance):
         return instance.combined_check_state
index 5bbebf2ea939eb244e52fbe5f5bca55787e48c56..59450d8ab729d6041f3824ec296e137d1c089da6 100644 (file)
@@ -90,7 +90,7 @@ class TestPatchComments(utils.APITestCase):
         kwargs = {}
         if version:
             kwargs['version'] = version
-        kwargs['pk'] = patch.id
+        kwargs['patch_id'] = patch.id
 
         return reverse('api-patch-comment-list', kwargs=kwargs)
 
@@ -142,5 +142,5 @@ class TestPatchComments(utils.APITestCase):
     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'}))
+            reverse('api-patch-comment-list', kwargs={'patch_id': '99999'}))
         self.assertEqual(status.HTTP_404_NOT_FOUND, resp.status_code)
index 6ac9b81a8c034e5beadbac2ca0608d2018cbe6af..1e6c12ab2232d623b8b6bd56d97eb05ee4033b07 100644 (file)
@@ -332,7 +332,7 @@ if settings.ENABLE_REST_API:
 
     api_1_1_patterns = [
         path(
-            'patches/<pk>/comments/',
+            'patches/<patch_id>/comments/',
             api_comment_views.PatchCommentList.as_view(),
             name='api-patch-comment-list',
         ),