diff --git a/changelog.d/1194.added.md b/changelog.d/1194.added.md new file mode 100644 index 000000000..d9c26471f --- /dev/null +++ b/changelog.d/1194.added.md @@ -0,0 +1 @@ +Add fake ticket page that DummyPlugin links to when creating a ticket. diff --git a/src/argus/htmx/incident/urls.py b/src/argus/htmx/incident/urls.py index 47fe3b186..106c01adb 100644 --- a/src/argus/htmx/incident/urls.py +++ b/src/argus/htmx/incident/urls.py @@ -15,4 +15,5 @@ path("filter/delete//", views.delete_filter, name="filter-delete"), path("filter/update//", views.update_filter, name="filter-update"), path("filter/existing/", views.get_existing_filters, name="existing-filters"), + path("fake_ticket//", views.get_fake_ticket, name="fake-ticket"), ] diff --git a/src/argus/htmx/incident/views.py b/src/argus/htmx/incident/views.py index a55fa7da5..29ae800aa 100644 --- a/src/argus/htmx/incident/views.py +++ b/src/argus/htmx/incident/views.py @@ -3,11 +3,14 @@ import logging from datetime import datetime, timedelta from typing import Optional +from urllib.parse import urljoin from django import forms +from django.conf import settings from django.contrib.auth import get_user_model from django.contrib import messages from django.utils.timezone import now as tznow +from django.urls import reverse from django.shortcuts import render, get_object_or_404 from django.views.decorators.http import require_POST, require_GET @@ -19,6 +22,7 @@ from argus.incident.models import Incident from argus.incident.ticket.utils import get_ticket_plugin_path from argus.incident.ticket.base import TicketPluginException +from argus.incident.serializers import IncidentSerializer from argus.notificationprofile.models import Filter from argus.util.datetime_utils import make_aware @@ -257,3 +261,15 @@ def incident_list(request: HtmxHttpRequest) -> HttpResponse: } return render(request, "htmx/incident/incident_list.html", context=context) + + +@require_GET +def get_fake_ticket(request: HtmxHttpRequest, pk: int) -> HttpResponse: + incident = get_object_or_404(Incident.objects.all(), pk=pk) + context = IncidentSerializer(incident).data + argus_url = urljoin( + getattr(settings, "FRONTEND_URL", ""), + reverse("htmx:incident-detail", kwargs={"pk": pk}), + ) + context["argus_url"] = argus_url + return render(request, "incident/ticket/default_ticket_body.html", context=context) diff --git a/src/argus/incident/ticket/dummy.py b/src/argus/incident/ticket/dummy.py index 5f1f60f4e..79a158b8f 100644 --- a/src/argus/incident/ticket/dummy.py +++ b/src/argus/incident/ticket/dummy.py @@ -10,6 +10,11 @@ from factory import Faker import logging +from urllib.parse import urljoin + +from django.conf import settings +from django.urls import reverse + from .base import TicketPlugin @@ -56,8 +61,6 @@ def create(self, *args, **kwargs): global created_tickets created_tickets.append((*args, kwargs)) - return _get_fake_url() - class DummyPlugin(TicketPlugin): """Example of a minimal plugin, can be used for testing""" @@ -94,11 +97,14 @@ def create_ticket(cls, serialized_incident: dict): endpoint, authentication, ticket_information = cls.import_settings() client = cls.create_client(endpoint=endpoint, authentication=authentication) - ticket_url = client.create( + client.create( { "title": serialized_incident["description"], "description": serialized_incident["description"], } ) - - return ticket_url + url = urljoin( + getattr(settings, "FRONTEND_URL", ""), + reverse("htmx:incident-detail", kwargs={"pk": serialized_incident["pk"]}), + ) + return url diff --git a/tests/incident/ticket_plugins/test_dummy.py b/tests/incident/ticket_plugins/test_dummy.py index a92a5a58c..83b1abaa3 100644 --- a/tests/incident/ticket_plugins/test_dummy.py +++ b/tests/incident/ticket_plugins/test_dummy.py @@ -1,6 +1,6 @@ from django.core.exceptions import ValidationError from django.core.validators import URLValidator -from django.test import TestCase +from django.test import TestCase, override_settings from argus.incident.factories import SourceSystemFactory, SourceUserFactory, StatefulIncidentFactory from argus.incident.ticket.dummy import created_tickets @@ -16,6 +16,9 @@ def setUp(self): def tearDown(self): connect_signals() + @override_settings( + FRONTEND_URL="http://www.fakeurl.com", + ) def test_create_ticket_writes_to_local_variable(self): dummy_class = import_class_from_dotted_path("argus.incident.ticket.dummy.DummyPlugin")