mirror of
https://gitea.mueller.network/extern/django-helpdesk.git
synced 2024-11-22 16:03:19 +01:00
Fixing some unit tests
This commit is contained in:
parent
449e3f9214
commit
5e8f5fed62
@ -5,7 +5,7 @@ from django.contrib.auth.models import User
|
|||||||
from pytz import UTC
|
from pytz import UTC
|
||||||
from rest_framework import HTTP_HEADER_ENCODING
|
from rest_framework import HTTP_HEADER_ENCODING
|
||||||
from rest_framework.exceptions import ErrorDetail
|
from rest_framework.exceptions import ErrorDetail
|
||||||
from rest_framework.status import HTTP_201_CREATED, HTTP_200_OK, HTTP_204_NO_CONTENT, HTTP_400_BAD_REQUEST
|
from rest_framework.status import HTTP_200_OK, HTTP_201_CREATED, HTTP_204_NO_CONTENT, HTTP_400_BAD_REQUEST, HTTP_403_FORBIDDEN
|
||||||
from rest_framework.test import APITestCase
|
from rest_framework.test import APITestCase
|
||||||
|
|
||||||
from helpdesk.models import Queue, Ticket, CustomField
|
from helpdesk.models import Queue, Ticket, CustomField
|
||||||
@ -21,13 +21,13 @@ class TicketTest(APITestCase):
|
|||||||
|
|
||||||
def test_create_api_ticket_not_authenticated_user(self):
|
def test_create_api_ticket_not_authenticated_user(self):
|
||||||
response = self.client.post('/api/tickets/')
|
response = self.client.post('/api/tickets/')
|
||||||
self.assertEqual(response.status_code, 403)
|
self.assertEqual(response.status_code, HTTP_403_FORBIDDEN)
|
||||||
|
|
||||||
def test_create_api_ticket_authenticated_non_staff_user(self):
|
def test_create_api_ticket_authenticated_non_staff_user(self):
|
||||||
non_staff_user = User.objects.create_user(username='test')
|
non_staff_user = User.objects.create_user(username='test')
|
||||||
self.client.force_authenticate(non_staff_user)
|
self.client.force_authenticate(non_staff_user)
|
||||||
response = self.client.post('/api/tickets/')
|
response = self.client.post('/api/tickets/')
|
||||||
self.assertEqual(response.status_code, 403)
|
self.assertEqual(response.status_code, HTTP_403_FORBIDDEN)
|
||||||
|
|
||||||
def test_create_api_ticket_no_data(self):
|
def test_create_api_ticket_no_data(self):
|
||||||
staff_user = User.objects.create_user(username='test', is_staff=True)
|
staff_user = User.objects.create_user(username='test', is_staff=True)
|
||||||
|
@ -603,13 +603,16 @@ class EmailInteractionsTestCase(TestCase):
|
|||||||
# As we have created a Ticket from an email, we notify the sender
|
# As we have created a Ticket from an email, we notify the sender
|
||||||
# and contacts on the cc_list (+1 as it's treated as a list),
|
# and contacts on the cc_list (+1 as it's treated as a list),
|
||||||
# the new and update queues (+2)
|
# the new and update queues (+2)
|
||||||
|
# then each cc gets its own email? (+2)
|
||||||
|
# TODO: check this is correct!
|
||||||
|
|
||||||
# Ensure that the submitter is notified
|
# Ensure that the submitter is notified
|
||||||
self.assertIn(submitter_email, mail.outbox[0].to)
|
self.assertIn(submitter_email, mail.outbox[0].to)
|
||||||
|
|
||||||
# As we have created an Ticket from an email, we notify the sender (+1)
|
# As we have created an Ticket from an email, we notify the sender (+1)
|
||||||
# and the new and update queues (+2)
|
# and the new and update queues (+2)
|
||||||
expected_email_count = 1 + 2
|
# then each cc gets its own email? (+2)
|
||||||
|
expected_email_count = 1 + 2 + 2
|
||||||
self.assertEqual(expected_email_count, len(mail.outbox))
|
self.assertEqual(expected_email_count, len(mail.outbox))
|
||||||
# end of the Ticket and TicketCCs creation #
|
# end of the Ticket and TicketCCs creation #
|
||||||
|
|
||||||
@ -637,7 +640,8 @@ class EmailInteractionsTestCase(TestCase):
|
|||||||
|
|
||||||
# As an update was made, we increase the expected_email_count with:
|
# As an update was made, we increase the expected_email_count with:
|
||||||
# public_update_queue: +1
|
# public_update_queue: +1
|
||||||
expected_email_count += 1
|
# since the submitter and the two ccs each get an email
|
||||||
|
expected_email_count += 1 + 3
|
||||||
self.assertEqual(expected_email_count, len(mail.outbox))
|
self.assertEqual(expected_email_count, len(mail.outbox))
|
||||||
|
|
||||||
# As we have created a FollowUp from an email, we notify the sender
|
# As we have created a FollowUp from an email, we notify the sender
|
||||||
|
@ -19,7 +19,9 @@ def validate_file_extension(value):
|
|||||||
if hasattr(settings, 'VALID_EXTENSIONS'):
|
if hasattr(settings, 'VALID_EXTENSIONS'):
|
||||||
valid_extensions = settings.VALID_EXTENSIONS
|
valid_extensions = settings.VALID_EXTENSIONS
|
||||||
else:
|
else:
|
||||||
valid_extensions = ['.txt', '.pdf', '.doc', '.docx', '.odt', '.jpg', '.png', '.eml']
|
valid_extensions = ['.txt', '.asc', '.htm', '.html', '.pdf', '.doc', '.docx', '.odt', '.jpg', '.png', '.eml']
|
||||||
|
|
||||||
if not ext.lower() in valid_extensions:
|
if not ext.lower() in valid_extensions:
|
||||||
raise ValidationError('Unsupported file extension.')
|
# TODO: one more check in case it is a file with no extension; we should always allow that?
|
||||||
|
if not (ext.lower() == '' or ext.lower() == '.'):
|
||||||
|
raise ValidationError('Unsupported file extension: %s.' % ext.lower())
|
||||||
|
@ -40,6 +40,7 @@ class QuickDjangoTest(object):
|
|||||||
#'account',
|
#'account',
|
||||||
#'pinax.invitations',
|
#'pinax.invitations',
|
||||||
#'pinax.teams',
|
#'pinax.teams',
|
||||||
|
'rest_framework',
|
||||||
'helpdesk',
|
'helpdesk',
|
||||||
#'reversion',
|
#'reversion',
|
||||||
)
|
)
|
||||||
@ -104,7 +105,9 @@ class QuickDjangoTest(object):
|
|||||||
## The following settings disable teams
|
## The following settings disable teams
|
||||||
HELPDESK_TEAMS_MODEL = 'auth.User',
|
HELPDESK_TEAMS_MODEL = 'auth.User',
|
||||||
HELPDESK_TEAMS_MIGRATION_DEPENDENCIES = [],
|
HELPDESK_TEAMS_MIGRATION_DEPENDENCIES = [],
|
||||||
HELPDESK_KBITEM_TEAM_GETTER = lambda _: None
|
HELPDESK_KBITEM_TEAM_GETTER = lambda _: None,
|
||||||
|
## test the API
|
||||||
|
HELPDESK_ACTIVATE_API_ENDPOINT=True
|
||||||
)
|
)
|
||||||
|
|
||||||
from django.test.runner import DiscoverRunner
|
from django.test.runner import DiscoverRunner
|
||||||
|
Loading…
Reference in New Issue
Block a user