test helpdesk.views.staff.return_to_ticket

This commit is contained in:
Stefano Brentegani 2014-07-30 06:07:08 +02:00
parent ccec263452
commit c0dd6ea075
2 changed files with 39 additions and 3 deletions

View File

@ -7,6 +7,8 @@ except ImportError:
else:
User = get_user_model()
from helpdesk.models import Ticket, Queue
def get_staff_user(username='helpdesk.staff', password='password'):
try:
@ -49,3 +51,18 @@ def delete_user_settings(user, *args):
del settings[setting]
usersettings.settings = settings
usersettings.save()
def create_ticket(**kwargs):
q = kwargs.get('queue', None)
if q is None:
try:
q = Queue.objects.all()[0]
except IndexError:
q = Queue.objects.create(title='Test Q', slug='test', )
data = {
'title': "I wish to register a complaint",
'queue': q,
}
data.update(kwargs)
return Ticket.objects.create(**data)

View File

@ -4,7 +4,8 @@ from django.core.urlresolvers import reverse
from django.test import TestCase
from helpdesk import settings
from helpdesk.tests.helpers import get_staff_user, reload_urlconf, User, update_user_settings, delete_user_settings
from helpdesk.tests.helpers import (get_staff_user, reload_urlconf, User, update_user_settings, delete_user_settings,
create_ticket)
class KBDisabledTestCase(TestCase):
@ -146,7 +147,7 @@ class CustomStaffUserTestCase(StaffUserTestCaseMixin, TestCase):
self.assertTemplateUsed(response, 'helpdesk/registration/login.html')
class HomePageAnonymousUserTest(TestCase):
class HomePageAnonymousUserTestCase(TestCase):
def setUp(self):
self.redirect_to_login = settings.HELPDESK_REDIRECT_TO_LOGIN_BY_DEFAULT
@ -165,7 +166,7 @@ class HomePageAnonymousUserTest(TestCase):
self.assertRedirects(response, reverse('login'))
class HomePageTest(TestCase):
class HomePageTestCase(TestCase):
def setUp(self):
self.previous = settings.HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE, settings.HELPDESK_CUSTOM_STAFF_FILTER_CALLBACK
settings.HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE = False
@ -211,3 +212,21 @@ class HomePageTest(TestCase):
update_user_settings(user, login_view_ticketlist=True)
self.assertUserRedirectedToView(user, 'helpdesk_list')
class ReturnToTicketTestCase(TestCase):
def test_staff_user(self):
from helpdesk.views.staff import return_to_ticket
user = get_staff_user()
ticket = create_ticket()
response = return_to_ticket(user, settings, ticket)
self.assertEqual(response['location'], ticket.get_absolute_url())
def test_non_staff_user(self):
from helpdesk.views.staff import return_to_ticket
user = User.objects.create_user(username='henry.wensleydale', password='gouda', email='wensleydale@example.com')
ticket = create_ticket()
response = return_to_ticket(user, settings, ticket)
self.assertEqual(response['location'], ticket.ticket_url)