django-helpdeskmig/helpdesk/tests/public_actions.py
Ross Poulton 26e0809e5e Add some tests. Finally. First draft: just includes submission & public
action testing - needs plenty more tests added.
2012-08-08 00:04:34 +10:00

50 lines
2.0 KiB
Python

from helpdesk.models import Queue, CustomField, Ticket
from django.test import TestCase
from django.core import mail
from django.test.client import Client
from django.core.urlresolvers import reverse
class PublicActionsTestCase(TestCase):
"""
Tests for public actions:
- View a ticket
- Add a followup
- Close resolved case
"""
def setUp(self):
"""
Create a queue & ticket we can use for later tests.
"""
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.')
self.client = Client()
def test_public_view_ticket(self):
response = self.client.get('%s?id=%s&email=%s' % (reverse('helpdesk_public_view'), self.ticket.id, 'test.submitter@example.com'))
self.assertEqual(response.status_code, 200)
def test_public_close(self):
old_status = self.ticket.status
old_resolution = self.ticket.resolution
resolution_text = 'Resolved by test script'
self.ticket.status = Ticket.RESOLVED_STATUS
self.ticket.resolution = resolution_text
self.ticket.save()
current_followups = self.ticket.followup_set.all().count()
response = self.client.get('%s?id=%s&email=%s&close=yes' % (reverse('helpdesk_public_view'), self.ticket.id, 'test.submitter@example.com'))
ticket = Ticket.objects.get(id=self.ticket.id)
self.assertEqual(response.status_code, 200)
self.assertEqual(ticket.status, Ticket.CLOSED_STATUS)
self.assertEqual(ticket.resolution, resolution_text)
self.assertEqual(current_followups+1, self.ticket.followup_set.all().count())
self.ticket.resolution = old_resolution
self.ticket.status = old_status
self.ticket.save()