forked from extern/django-helpdesk
Add kb tests
This commit is contained in:
parent
b20f600db2
commit
0b50b14449
83
helpdesk/tests/test_kb.py
Normal file
83
helpdesk/tests/test_kb.py
Normal file
@ -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, '<i class="fa fa-thumbs-up fa-lg"></i>')
|
||||
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")
|
||||
|
@ -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, '<option value="1" selected>KBItem 1</option>')
|
||||
self.assertContains(response, '<input type="email" name="submitter_email" value="foo@bar.cz" class="form-control form-control" required id="id_submitter_email">')
|
||||
self.assertContains(response, '<input type="text" name="title" value="lol" class="form-control form-control" maxlength="100" required id="id_title">')
|
||||
|
@ -232,14 +232,14 @@ if helpdesk_settings.HELPDESK_KB_ENABLED:
|
||||
kb.index,
|
||||
name='kb_index'),
|
||||
|
||||
url(r'^kb/(?P<item>[0-9]+)/vote/$',
|
||||
kb.vote,
|
||||
name='kb_vote'),
|
||||
|
||||
url(r'^kb/(?P<slug>[A-Za-z0-9_-]+)/$',
|
||||
kb.category,
|
||||
name='kb_category'),
|
||||
|
||||
url(r'^kb/(?P<item>[0-9]+)/vote/$',
|
||||
kb.vote,
|
||||
name='kb_vote'),
|
||||
|
||||
url(r'^kb_iframe/(?P<slug>[A-Za-z0-9_-]+)/$',
|
||||
kb.category_iframe,
|
||||
name='kb_category_iframe'),
|
||||
|
Loading…
Reference in New Issue
Block a user