From c0dd6ea075aba9e01b6b3ffc490fc3e91f464894 Mon Sep 17 00:00:00 2001 From: Stefano Brentegani Date: Wed, 30 Jul 2014 06:07:08 +0200 Subject: [PATCH] test helpdesk.views.staff.return_to_ticket --- helpdesk/tests/helpers.py | 17 +++++++++++++++++ helpdesk/tests/navigation.py | 25 ++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/helpdesk/tests/helpers.py b/helpdesk/tests/helpers.py index ba73e990..9d0a9a00 100644 --- a/helpdesk/tests/helpers.py +++ b/helpdesk/tests/helpers.py @@ -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) \ No newline at end of file diff --git a/helpdesk/tests/navigation.py b/helpdesk/tests/navigation.py index 2af8cd29..88986d69 100644 --- a/helpdesk/tests/navigation.py +++ b/helpdesk/tests/navigation.py @@ -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)