forked from extern/django-helpdesk
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 rest_framework import HTTP_HEADER_ENCODING
|
||||
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 helpdesk.models import Queue, Ticket, CustomField
|
||||
@ -21,13 +21,13 @@ class TicketTest(APITestCase):
|
||||
|
||||
def test_create_api_ticket_not_authenticated_user(self):
|
||||
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):
|
||||
non_staff_user = User.objects.create_user(username='test')
|
||||
self.client.force_authenticate(non_staff_user)
|
||||
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):
|
||||
staff_user = User.objects.create_user(username='test', is_staff=True)
|
||||
|
@ -52,7 +52,7 @@ class GetEmailCommonTests(TestCase):
|
||||
"""
|
||||
with open(os.path.join(THIS_DIR, "test_files/blank-body-with-attachment.eml")) as fd:
|
||||
test_email = fd.read()
|
||||
ticket = helpdesk.email.object_from_message(test_email, self.queue_public, self.logger)
|
||||
ticket = helpdesk.email.object_from_message(test_email, self.queue_public, self.logger)
|
||||
|
||||
# title got truncated because of max_lengh of the model.title field
|
||||
assert ticket.title == (
|
||||
@ -68,7 +68,7 @@ class GetEmailCommonTests(TestCase):
|
||||
"""
|
||||
with open(os.path.join(THIS_DIR, "test_files/quoted_printable.eml")) as fd:
|
||||
test_email = fd.read()
|
||||
ticket = helpdesk.email.object_from_message(test_email, self.queue_public, self.logger)
|
||||
ticket = helpdesk.email.object_from_message(test_email, self.queue_public, self.logger)
|
||||
self.assertEqual(ticket.title, "Český test")
|
||||
self.assertEqual(ticket.description, "Tohle je test českých písmen odeslaných z gmailu.")
|
||||
followups = FollowUp.objects.filter(ticket=ticket)
|
||||
@ -86,7 +86,7 @@ class GetEmailCommonTests(TestCase):
|
||||
"""
|
||||
with open(os.path.join(THIS_DIR, "test_files/all-special-chars.eml")) as fd:
|
||||
test_email = fd.read()
|
||||
ticket = helpdesk.email.object_from_message(test_email, self.queue_public, self.logger)
|
||||
ticket = helpdesk.email.object_from_message(test_email, self.queue_public, self.logger)
|
||||
self.assertEqual(ticket.title, "Testovácí email")
|
||||
self.assertEqual(ticket.description, "íářčšáíéřášč")
|
||||
|
||||
|
@ -603,13 +603,16 @@ class EmailInteractionsTestCase(TestCase):
|
||||
# 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),
|
||||
# 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
|
||||
self.assertIn(submitter_email, mail.outbox[0].to)
|
||||
|
||||
# As we have created an Ticket from an email, we notify the sender (+1)
|
||||
# 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))
|
||||
# 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:
|
||||
# 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))
|
||||
|
||||
# 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'):
|
||||
valid_extensions = settings.VALID_EXTENSIONS
|
||||
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:
|
||||
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',
|
||||
#'pinax.invitations',
|
||||
#'pinax.teams',
|
||||
'rest_framework',
|
||||
'helpdesk',
|
||||
#'reversion',
|
||||
)
|
||||
@ -104,7 +105,9 @@ class QuickDjangoTest(object):
|
||||
## The following settings disable teams
|
||||
HELPDESK_TEAMS_MODEL = 'auth.User',
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user