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

Commit

Permalink
workflows: display tickets with its url when fetching workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
DonHaul committed Aug 16, 2024
1 parent ed845d4 commit 17f0cc1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
2 changes: 2 additions & 0 deletions backoffice/.envs/local/.django
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ OPENSEARCH_INDEX_PREFIX=backoffice-backend-local
# Airflow
AIRFLOW_BASE_URL=http://airflow-webserver:8080
AIRFLOW_TOKEN=YWlyZmxvdzphaXJmbG93

SERVICENOW_URL=https://cerntraining.service-now.com
20 changes: 16 additions & 4 deletions backoffice/backoffice/workflows/api/serializers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from os import environ

from django_elasticsearch_dsl_drf.serializers import DocumentSerializer
from drf_spectacular.utils import OpenApiExample, extend_schema_serializer
from rest_framework import serializers
Expand All @@ -7,15 +9,25 @@
from backoffice.workflows.models import Workflow, WorkflowTicket


class WorkflowSerializer(serializers.ModelSerializer):
class WorkflowTicketSerializer(serializers.ModelSerializer):
ticket_url = serializers.SerializerMethodField()

class Meta:
model = Workflow
model = WorkflowTicket
fields = "__all__"

def get_ticket_url(self, obj):
return (
f"{environ.get('SERVICENOW_URL')}"
f"/nav_to.do?uri=/u_request_fulfillment.do?sys_id={obj.ticket_id}"
)


class WorkflowSerializer(serializers.ModelSerializer):
tickets = WorkflowTicketSerializer(many=True, read_only=True)

class WorkflowTicketSerializer(serializers.ModelSerializer):
class Meta:
model = WorkflowTicket
model = Workflow
fields = "__all__"


Expand Down
4 changes: 3 additions & 1 deletion backoffice/backoffice/workflows/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class Workflow(models.Model):


class WorkflowTicket(models.Model):
workflow_id = models.ForeignKey(Workflow, on_delete=models.CASCADE)
workflow_id = models.ForeignKey(
Workflow, related_name="tickets", on_delete=models.CASCADE
)
ticket_id = models.CharField(
max_length=32, null=False, blank=False
) # in SNOW it's GUID
Expand Down
18 changes: 17 additions & 1 deletion backoffice/backoffice/workflows/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
from rest_framework.test import APIClient

from backoffice.workflows import airflow_utils
from backoffice.workflows.api.serializers import WorkflowTicketSerializer
from backoffice.workflows.api.serializers import (
WorkflowSerializer,
WorkflowTicketSerializer,
)
from backoffice.workflows.constants import WORKFLOW_DAGS, StatusChoices, WorkflowType
from backoffice.workflows.models import WorkflowTicket

Expand Down Expand Up @@ -75,6 +78,16 @@ def test_list_anonymous(self):

self.assertEqual(response.status_code, 403)

def test_tickets(self):
WorkflowTicket.objects.create(
workflow_id=self.workflow, ticket_id="123", ticket_type="author_create_user"
)
workflow_data = WorkflowSerializer(self.workflow).data

assert "tickets" in workflow_data
assert "ticket_id" in workflow_data["tickets"][0]
assert "ticket_type" in workflow_data["tickets"][0]


class TestWorkflowSearchViewSet(BaseTransactionTestCase):
endpoint = "/api/workflows/search/"
Expand Down Expand Up @@ -219,6 +232,9 @@ def test_get_ticket_happy_flow(self):
assert response.status_code == 200
assert response.data == WorkflowTicketSerializer(self.workflow_ticket).data

def test_ticket_url(self):
assert "ticket_url" in WorkflowTicketSerializer(self.workflow_ticket).data

def test_create_missing_params(self):
self.api_client.force_authenticate(user=self.curator)
response = self.api_client.post(
Expand Down

0 comments on commit 17f0cc1

Please sign in to comment.