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

Commit

Permalink
Merge pull request #96 from DonHaul/endpoint-return-obj
Browse files Browse the repository at this point in the history
backoffice: workflow views return object
  • Loading branch information
DonHaul authored Aug 27, 2024
2 parents 1487380 + 97fd4cf commit d52647a
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 @@ -122,11 +122,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 @@ -169,9 +170,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 @@ -361,7 +363,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 @@ -379,7 +382,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 @@ -400,6 +404,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 d52647a

Please sign in to comment.