This repository has been archived by the owner on Nov 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
author decisions: add decision table and populate it. implemented tas…
…k in airflow that allows for this and added unit tests for all the changes * ref: cern-sis/issues-inspire/issues/522
- Loading branch information
Showing
11 changed files
with
245 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,7 @@ jobs: | |
-v "$(pwd)"/tests:/opt/airflow/tests | ||
-v "$(pwd)"/requirements-test.txt:/opt/airflow/requirements-test.txt | ||
-v "$(pwd)"/data:/opt/airflow/data | ||
-v "$(pwd)"/scripts/variables/variables.json:/opt/airflow/variables.json | ||
-v "$(pwd)"/scripts:/opt/airflow/scripts | ||
-e AIRFLOW__CORE__EXECUTOR=CeleryExecutor | ||
-e AIRFLOW__DATABASE__SQL_ALCHEMY_CONN=postgresql+psycopg2://airflow:[email protected]:5432/airflow | ||
-e AIRFLOW__CELERY__RESULT_BACKEND=db+postgresql://airflow:[email protected]:5432/airflow | ||
|
@@ -61,4 +61,4 @@ jobs: | |
-e AIRFLOW__CORE__LOAD_EXAMPLES="false" | ||
-e AIRFLOW__API__AUTH_BACKENDS="airflow.api.auth.backend.basic_auth,airflow.api.auth.backend.session" | ||
registry.cern.ch/cern-sis/inspire/workflows@${{ needs.build.outputs.image-id }} | ||
bash -c "pip install -r requirements-test.txt && airflow db init && airflow variables import /opt/airflow/variables.json && pytest /opt/airflow/tests" | ||
bash -c "pip install -r requirements-test.txt && airflow db init && airflow connections import /opt/airflow/scripts/connections/connections.json && airflow variables import /opt/airflow/scripts/variables/variables.json && pytest /opt/airflow/tests" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from backoffice.workflows.api.serializers import DecisionSerializer | ||
|
||
|
||
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 serializer.data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
backoffice/backoffice/workflows/migrations/0009_decision.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Generated by Django 4.2.6 on 2024-08-15 12:25 | ||
|
||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
("workflows", "0008_alter_workflow_status_alter_workflow_workflow_type"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Decision", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
( | ||
"action", | ||
models.CharField( | ||
choices=[ | ||
("accept", "author_create_approved_dag"), | ||
("reject", "author_create_rejected_dag"), | ||
("accept_curate", "author_create_approved_dag"), | ||
], | ||
max_length=30, | ||
), | ||
), | ||
("_created_at", models.DateTimeField(auto_now_add=True)), | ||
("_updated_at", models.DateTimeField(auto_now=True)), | ||
( | ||
"user", | ||
models.ForeignKey( | ||
db_column="email", | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to=settings.AUTH_USER_MODEL, | ||
to_field="email", | ||
), | ||
), | ||
( | ||
"workflow", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="workflows.workflow", | ||
), | ||
), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import uuid | ||
|
||
import pytest | ||
from django.apps import apps | ||
from django.contrib.auth import get_user_model | ||
from django.test import TransactionTestCase | ||
from rest_framework.exceptions import ValidationError | ||
|
||
from backoffice.workflows import constants | ||
from backoffice.workflows.api import utils | ||
from backoffice.workflows.constants import StatusChoices | ||
|
||
User = get_user_model() | ||
Workflow = apps.get_model(app_label="workflows", model_name="Workflow") | ||
|
||
|
||
class TestUtils(TransactionTestCase): | ||
reset_sequences = True | ||
fixtures = ["backoffice/fixtures/groups.json"] | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.workflow = Workflow.objects.create( | ||
data={}, status=StatusChoices.APPROVAL, core=True, is_update=False | ||
) | ||
self.user = User.objects.create_user( | ||
email="[email protected]", password="12345" | ||
) | ||
|
||
def test_add_decision(self): | ||
decision_data = utils.add_decision( | ||
self.workflow.id, self.user, constants.ResolutionDags.accept | ||
) | ||
import ipdb | ||
|
||
ipdb.set_trace() | ||
|
||
self.assertIsNotNone(decision_data) | ||
|
||
def test_add_decision_validation_errors(self): | ||
with pytest.raises(ValidationError): | ||
utils.add_decision(self.workflow.id, self.user, "wrong") | ||
|
||
with pytest.raises(ValidationError): | ||
utils.add_decision( | ||
uuid.UUID(int=0), self.user, constants.ResolutionDags.accept | ||
) |
Oops, something went wrong.