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

backoffice: workflow views return object #96

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure we need to do a query here? The object is already changed in the session

)

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
Loading