Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/1194.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add fake ticket page that DummyPlugin links to when creating a ticket.
1 change: 1 addition & 0 deletions src/argus/htmx/incident/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
path("filter/delete/<int:pk>/", views.delete_filter, name="filter-delete"),
path("filter/update/<int:pk>/", views.update_filter, name="filter-update"),
path("filter/existing/", views.get_existing_filters, name="existing-filters"),
path("fake_ticket/<int:pk>/", views.get_fake_ticket, name="fake-ticket"),
]
16 changes: 16 additions & 0 deletions src/argus/htmx/incident/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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)
16 changes: 11 additions & 5 deletions src/argus/incident/ticket/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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
5 changes: 4 additions & 1 deletion tests/incident/ticket_plugins/test_dummy.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")

Expand Down
Loading