2012-08-07 16:04:34 +02:00
|
|
|
from django.test import TestCase
|
|
|
|
from django.test.client import Client
|
2017-12-28 15:11:34 +01:00
|
|
|
from django.urls import reverse
|
2022-07-22 03:26:41 +02:00
|
|
|
from helpdesk.models import Queue, Ticket
|
2012-08-07 16:04:34 +02:00
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
|
2012-08-07 16:04:34 +02:00
|
|
|
class PublicActionsTestCase(TestCase):
|
|
|
|
"""
|
|
|
|
Tests for public actions:
|
|
|
|
- View a ticket
|
|
|
|
- Add a followup
|
|
|
|
- Close resolved case
|
|
|
|
"""
|
2016-10-23 22:10:32 +02:00
|
|
|
|
2012-08-07 16:04:34 +02:00
|
|
|
def setUp(self):
|
|
|
|
"""
|
|
|
|
Create a queue & ticket we can use for later tests.
|
|
|
|
"""
|
2016-10-21 17:14:12 +02:00
|
|
|
self.queue = Queue.objects.create(title='Queue 1',
|
|
|
|
slug='q',
|
|
|
|
allow_public_submission=True,
|
|
|
|
new_ticket_cc='new.public@example.com',
|
|
|
|
updated_ticket_cc='update.public@example.com')
|
|
|
|
self.ticket = Ticket.objects.create(title='Test Ticket',
|
|
|
|
queue=self.queue,
|
|
|
|
submitter_email='test.submitter@example.com',
|
|
|
|
description='This is a test ticket.')
|
2012-08-07 16:04:34 +02:00
|
|
|
|
|
|
|
self.client = Client()
|
|
|
|
|
|
|
|
def test_public_view_ticket(self):
|
2018-09-08 20:36:35 +02:00
|
|
|
# Without key, we get 403
|
2016-10-21 17:14:12 +02:00
|
|
|
response = self.client.get('%s?ticket=%s&email=%s' % (
|
2016-10-24 08:04:31 +02:00
|
|
|
reverse('helpdesk:public_view'),
|
2016-10-21 17:14:12 +02:00
|
|
|
self.ticket.ticket_for_url,
|
|
|
|
'test.submitter@example.com'))
|
2018-09-08 20:36:35 +02:00
|
|
|
self.assertEqual(response.status_code, 403)
|
2012-08-08 06:32:17 +02:00
|
|
|
self.assertTemplateNotUsed(response, 'helpdesk/public_view_form.html')
|
2018-09-08 20:36:35 +02:00
|
|
|
# With a key it works
|
|
|
|
response = self.client.get('%s?ticket=%s&email=%s&key=%s' % (
|
|
|
|
reverse('helpdesk:public_view'),
|
|
|
|
self.ticket.ticket_for_url,
|
|
|
|
'test.submitter@example.com',
|
|
|
|
self.ticket.secret_key))
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertTemplateUsed(response, 'helpdesk/public_view_ticket.html')
|
2012-08-07 16:04:34 +02:00
|
|
|
|
|
|
|
def test_public_close(self):
|
|
|
|
old_status = self.ticket.status
|
|
|
|
old_resolution = self.ticket.resolution
|
|
|
|
resolution_text = 'Resolved by test script'
|
2012-08-08 06:32:17 +02:00
|
|
|
|
|
|
|
ticket = Ticket.objects.get(id=self.ticket.id)
|
2016-10-23 22:10:32 +02:00
|
|
|
|
2012-08-08 06:32:17 +02:00
|
|
|
ticket.status = Ticket.RESOLVED_STATUS
|
|
|
|
ticket.resolution = resolution_text
|
|
|
|
ticket.save()
|
2012-08-07 16:04:34 +02:00
|
|
|
|
2012-08-08 06:32:17 +02:00
|
|
|
current_followups = ticket.followup_set.all().count()
|
2016-10-23 22:10:32 +02:00
|
|
|
|
2018-09-08 20:36:35 +02:00
|
|
|
response = self.client.get('%s?ticket=%s&email=%s&close&key=%s' % (
|
2016-10-24 08:04:31 +02:00
|
|
|
reverse('helpdesk:public_view'),
|
2016-10-21 17:14:12 +02:00
|
|
|
ticket.ticket_for_url,
|
2018-09-08 20:36:35 +02:00
|
|
|
'test.submitter@example.com',
|
|
|
|
ticket.secret_key))
|
2016-10-23 22:10:32 +02:00
|
|
|
|
2012-08-07 16:04:34 +02:00
|
|
|
ticket = Ticket.objects.get(id=self.ticket.id)
|
|
|
|
|
2012-08-08 06:32:17 +02:00
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
self.assertTemplateNotUsed(response, 'helpdesk/public_view_form.html')
|
2012-08-07 16:04:34 +02:00
|
|
|
self.assertEqual(ticket.status, Ticket.CLOSED_STATUS)
|
|
|
|
self.assertEqual(ticket.resolution, resolution_text)
|
2022-07-12 12:34:19 +02:00
|
|
|
self.assertEqual(current_followups + 1,
|
|
|
|
ticket.followup_set.all().count())
|
2016-10-23 22:10:32 +02:00
|
|
|
|
2012-08-08 06:32:17 +02:00
|
|
|
ticket.resolution = old_resolution
|
|
|
|
ticket.status = old_status
|
|
|
|
ticket.save()
|