Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
add ticket_id to workflow_ticket create view
Browse files Browse the repository at this point in the history
  • Loading branch information
MJedr committed Dec 11, 2023
1 parent d703e1a commit 41eb31f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 6 additions & 3 deletions backoffice/workflows/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions backoffice/workflows/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 41eb31f

Please sign in to comment.