From 41eb31f9c91b6e7cde3bcddd4399f7071e8cbfa7 Mon Sep 17 00:00:00 2001 From: MJedr Date: Mon, 11 Dec 2023 14:08:00 +0100 Subject: [PATCH] add ticket_id to workflow_ticket create view --- backoffice/workflows/api/views.py | 9 ++++++--- backoffice/workflows/tests/test_views.py | 8 ++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/backoffice/workflows/api/views.py b/backoffice/workflows/api/views.py index 20758b3b..5a5cb73e 100644 --- a/backoffice/workflows/api/views.py +++ b/backoffice/workflows/api/views.py @@ -49,15 +49,18 @@ def retrieve(self, request, *args, **kwargs): def create(self, request, *args, **kwargs): workflow_id = request.data.get("workflow_id") ticket_type = request.data.get("ticket_type") + ticket_id = request.data.get("ticket_type") - if not workflow_id or not ticket_type: + if not all([workflow_id, ticket_type, ticket_id]): return Response( - {"error": "Both workflow_id and ticket_type are required."}, status=status.HTTP_400_BAD_REQUEST + {"error": "Workflow_id, ticket_id and ticket_type are required."}, status=status.HTTP_400_BAD_REQUEST ) try: workflow = Workflow.objects.get(id=workflow_id) - workflow_ticket = WorkflowTicket.objects.create(workflow_id=workflow, ticket_type=ticket_type) + workflow_ticket = WorkflowTicket.objects.create( + workflow_id=workflow, ticket_id=ticket_id, ticket_type=ticket_type + ) serializer = WorkflowTicketSerializer(workflow_ticket) return Response(serializer.data, status=status.HTTP_201_CREATED) except Exception as e: diff --git a/backoffice/workflows/tests/test_views.py b/backoffice/workflows/tests/test_views.py index 38d5662b..416e8740 100644 --- a/backoffice/workflows/tests/test_views.py +++ b/backoffice/workflows/tests/test_views.py @@ -145,12 +145,16 @@ def test_create_missing_params(self): response = self.api_client.post(f"{TestWorkflowTicketViewSet.endpoint}/", format="json", data={}) assert response.status_code == 400 - assert response.data == {"error": "Both workflow_id and ticket_type are required."} + assert response.data == {"error": "Workflow_id, ticket_id and ticket_type are required."} def test_create_happy_flow(self): self.api_client.force_authenticate(user=self.curator) - data = {"workflow_id": self.workflow.id, "ticket_type": "author_create_user"} + data = { + "workflow_id": self.workflow.id, + "ticket_id": "dc94caad1b4f71502d06117a3b4bcb25", + "ticket_type": "author_create_user", + } response = self.api_client.post(f"{TestWorkflowTicketViewSet.endpoint}/", format="json", data=data) assert response.status_code == 201