From 9b3c55445dbcb95f2344d2215d38457b7c30e0f8 Mon Sep 17 00:00:00 2001 From: DonHaul Date: Tue, 20 Aug 2024 15:57:32 +0200 Subject: [PATCH] decisions: added to endpoint to resolve --- backoffice/backoffice/workflows/api/views.py | 31 +++++++++----------- workflows/tests/__init__.py | 0 workflows/tests/test_author_create_tasks.py | 20 ------------- workflows/tests/test_dags_integrity.py | 6 ---- workflows/tests/test_example.py | 2 -- 5 files changed, 14 insertions(+), 45 deletions(-) delete mode 100644 workflows/tests/__init__.py delete mode 100644 workflows/tests/test_author_create_tasks.py delete mode 100644 workflows/tests/test_dags_integrity.py delete mode 100644 workflows/tests/test_example.py diff --git a/backoffice/backoffice/workflows/api/views.py b/backoffice/backoffice/workflows/api/views.py index 7da3f604c..297089440 100644 --- a/backoffice/backoffice/workflows/api/views.py +++ b/backoffice/backoffice/workflows/api/views.py @@ -43,6 +43,16 @@ logger = logging.getLogger(__name__) +def add_decision(workflow_id, user, action): + serializer_class = DecisionSerializer + data = {"workflow": workflow_id, "user": user, "action": action} + + serializer = serializer_class(data=data) + if serializer.is_valid(raise_exception=True): + serializer.save() + return Response(serializer.data, status=status.HTTP_201_CREATED) + + class WorkflowViewSet(viewsets.ModelViewSet): queryset = Workflow.objects.all() serializer_class = WorkflowSerializer @@ -103,25 +113,11 @@ def create(self, request, *args, **kwargs): class DecisionViewSet(viewsets.ModelViewSet): queryset = Decision.objects.all() - serializer_class = DecisionSerializer - - def get_queryset(self): - status = self.request.query_params.get("status") - if status: - return self.queryset.filter(status__status=status) - return self.queryset def create(self, request, *args, **kwargs): - data = { - "workflow": request.data["workflow_id"], - "user": request.user, - "action": request.data["action"], - } - - serializer = self.serializer_class(data=data) - if serializer.is_valid(raise_exception=True): - serializer.save() - return Response(serializer.data, status=status.HTTP_201_CREATED) + return add_decision( + request.data["workflow_id"], request.user, request.data["action"] + ) class AuthorWorkflowViewSet(viewsets.ViewSet): @@ -190,6 +186,7 @@ def resolve(self, request, pk=None): ResolutionDags[serializer.validated_data["value"]], pk, ) + add_decision(pk, request.user, serializer.validated_data["value"]) return airflow_utils.trigger_airflow_dag( ResolutionDags[serializer.validated_data["value"]].label, pk, extra_data diff --git a/workflows/tests/__init__.py b/workflows/tests/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/workflows/tests/test_author_create_tasks.py b/workflows/tests/test_author_create_tasks.py deleted file mode 100644 index 048c16e05..000000000 --- a/workflows/tests/test_author_create_tasks.py +++ /dev/null @@ -1,20 +0,0 @@ -import pytest -from dags.author.author_create.shared_tasks import ( - create_decision_on_curation_choice, -) - - -class TestAuthorCreate: - context = { - "params": { - "workflow_id": "ecaa62db-1326-43cf-8885-da96c544af42", - "data": { - "value": "create", - }, - } - } - - @pytest.mark.vcr() - def test_create_decision_on_curation_choice(self): - result = create_decision_on_curation_choice.function(**self.context) - assert result.status_code == 201 diff --git a/workflows/tests/test_dags_integrity.py b/workflows/tests/test_dags_integrity.py deleted file mode 100644 index 86d1b16d2..000000000 --- a/workflows/tests/test_dags_integrity.py +++ /dev/null @@ -1,6 +0,0 @@ -from airflow.models import DagBag - - -def test_dagbag(): - dag_bag = DagBag(include_examples=False) - assert not dag_bag.import_errors diff --git a/workflows/tests/test_example.py b/workflows/tests/test_example.py deleted file mode 100644 index 813df6020..000000000 --- a/workflows/tests/test_example.py +++ /dev/null @@ -1,2 +0,0 @@ -def test_example(): - assert True