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

Commit

Permalink
backoffice: workflow views return object
Browse files Browse the repository at this point in the history
  • Loading branch information
DonHaul committed Aug 27, 2024
1 parent eb18714 commit 166d0ba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions backoffice/backoffice/workflows/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,12 @@ def create(self, request):
WORKFLOW_DAGS[workflow.workflow_type].initialize,
workflow.id,
)
return airflow_utils.trigger_airflow_dag(
airflow_utils.trigger_airflow_dag(
WORKFLOW_DAGS[workflow.workflow_type].initialize,
str(workflow.id),
workflow.data,
)
return Response(serializer.data, status=status.HTTP_201_CREATED)

@extend_schema(
summary="Partially Updates Author",
Expand Down Expand Up @@ -183,9 +184,14 @@ def resolve(self, request, pk=None):
)
utils.add_decision(pk, request.user, serializer.validated_data["value"])

return airflow_utils.trigger_airflow_dag(
airflow_utils.trigger_airflow_dag(
ResolutionDags[serializer.validated_data["value"]].label, pk, extra_data
)
workflow_serializer = self.serializer_class(
get_object_or_404(Workflow, pk=pk)
)

return Response(workflow_serializer.data)

@extend_schema(
summary="Restart an Author Workflow",
Expand Down
10 changes: 8 additions & 2 deletions backoffice/backoffice/workflows/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ def test_patch_admin(self):
"test": "test",
},
)
self.assertEqual(response.json()["id"], str(self.workflow.id))
self.assertIn("decisions", response.json())

def test_patch_anonymous(self):
self.api_client.force_authenticate(user=self.user)
Expand Down Expand Up @@ -360,7 +362,8 @@ def test_create_author(self):
url = reverse("api:workflows-authors-list")
response = self.api_client.post(url, format="json", data=data)

self.assertEqual(response.status_code, 200)
self.assertEqual(response.status_code, 201)
self.assertEqual(response.json(), data)

@pytest.mark.vcr()
def test_accept_author(self):
Expand All @@ -378,7 +381,8 @@ def test_accept_author(self):
self.assertEqual(
Decision.objects.filter(workflow=self.workflow.id)[0].action, action
)

self.assertEqual(response.json()["id"], str(self.workflow.id))
self.assertIn("decisions", response.json())
airflow_utils.delete_workflow_dag(
WORKFLOW_DAGS[WorkflowType.AUTHOR_CREATE].approve, self.workflow.id
)
Expand All @@ -399,6 +403,8 @@ def test_reject_author(self):
self.assertEqual(
Decision.objects.filter(workflow=self.workflow.id)[0].action, action
)
self.assertEqual(response.json()["id"], str(self.workflow.id))
self.assertIn("decisions", response.json())

airflow_utils.delete_workflow_dag(
WORKFLOW_DAGS[WorkflowType.AUTHOR_CREATE].reject, self.workflow.id
Expand Down

0 comments on commit 166d0ba

Please sign in to comment.