From 5761f3fd88c4c92ac723630adcf1421d3665d297 Mon Sep 17 00:00:00 2001 From: DonHaul Date: Wed, 28 Aug 2024 14:41:31 +0200 Subject: [PATCH] backoffice: rename foreign key for workflow in ticket * ref: cern-sis/issues-inspire/issues/547 --- .../backoffice/workflows/api/serializers.py | 2 +- ...ename_workflow_id_workflowticket_workflow.py | 17 +++++++++++++++++ backoffice/backoffice/workflows/models.py | 2 +- .../backoffice/workflows/tests/test_views.py | 10 +++++----- 4 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 backoffice/backoffice/workflows/migrations/0011_rename_workflow_id_workflowticket_workflow.py diff --git a/backoffice/backoffice/workflows/api/serializers.py b/backoffice/backoffice/workflows/api/serializers.py index bf7bf9f5..b7c2b60f 100644 --- a/backoffice/backoffice/workflows/api/serializers.py +++ b/backoffice/backoffice/workflows/api/serializers.py @@ -11,7 +11,7 @@ class WorkflowTicketSerializer(serializers.ModelSerializer): ticket_url = serializers.SerializerMethodField() - workflow_id = serializers.PrimaryKeyRelatedField(queryset=Workflow.objects.all()) + workflow = serializers.PrimaryKeyRelatedField(queryset=Workflow.objects.all()) class Meta: model = WorkflowTicket diff --git a/backoffice/backoffice/workflows/migrations/0011_rename_workflow_id_workflowticket_workflow.py b/backoffice/backoffice/workflows/migrations/0011_rename_workflow_id_workflowticket_workflow.py new file mode 100644 index 00000000..473980fe --- /dev/null +++ b/backoffice/backoffice/workflows/migrations/0011_rename_workflow_id_workflowticket_workflow.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.6 on 2024-08-28 11:55 + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("workflows", "0010_alter_decision_workflow_and_more"), + ] + + operations = [ + migrations.RenameField( + model_name="workflowticket", + old_name="workflow_id", + new_name="workflow", + ), + ] diff --git a/backoffice/backoffice/workflows/models.py b/backoffice/backoffice/workflows/models.py index d4fb3704..77bced43 100644 --- a/backoffice/backoffice/workflows/models.py +++ b/backoffice/backoffice/workflows/models.py @@ -36,7 +36,7 @@ class Workflow(models.Model): class WorkflowTicket(models.Model): - workflow_id = models.ForeignKey( + workflow = models.ForeignKey( Workflow, related_name="tickets", on_delete=models.CASCADE ) ticket_id = models.CharField( diff --git a/backoffice/backoffice/workflows/tests/test_views.py b/backoffice/backoffice/workflows/tests/test_views.py index 0f6ff9a5..2300830a 100644 --- a/backoffice/backoffice/workflows/tests/test_views.py +++ b/backoffice/backoffice/workflows/tests/test_views.py @@ -93,7 +93,7 @@ def test_list_anonymous(self): def test_tickets(self): WorkflowTicket.objects.create( - workflow_id=self.workflow, ticket_id="123", ticket_type="author_create_user" + workflow=self.workflow, ticket_id="123", ticket_type="author_create_user" ) workflow_data = WorkflowSerializer(self.workflow).data @@ -242,7 +242,7 @@ def setUp(self): data={}, status="running", core=True, is_update=False ) self.workflow_ticket = WorkflowTicket.objects.create( - workflow_id=self.workflow, ticket_id="123", ticket_type="author_create_user" + workflow=self.workflow, ticket_id="123", ticket_type="author_create_user" ) def test_get_missing_params(self): @@ -294,7 +294,7 @@ def test_create_missing_params(self): assert response.status_code == 400 assert response.json() == { - "workflow_id": ["This field is required."], + "workflow": ["This field is required."], "ticket_id": ["This field is required."], } @@ -302,7 +302,7 @@ def test_create_happy_flow(self): self.api_client.force_authenticate(user=self.curator) data = { - "workflow_id": self.workflow.id, + "workflow": str(self.workflow.id), "ticket_id": "dc94caad1b4f71502d06117a3b4bcb25", "ticket_type": "author_create_user", } @@ -312,7 +312,7 @@ def test_create_happy_flow(self): assert response.status_code == 201 - assert "workflow_id" in response.data + assert "workflow" in response.data assert "ticket_id" in response.data assert "ticket_type" in response.data