From 63d0b1373a6c0a87a68c62c1ff504eaa050044ad Mon Sep 17 00:00:00 2001 From: Paul Konstantin Gerke Date: Mon, 10 Jan 2022 16:03:18 +0100 Subject: [PATCH] Reworked POST to PATCH endpoints Signed-off-by: Paul Konstantin Gerke --- api/tests.py | 8 ++++---- api/views.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/tests.py b/api/tests.py index 57101256..6d0b77db 100644 --- a/api/tests.py +++ b/api/tests.py @@ -404,7 +404,7 @@ class TimerAPITestCase(TestBase.BabyBuddyAPITestCaseBase): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertFalse(response.data["active"]) - response = self.client.post(f"{endpoint}restart/") + response = self.client.patch(f"{endpoint}restart/") self.assertEqual(response.status_code, status.HTTP_200_OK) response = self.client.get(endpoint) @@ -412,10 +412,10 @@ class TimerAPITestCase(TestBase.BabyBuddyAPITestCaseBase): self.assertTrue(response.data["active"]) # Restart twice fails - response = self.client.post(f"{endpoint}restart/") + response = self.client.patch(f"{endpoint}restart/") self.assertEqual(response.status_code, status.HTTP_412_PRECONDITION_FAILED) - response = self.client.post(f"{endpoint}stop/") + response = self.client.patch(f"{endpoint}stop/") self.assertEqual(response.status_code, status.HTTP_200_OK) response = self.client.get(endpoint) @@ -423,7 +423,7 @@ class TimerAPITestCase(TestBase.BabyBuddyAPITestCaseBase): self.assertFalse(response.data["active"]) # Stopping twice fails - response = self.client.post(f"{endpoint}stop/") + response = self.client.patch(f"{endpoint}stop/") self.assertEqual(response.status_code, status.HTTP_412_PRECONDITION_FAILED) diff --git a/api/views.py b/api/views.py index a12da8ad..dcf05b2c 100644 --- a/api/views.py +++ b/api/views.py @@ -61,7 +61,7 @@ class TimerViewSet(viewsets.ModelViewSet): status=status.HTTP_404_NOT_FOUND ) - @action(detail=True, methods=['post']) + @action(detail=True, methods=['patch']) def stop(self, request, pk=None): def do_stop(timer): if not timer.active: @@ -73,7 +73,7 @@ class TimerViewSet(viewsets.ModelViewSet): return Response({"detail": "timer stopped"}) return self.__timer_operation(pk, do_stop) - @action(detail=True, methods=['post']) + @action(detail=True, methods=['patch']) def restart(self, request, pk=None): def do_restart(timer): if timer.active: