2020-01-20 14:17:23 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2020-01-09 17:35:05 +01:00
|
|
|
from django.test import TestCase
|
2022-07-22 03:26:41 +02:00
|
|
|
from django.urls import reverse
|
2020-01-09 17:35:05 +01:00
|
|
|
from helpdesk.models import KBCategory, KBItem, Queue, Ticket
|
2023-11-14 20:07:25 +01:00
|
|
|
from helpdesk.tests.helpers import get_staff_user
|
2020-01-09 17:35:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
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):
|
2022-07-12 12:34:19 +02:00
|
|
|
response = self.client.get(
|
|
|
|
reverse('helpdesk:kb_category', args=("test_cat", )))
|
2020-01-09 17:35:05 +01:00
|
|
|
self.assertContains(response, 'This is a test category')
|
|
|
|
self.assertContains(response, 'KBItem 1')
|
|
|
|
self.assertContains(response, 'KBItem 2')
|
2021-02-11 02:09:46 +01:00
|
|
|
self.assertContains(response, 'Create New Ticket Queue:')
|
2022-07-12 12:34:19 +02:00
|
|
|
self.client.login(username=self.user.get_username(),
|
|
|
|
password='password')
|
|
|
|
response = self.client.get(
|
|
|
|
reverse('helpdesk:kb_category', args=("test_cat", )))
|
2020-01-09 17:35:05 +01:00
|
|
|
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()
|
2022-07-12 12:34:19 +02:00
|
|
|
response = self.client.get(
|
|
|
|
reverse('helpdesk:kb_category', args=("test_cat",)))
|
2020-01-09 17:35:05 +01:00
|
|
|
self.assertContains(response, '1 open tickets')
|
|
|
|
|
|
|
|
def test_kb_vote(self):
|
2022-07-12 12:34:19 +02:00
|
|
|
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"
|
2020-01-09 17:35:05 +01:00
|
|
|
self.assertRedirects(response, cat_url)
|
|
|
|
response = self.client.get(cat_url)
|
|
|
|
self.assertContains(response, '1 people found this answer useful of 1')
|
2022-07-12 12:34:19 +02:00
|
|
|
response = self.client.get(
|
|
|
|
reverse('helpdesk:kb_vote', args=(self.kbitem1.pk,)) + "?vote=down")
|
2020-01-09 17:35:05 +01:00
|
|
|
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):
|
2022-07-12 12:34:19 +02:00
|
|
|
cat_url = reverse('helpdesk:kb_category', args=(
|
|
|
|
"test_cat",)) + "?kbitem=1&submitter_email=foo@bar.cz&title=lol&"
|
2020-01-09 17:35:05 +01:00
|
|
|
response = self.client.get(cat_url)
|
|
|
|
# Assert that query params are passed on to ticket submit form
|
2022-07-12 12:34:19 +02:00
|
|
|
self.assertContains(
|
|
|
|
response, "'/tickets/submit/?queue=1&_readonly_fields_=queue&kbitem=1&submitter_email=foo%40bar.cz&title=lol")
|