diff --git a/helpdesk/tests/test_kb.py b/helpdesk/tests/test_kb.py
new file mode 100644
index 00000000..6eba76bd
--- /dev/null
+++ b/helpdesk/tests/test_kb.py
@@ -0,0 +1,83 @@
+#queue_publii -*- coding: utf-8 -*-
+from django.urls import reverse
+from django.test import TestCase
+
+from helpdesk.models import KBCategory, KBItem, Queue, Ticket
+
+from helpdesk.tests.helpers import (get_staff_user, reload_urlconf, User, create_ticket, print_response)
+
+
+class KBTests(TestCase):
+ def setUp(self):
+ self.queue = Queue.objects.create(
+ title="Test queue",
+ slug="test_queue",
+ allow_public_submission=True,
+ )
+ self.queue.save()
+ cat = KBCategory.objects.create(
+ title="Test Cat",
+ slug="test_cat",
+ description="This is a test category",
+ queue=self.queue,
+ )
+ cat.save()
+ self.kbitem1 = KBItem.objects.create(
+ category=cat,
+ title="KBItem 1",
+ question="What?",
+ answer="A KB Item",
+ )
+ self.kbitem1.save()
+ self.kbitem2 = KBItem.objects.create(
+ category=cat,
+ title="KBItem 2",
+ question="When?",
+ answer="Now",
+ )
+ self.kbitem2.save()
+ self.user = get_staff_user()
+
+ def test_kb_index(self):
+ response = self.client.get(reverse('helpdesk:kb_index'))
+ self.assertContains(response, 'This is a test category')
+
+ def test_kb_category(self):
+ response = self.client.get(reverse('helpdesk:kb_category', args=("test_cat", )))
+ self.assertContains(response, 'This is a test category')
+ self.assertContains(response, 'KBItem 1')
+ self.assertContains(response, 'KBItem 2')
+ self.assertContains(response, 'Contact a human')
+ self.client.login(username=self.user.get_username(), password='password')
+ response = self.client.get(reverse('helpdesk:kb_category', args=("test_cat", )))
+ self.assertContains(response, '')
+ self.assertContains(response, '0 open tickets')
+ ticket = Ticket.objects.create(
+ title="Test ticket",
+ queue=self.queue,
+ kbitem=self.kbitem1,
+ )
+ ticket.save()
+ response = self.client.get(reverse('helpdesk:kb_category', args=("test_cat",)))
+ self.assertContains(response, '1 open tickets')
+
+
+ def test_kb_vote(self):
+ self.client.login(username=self.user.get_username(), password='password')
+ response = self.client.get(reverse('helpdesk:kb_vote', args=(self.kbitem1.pk,)) + "?vote=up")
+ cat_url = reverse('helpdesk:kb_category', args=("test_cat",)) + "?kbitem=1"
+ self.assertRedirects(response, cat_url)
+ response = self.client.get(cat_url)
+ self.assertContains(response, '1 people found this answer useful of 1')
+ response = self.client.get(reverse('helpdesk:kb_vote', args=(self.kbitem1.pk,)) + "?vote=down")
+ self.assertRedirects(response, cat_url)
+ response = self.client.get(cat_url)
+ self.assertContains(response, '0 people found this answer useful of 1')
+
+
+ def test_kb_category_iframe(self):
+ cat_url = reverse('helpdesk:kb_category', args=("test_cat",)) + "?kbitem=1;submitter_email=foo@bar.cz;title=lol;"
+ response = self.client.get(cat_url)
+ # Assert that query params are passed on to ticket submit form
+ self.assertContains(response, "'/helpdesk/tickets/submit/?queue=1;_readonly_fields_=queue;kbitem=1;submitter_email=foo%40bar.cz&title=lol")
+
diff --git a/helpdesk/tests/test_ticket_submission.py b/helpdesk/tests/test_ticket_submission.py
index 547cb6cc..31fb0b68 100644
--- a/helpdesk/tests/test_ticket_submission.py
+++ b/helpdesk/tests/test_ticket_submission.py
@@ -2,7 +2,7 @@
import email
import uuid
-from helpdesk.models import Queue, CustomField, FollowUp, Ticket, TicketCC
+from helpdesk.models import Queue, CustomField, FollowUp, Ticket, TicketCC, KBCategory, KBItem
from django.test import TestCase
from django.core import mail
from django.core.exceptions import ObjectDoesNotExist
@@ -11,6 +11,7 @@ from django.test.client import Client
from django.urls import reverse
from helpdesk.email import object_from_message, create_ticket_cc
+from helpdesk.tests.helpers import print_response
from urllib.parse import urlparse
@@ -976,3 +977,24 @@ class EmailInteractionsTestCase(TestCase):
# public_update_queue: +1
expected_email_count += 1 + 2 + 1
self.assertEqual(expected_email_count, len(mail.outbox))
+
+ def test_ticket_field_autofill(self):
+ cat = KBCategory.objects.create(
+ title="Test Cat",
+ slug="test_cat",
+ description="This is a test category",
+ queue=self.queue_public,
+ )
+ cat.save()
+ self.kbitem1 = KBItem.objects.create(
+ category=cat,
+ title="KBItem 1",
+ question="What?",
+ answer="A KB Item",
+ )
+ self.kbitem1.save()
+ cat_url = reverse('helpdesk:submit') + "?kbitem=1;submitter_email=foo@bar.cz;title=lol;"
+ response = self.client.get(cat_url)
+ self.assertContains(response, '')
+ self.assertContains(response, '')
+ self.assertContains(response, '')
diff --git a/helpdesk/urls.py b/helpdesk/urls.py
index 94bd28c8..59f27bcc 100644
--- a/helpdesk/urls.py
+++ b/helpdesk/urls.py
@@ -232,14 +232,14 @@ if helpdesk_settings.HELPDESK_KB_ENABLED:
kb.index,
name='kb_index'),
- url(r'^kb/(?P- [0-9]+)/vote/$',
- kb.vote,
- name='kb_vote'),
-
url(r'^kb/(?P[A-Za-z0-9_-]+)/$',
kb.category,
name='kb_category'),
+ url(r'^kb/(?P
- [0-9]+)/vote/$',
+ kb.vote,
+ name='kb_vote'),
+
url(r'^kb_iframe/(?P[A-Za-z0-9_-]+)/$',
kb.category_iframe,
name='kb_category_iframe'),