Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
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"]}),
)
Comment on lines +106 to +109
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could move this into the create function, just to keep the concern of "creating a ticket" separate for demonstration purposes on how to write a ticket plugin

Comment on lines +106 to +109
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This returns the link to the incident detail page, not the fake ticket system page

Suggested change
url = urljoin(
getattr(settings, "FRONTEND_URL", ""),
reverse("htmx:incident-detail", kwargs={"pk": serialized_incident["pk"]}),
)
url = reverse("htmx:fake-ticket", 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