2016-02-07 18:49:48 +01:00
|
|
|
|
|
|
|
|
2020-03-03 22:39:02 +01:00
|
|
|
from django.contrib.auth import get_user_model
|
2012-08-07 16:04:34 +02:00
|
|
|
from django.core import mail
|
2022-07-22 03:26:41 +02:00
|
|
|
from django.test import TestCase
|
2012-08-07 16:04:34 +02:00
|
|
|
from django.test.client import Client
|
2017-12-28 15:11:34 +01:00
|
|
|
from django.urls import reverse
|
2022-07-22 03:26:41 +02:00
|
|
|
import email
|
2023-07-18 00:33:56 +02:00
|
|
|
from helpdesk.email import object_from_message
|
2022-07-22 03:26:41 +02:00
|
|
|
from helpdesk.models import CustomField, FollowUp, KBCategory, KBItem, Queue, Ticket, TicketCC
|
2018-12-28 16:53:28 +01:00
|
|
|
import logging
|
2022-07-22 03:26:41 +02:00
|
|
|
from urllib.parse import urlparse
|
|
|
|
import uuid
|
2018-12-28 16:53:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger('helpdesk')
|
2015-11-16 16:08:52 +01:00
|
|
|
|
|
|
|
|
2012-08-07 16:04:34 +02:00
|
|
|
class TicketBasicsTestCase(TestCase):
|
2015-01-14 16:00:35 +01:00
|
|
|
fixtures = ['emailtemplate.json']
|
|
|
|
|
2012-08-07 16:04:34 +02:00
|
|
|
def setUp(self):
|
2016-10-21 17:14:12 +02:00
|
|
|
self.queue_public = Queue.objects.create(
|
|
|
|
title='Queue 1',
|
|
|
|
slug='q1',
|
|
|
|
allow_public_submission=True,
|
|
|
|
new_ticket_cc='new.public@example.com',
|
|
|
|
updated_ticket_cc='update.public@example.com')
|
|
|
|
self.queue_private = Queue.objects.create(
|
|
|
|
title='Queue 2',
|
|
|
|
slug='q2',
|
|
|
|
allow_public_submission=False,
|
|
|
|
new_ticket_cc='new.private@example.com',
|
|
|
|
updated_ticket_cc='update.private@example.com')
|
2012-08-07 16:04:34 +02:00
|
|
|
|
|
|
|
self.ticket_data = {
|
2016-10-21 17:14:12 +02:00
|
|
|
'title': 'Test Ticket',
|
|
|
|
'description': 'Some Test Ticket',
|
|
|
|
}
|
2012-08-07 16:04:34 +02:00
|
|
|
|
2020-03-03 22:39:02 +01:00
|
|
|
self.user = get_user_model().objects.create(
|
|
|
|
username='User_1',
|
|
|
|
)
|
|
|
|
|
2012-08-07 16:04:34 +02:00
|
|
|
self.client = Client()
|
|
|
|
|
2016-02-15 19:15:46 +01:00
|
|
|
def test_create_ticket_instance_from_payload(self):
|
2016-02-07 19:54:05 +01:00
|
|
|
"""
|
|
|
|
Ensure that a <Ticket> instance is created whenever an email is sent to a public queue.
|
|
|
|
"""
|
|
|
|
|
2012-08-07 16:04:34 +02:00
|
|
|
email_count = len(mail.outbox)
|
|
|
|
ticket_data = dict(queue=self.queue_public, **self.ticket_data)
|
|
|
|
ticket = Ticket.objects.create(**ticket_data)
|
|
|
|
self.assertEqual(ticket.ticket_for_url, "q1-%s" % ticket.id)
|
|
|
|
self.assertEqual(email_count, len(mail.outbox))
|
|
|
|
|
|
|
|
def test_create_ticket_public(self):
|
|
|
|
email_count = len(mail.outbox)
|
|
|
|
|
2015-12-22 10:10:00 +01:00
|
|
|
response = self.client.get(reverse('helpdesk:home'))
|
2012-08-07 16:04:34 +02:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
post_data = {
|
2016-10-23 22:10:32 +02:00
|
|
|
'title': 'Test ticket title',
|
|
|
|
'queue': self.queue_public.id,
|
|
|
|
'submitter_email': 'ticket1.submitter@example.com',
|
|
|
|
'body': 'Test ticket body',
|
|
|
|
'priority': 3,
|
|
|
|
}
|
2012-08-07 16:04:34 +02:00
|
|
|
|
2022-07-12 12:34:19 +02:00
|
|
|
response = self.client.post(
|
|
|
|
reverse('helpdesk:home'), post_data, follow=True)
|
2012-08-07 16:04:34 +02:00
|
|
|
last_redirect = response.redirect_chain[-1]
|
|
|
|
last_redirect_url = last_redirect[0]
|
2016-10-21 17:14:12 +02:00
|
|
|
# last_redirect_status = last_redirect[1]
|
2015-11-16 16:08:52 +01:00
|
|
|
|
2012-08-07 16:04:34 +02:00
|
|
|
# Ensure we landed on the "View" page.
|
2015-11-16 16:08:52 +01:00
|
|
|
# Django 1.9 compatible way of testing this
|
|
|
|
# https://docs.djangoproject.com/en/1.9/releases/1.9/#http-redirects-no-longer-forced-to-absolute-uris
|
|
|
|
urlparts = urlparse(last_redirect_url)
|
2015-12-22 10:10:00 +01:00
|
|
|
self.assertEqual(urlparts.path, reverse('helpdesk:public_view'))
|
2015-11-16 16:08:52 +01:00
|
|
|
|
2012-08-07 16:04:34 +02:00
|
|
|
# Ensure submitter, new-queue + update-queue were all emailed.
|
2016-10-23 22:10:32 +02:00
|
|
|
self.assertEqual(email_count + 3, len(mail.outbox))
|
2015-11-16 16:08:52 +01:00
|
|
|
|
2020-03-03 22:39:02 +01:00
|
|
|
ticket = Ticket.objects.last()
|
|
|
|
self.assertEqual(ticket.followup_set.count(), 1)
|
|
|
|
# Follow up is anonymous
|
|
|
|
self.assertIsNone(ticket.followup_set.first().user)
|
|
|
|
|
2021-08-19 22:00:06 +02:00
|
|
|
def test_create_ticket_public_with_hidden_fields(self):
|
|
|
|
email_count = len(mail.outbox)
|
|
|
|
|
|
|
|
response = self.client.get(reverse('helpdesk:home'))
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
post_data = {
|
|
|
|
'title': 'Test ticket title',
|
|
|
|
'queue': self.queue_public.id,
|
|
|
|
'submitter_email': 'ticket1.submitter@example.com',
|
|
|
|
'body': 'Test ticket body',
|
|
|
|
'priority': 4,
|
|
|
|
}
|
|
|
|
|
2022-07-12 12:34:19 +02:00
|
|
|
response = self.client.post(
|
|
|
|
reverse('helpdesk:home') + "?_hide_fields_=priority", post_data, follow=True)
|
2021-08-19 22:00:06 +02:00
|
|
|
ticket = Ticket.objects.last()
|
|
|
|
self.assertEqual(ticket.priority, 4)
|
|
|
|
|
2020-03-03 22:39:02 +01:00
|
|
|
def test_create_ticket_authorized(self):
|
|
|
|
email_count = len(mail.outbox)
|
|
|
|
self.client.force_login(self.user)
|
|
|
|
|
|
|
|
response = self.client.get(reverse('helpdesk:home'))
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
post_data = {
|
|
|
|
'title': 'Test ticket title',
|
|
|
|
'queue': self.queue_public.id,
|
|
|
|
'submitter_email': 'ticket1.submitter@example.com',
|
|
|
|
'body': 'Test ticket body',
|
|
|
|
'priority': 3,
|
|
|
|
}
|
|
|
|
|
2022-07-12 12:34:19 +02:00
|
|
|
response = self.client.post(
|
|
|
|
reverse('helpdesk:home'), post_data, follow=True)
|
2020-03-03 22:39:02 +01:00
|
|
|
last_redirect = response.redirect_chain[-1]
|
|
|
|
last_redirect_url = last_redirect[0]
|
|
|
|
# last_redirect_status = last_redirect[1]
|
|
|
|
|
|
|
|
# Ensure we landed on the "View" page.
|
|
|
|
# Django 1.9 compatible way of testing this
|
|
|
|
# https://docs.djangoproject.com/en/1.9/releases/1.9/#http-redirects-no-longer-forced-to-absolute-uris
|
|
|
|
urlparts = urlparse(last_redirect_url)
|
|
|
|
self.assertEqual(urlparts.path, reverse('helpdesk:public_view'))
|
|
|
|
|
|
|
|
# Ensure submitter, new-queue + update-queue were all emailed.
|
|
|
|
self.assertEqual(email_count + 3, len(mail.outbox))
|
|
|
|
|
|
|
|
ticket = Ticket.objects.last()
|
|
|
|
self.assertEqual(ticket.followup_set.count(), 1)
|
|
|
|
# Follow up is for registered user
|
|
|
|
self.assertEqual(ticket.followup_set.first().user, self.user)
|
|
|
|
|
2012-08-07 16:04:34 +02:00
|
|
|
def test_create_ticket_private(self):
|
|
|
|
email_count = len(mail.outbox)
|
|
|
|
post_data = {
|
2016-10-21 17:14:12 +02:00
|
|
|
'title': 'Private ticket test',
|
|
|
|
'queue': self.queue_private.id,
|
|
|
|
'submitter_email': 'ticket2.submitter@example.com',
|
|
|
|
'body': 'Test ticket body',
|
|
|
|
'priority': 3,
|
|
|
|
}
|
2012-08-07 16:04:34 +02:00
|
|
|
|
2015-12-22 10:10:00 +01:00
|
|
|
response = self.client.post(reverse('helpdesk:home'), post_data)
|
2012-08-07 16:04:34 +02:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertEqual(email_count, len(mail.outbox))
|
|
|
|
self.assertContains(response, 'Select a valid choice.')
|
|
|
|
|
|
|
|
def test_create_ticket_customfields(self):
|
|
|
|
email_count = len(mail.outbox)
|
2016-10-21 17:14:12 +02:00
|
|
|
queue_custom = Queue.objects.create(
|
|
|
|
title='Queue 3',
|
|
|
|
slug='q3',
|
|
|
|
allow_public_submission=True,
|
|
|
|
updated_ticket_cc='update.custom@example.com')
|
|
|
|
custom_field_1 = CustomField.objects.create(
|
|
|
|
name='textfield',
|
|
|
|
label='Text Field',
|
|
|
|
data_type='varchar',
|
|
|
|
max_length=100,
|
|
|
|
ordering=10,
|
|
|
|
required=False,
|
|
|
|
staff_only=False)
|
2012-08-07 16:04:34 +02:00
|
|
|
post_data = {
|
2016-10-21 17:14:12 +02:00
|
|
|
'queue': queue_custom.id,
|
|
|
|
'title': 'Ticket with custom text field',
|
|
|
|
'submitter_email': 'ticket3.submitter@example.com',
|
|
|
|
'body': 'Test ticket body',
|
|
|
|
'priority': 3,
|
|
|
|
'custom_textfield': 'This is my custom text.',
|
|
|
|
}
|
2012-08-07 16:04:34 +02:00
|
|
|
|
2022-07-12 12:34:19 +02:00
|
|
|
response = self.client.post(
|
|
|
|
reverse('helpdesk:home'), post_data, follow=True)
|
2012-08-07 16:04:34 +02:00
|
|
|
|
|
|
|
custom_field_1.delete()
|
|
|
|
last_redirect = response.redirect_chain[-1]
|
|
|
|
last_redirect_url = last_redirect[0]
|
2016-10-21 17:14:12 +02:00
|
|
|
# last_redirect_status = last_redirect[1]
|
2016-10-23 22:10:32 +02:00
|
|
|
|
2012-08-07 16:04:34 +02:00
|
|
|
# Ensure we landed on the "View" page.
|
2015-11-16 16:08:52 +01:00
|
|
|
# Django 1.9 compatible way of testing this
|
|
|
|
# https://docs.djangoproject.com/en/1.9/releases/1.9/#http-redirects-no-longer-forced-to-absolute-uris
|
|
|
|
urlparts = urlparse(last_redirect_url)
|
2015-12-22 10:10:00 +01:00
|
|
|
self.assertEqual(urlparts.path, reverse('helpdesk:public_view'))
|
2015-11-16 16:08:52 +01:00
|
|
|
|
2012-08-07 16:04:34 +02:00
|
|
|
# Ensure only two e-mails were sent - submitter & updated.
|
2016-10-23 22:10:32 +02:00
|
|
|
self.assertEqual(email_count + 2, len(mail.outbox))
|
2016-02-28 19:00:15 +01:00
|
|
|
|
2020-01-17 18:11:52 +01:00
|
|
|
def test_create_ticket_public_no_loopback(self):
|
|
|
|
"""
|
|
|
|
Don't send emails to the queue's own inbox. It'll create a loop.
|
|
|
|
"""
|
|
|
|
email_count = len(mail.outbox)
|
|
|
|
|
|
|
|
self.queue_public.email_address = "queue@example.com"
|
|
|
|
self.queue_public.save()
|
|
|
|
|
|
|
|
post_data = {
|
|
|
|
'title': 'Test ticket title',
|
|
|
|
'queue': self.queue_public.id,
|
|
|
|
'submitter_email': 'queue@example.com',
|
|
|
|
'body': 'Test ticket body',
|
|
|
|
'priority': 3,
|
|
|
|
}
|
|
|
|
|
2022-07-12 12:34:19 +02:00
|
|
|
response = self.client.post(
|
|
|
|
reverse('helpdesk:home'), post_data, follow=True)
|
2020-01-17 18:11:52 +01:00
|
|
|
last_redirect = response.redirect_chain[-1]
|
|
|
|
last_redirect_url = last_redirect[0]
|
|
|
|
# last_redirect_status = last_redirect[1]
|
|
|
|
|
|
|
|
# Ensure we landed on the "View" page.
|
|
|
|
# Django 1.9 compatible way of testing this
|
|
|
|
# https://docs.djangoproject.com/en/1.9/releases/1.9/#http-redirects-no-longer-forced-to-absolute-uris
|
|
|
|
urlparts = urlparse(last_redirect_url)
|
|
|
|
self.assertEqual(urlparts.path, reverse('helpdesk:public_view'))
|
|
|
|
|
|
|
|
# Ensure submitter, new-queue + update-queue were all emailed.
|
|
|
|
self.assertEqual(email_count + 2, len(mail.outbox))
|
|
|
|
|
2018-12-28 17:32:49 +01:00
|
|
|
|
2016-02-28 19:19:08 +01:00
|
|
|
class EmailInteractionsTestCase(TestCase):
|
2016-02-28 19:00:15 +01:00
|
|
|
fixtures = ['emailtemplate.json']
|
|
|
|
|
|
|
|
def setUp(self):
|
2018-12-28 17:32:49 +01:00
|
|
|
self.queue_public = Queue.objects.create(
|
|
|
|
title='Mail Queue 1',
|
|
|
|
slug='mq1',
|
|
|
|
email_address='queue-1@example.com',
|
|
|
|
allow_public_submission=True,
|
|
|
|
new_ticket_cc='new.public.with.notifications@example.com',
|
|
|
|
updated_ticket_cc='update.public.with.notifications@example.com',
|
|
|
|
enable_notifications_on_email_events=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
self.queue_public_with_notifications_disabled = Queue.objects.create(
|
|
|
|
title='Mail Queue 2',
|
|
|
|
slug='mq2',
|
|
|
|
email_address='queue-2@example.com',
|
|
|
|
allow_public_submission=True,
|
|
|
|
new_ticket_cc='new.public.without.notifications@example.com',
|
|
|
|
updated_ticket_cc='update.public.without.notifications@example.com',
|
|
|
|
enable_notifications_on_email_events=False,
|
|
|
|
)
|
2016-02-28 19:00:15 +01:00
|
|
|
|
|
|
|
self.ticket_data = {
|
2018-12-28 17:32:49 +01:00
|
|
|
'title': 'Test Ticket',
|
|
|
|
'description': 'Some Test Ticket',
|
|
|
|
}
|
2016-02-28 19:00:15 +01:00
|
|
|
|
|
|
|
def test_create_ticket_from_email_with_message_id(self):
|
|
|
|
"""
|
|
|
|
Ensure that a <Ticket> instance is created whenever an email is sent to a public queue.
|
|
|
|
Also, make sure that the RFC 2822 field "message-id" is stored on the <Ticket.submitter_email_id>
|
|
|
|
field.
|
|
|
|
"""
|
|
|
|
|
|
|
|
msg = email.message.Message()
|
|
|
|
|
|
|
|
message_id = uuid.uuid4().hex
|
|
|
|
submitter_email = 'foo@bar.py'
|
2018-12-28 17:32:49 +01:00
|
|
|
|
2016-02-28 19:00:15 +01:00
|
|
|
msg.__setitem__('Message-ID', message_id)
|
|
|
|
msg.__setitem__('Subject', self.ticket_data['title'])
|
2018-12-28 17:32:49 +01:00
|
|
|
msg.__setitem__('From', submitter_email)
|
2016-02-28 19:00:15 +01:00
|
|
|
msg.__setitem__('To', self.queue_public.email_address)
|
|
|
|
msg.__setitem__('Content-Type', 'text/plain;')
|
|
|
|
msg.set_payload(self.ticket_data['description'])
|
|
|
|
|
|
|
|
email_count = len(mail.outbox)
|
|
|
|
|
2018-12-28 16:53:28 +01:00
|
|
|
object_from_message(str(msg), self.queue_public, logger=logger)
|
2016-02-28 19:00:15 +01:00
|
|
|
|
|
|
|
followup = FollowUp.objects.get(message_id=message_id)
|
|
|
|
ticket = Ticket.objects.get(id=followup.ticket.id)
|
|
|
|
|
2016-02-28 19:19:08 +01:00
|
|
|
self.assertEqual(ticket.ticket_for_url, "mq1-%s" % ticket.id)
|
2016-02-28 19:00:15 +01:00
|
|
|
|
2018-12-28 17:32:49 +01:00
|
|
|
# As we have created an Ticket from an email, we notify the sender (+1)
|
2016-02-28 19:00:15 +01:00
|
|
|
# and the new and update queues (+2)
|
|
|
|
self.assertEqual(email_count + 1 + 2, len(mail.outbox))
|
|
|
|
|
2016-03-17 05:12:42 +01:00
|
|
|
# Ensure that the submitter is notified
|
2018-12-28 17:32:49 +01:00
|
|
|
self.assertIn(submitter_email, mail.outbox[0].to)
|
2016-03-17 05:12:42 +01:00
|
|
|
|
2016-02-28 19:00:15 +01:00
|
|
|
def test_create_ticket_from_email_without_message_id(self):
|
|
|
|
"""
|
|
|
|
Ensure that a <Ticket> instance is created whenever an email is sent to a public queue.
|
|
|
|
Also, make sure that the RFC 2822 field "message-id" is stored on the <Ticket.submitter_email_id>
|
|
|
|
field.
|
|
|
|
"""
|
|
|
|
|
|
|
|
msg = email.message.Message()
|
|
|
|
submitter_email = 'foo@bar.py'
|
|
|
|
|
|
|
|
msg.__setitem__('Subject', self.ticket_data['title'])
|
2018-12-28 17:32:49 +01:00
|
|
|
msg.__setitem__('From', submitter_email)
|
2016-02-28 19:00:15 +01:00
|
|
|
msg.__setitem__('To', self.queue_public.email_address)
|
|
|
|
msg.__setitem__('Content-Type', 'text/plain;')
|
|
|
|
msg.set_payload(self.ticket_data['description'])
|
|
|
|
|
|
|
|
email_count = len(mail.outbox)
|
|
|
|
|
2018-12-28 16:53:28 +01:00
|
|
|
object_from_message(str(msg), self.queue_public, logger=logger)
|
2016-02-28 19:00:15 +01:00
|
|
|
|
2022-07-12 12:34:19 +02:00
|
|
|
ticket = Ticket.objects.get(
|
|
|
|
title=self.ticket_data['title'], queue=self.queue_public, submitter_email=submitter_email)
|
2016-02-28 19:00:15 +01:00
|
|
|
|
2016-02-28 19:19:08 +01:00
|
|
|
self.assertEqual(ticket.ticket_for_url, "mq1-%s" % ticket.id)
|
2016-02-28 19:00:15 +01:00
|
|
|
|
2018-12-28 17:32:49 +01:00
|
|
|
# As we have created an Ticket from an email, we notify the sender (+1)
|
2016-02-28 19:00:15 +01:00
|
|
|
# and the new and update queues (+2)
|
|
|
|
self.assertEqual(email_count + 1 + 2, len(mail.outbox))
|
|
|
|
|
2016-03-17 05:12:42 +01:00
|
|
|
# Ensure that the submitter is notified
|
2018-12-28 17:32:49 +01:00
|
|
|
self.assertIn(submitter_email, mail.outbox[0].to)
|
2016-03-17 05:12:42 +01:00
|
|
|
|
2016-02-28 19:00:15 +01:00
|
|
|
def test_create_ticket_from_email_with_carbon_copy(self):
|
2018-12-28 17:32:49 +01:00
|
|
|
"""
|
2016-02-28 19:00:15 +01:00
|
|
|
Ensure that an instance of <TicketCC> is created for every valid element of the
|
|
|
|
"rfc_2822_cc" field when creating a <Ticket> instance.
|
|
|
|
"""
|
|
|
|
|
|
|
|
msg = email.message.Message()
|
|
|
|
|
|
|
|
message_id = uuid.uuid4().hex
|
|
|
|
submitter_email = 'foo@bar.py'
|
|
|
|
cc_list = ['bravo@example.net', 'charlie@foobar.com']
|
|
|
|
|
|
|
|
msg.__setitem__('Message-ID', message_id)
|
|
|
|
msg.__setitem__('Subject', self.ticket_data['title'])
|
|
|
|
msg.__setitem__('From', submitter_email)
|
|
|
|
msg.__setitem__('To', self.queue_public.email_address)
|
|
|
|
msg.__setitem__('Cc', ','.join(cc_list))
|
|
|
|
msg.__setitem__('Content-Type', 'text/plain;')
|
|
|
|
msg.set_payload(self.ticket_data['description'])
|
|
|
|
|
|
|
|
email_count = len(mail.outbox)
|
2018-12-28 17:32:49 +01:00
|
|
|
|
2018-12-28 16:53:28 +01:00
|
|
|
object_from_message(str(msg), self.queue_public, logger=logger)
|
2016-02-28 19:00:15 +01:00
|
|
|
|
|
|
|
followup = FollowUp.objects.get(message_id=message_id)
|
|
|
|
ticket = Ticket.objects.get(id=followup.ticket.id)
|
2016-02-28 19:19:08 +01:00
|
|
|
self.assertEqual(ticket.ticket_for_url, "mq1-%s" % ticket.id)
|
2016-02-28 19:00:15 +01:00
|
|
|
|
2018-12-28 16:53:28 +01:00
|
|
|
# As we have created an Ticket from an email, we notify:
|
|
|
|
# the sender (+1),
|
|
|
|
# contacts on the cc_list (+2),
|
2018-12-28 17:32:49 +01:00
|
|
|
# the new and update queues (+2)
|
2018-12-28 16:53:28 +01:00
|
|
|
self.assertEqual(email_count + 1 + 2 + 2, len(mail.outbox))
|
2016-02-28 19:00:15 +01:00
|
|
|
|
2016-03-17 05:12:42 +01:00
|
|
|
# Ensure that the submitter is notified
|
2018-12-28 17:32:49 +01:00
|
|
|
self.assertIn(submitter_email, mail.outbox[0].to)
|
2016-03-17 05:12:42 +01:00
|
|
|
|
2016-03-23 17:16:49 +01:00
|
|
|
for cc_email in cc_list:
|
|
|
|
|
|
|
|
# Ensure that contacts on cc_list will be notified on the same email (index 0)
|
2018-12-28 17:32:49 +01:00
|
|
|
# self.assertIn(cc_email, mail.outbox[0].to)
|
2016-03-23 17:16:49 +01:00
|
|
|
|
|
|
|
# Ensure that <TicketCC> exists
|
|
|
|
ticket_cc = TicketCC.objects.get(ticket=ticket, email=cc_email)
|
|
|
|
self.assertTrue(ticket_cc.ticket, ticket)
|
|
|
|
self.assertTrue(ticket_cc.email, cc_email)
|
|
|
|
|
|
|
|
def test_create_ticket_from_email_to_multiple_emails(self):
|
2018-12-28 17:32:49 +01:00
|
|
|
"""
|
2016-03-23 17:16:49 +01:00
|
|
|
Ensure that an instance of <TicketCC> is created for every valid element of the
|
|
|
|
"rfc_2822_cc" field when creating a <Ticket> instance.
|
|
|
|
"""
|
|
|
|
|
|
|
|
msg = email.message.Message()
|
|
|
|
|
|
|
|
message_id = uuid.uuid4().hex
|
|
|
|
submitter_email = 'foo@bar.py'
|
|
|
|
to_list = [self.queue_public.email_address]
|
|
|
|
cc_list = ['bravo@example.net', 'charlie@foobar.com']
|
|
|
|
|
|
|
|
msg.__setitem__('Message-ID', message_id)
|
|
|
|
msg.__setitem__('Subject', self.ticket_data['title'])
|
|
|
|
msg.__setitem__('From', submitter_email)
|
|
|
|
msg.__setitem__('To', ','.join(to_list + cc_list))
|
|
|
|
msg.__setitem__('Content-Type', 'text/plain;')
|
|
|
|
msg.set_payload(self.ticket_data['description'])
|
|
|
|
|
|
|
|
email_count = len(mail.outbox)
|
2018-12-28 17:32:49 +01:00
|
|
|
|
2018-12-28 16:53:28 +01:00
|
|
|
object_from_message(str(msg), self.queue_public, logger=logger)
|
2016-03-23 17:16:49 +01:00
|
|
|
|
|
|
|
followup = FollowUp.objects.get(message_id=message_id)
|
|
|
|
ticket = Ticket.objects.get(id=followup.ticket.id)
|
|
|
|
self.assertEqual(ticket.ticket_for_url, "mq1-%s" % ticket.id)
|
|
|
|
|
2018-12-28 16:53:28 +01:00
|
|
|
# As we have created an Ticket from an email, we notify:
|
|
|
|
# the sender (+1),
|
|
|
|
# contacts on the cc_list (+2),
|
2018-12-28 17:32:49 +01:00
|
|
|
# the new and update queues (+2)
|
2018-12-28 16:53:28 +01:00
|
|
|
self.assertEqual(email_count + 1 + 2 + 2, len(mail.outbox))
|
2016-03-23 17:16:49 +01:00
|
|
|
|
|
|
|
# Ensure that the submitter is notified
|
2018-12-28 17:32:49 +01:00
|
|
|
self.assertIn(submitter_email, mail.outbox[0].to)
|
2016-03-23 17:16:49 +01:00
|
|
|
|
2022-07-12 12:34:19 +02:00
|
|
|
# Ensure that the queue's email was not subscribed to the event
|
|
|
|
# notifications.
|
|
|
|
self.assertRaises(TicketCC.DoesNotExist,
|
|
|
|
TicketCC.objects.get, ticket=ticket, email=to_list[0])
|
2018-12-28 17:32:49 +01:00
|
|
|
|
2016-02-28 19:00:15 +01:00
|
|
|
for cc_email in cc_list:
|
2016-03-17 05:12:42 +01:00
|
|
|
|
|
|
|
# Ensure that contacts on cc_list will be notified on the same email (index 0)
|
2018-12-28 17:32:49 +01:00
|
|
|
# self.assertIn(cc_email, mail.outbox[0].to)
|
2016-03-17 05:12:42 +01:00
|
|
|
|
|
|
|
# Ensure that <TicketCC> exists
|
2016-02-28 19:00:15 +01:00
|
|
|
ticket_cc = TicketCC.objects.get(ticket=ticket, email=cc_email)
|
|
|
|
self.assertTrue(ticket_cc.ticket, ticket)
|
|
|
|
self.assertTrue(ticket_cc.email, cc_email)
|
|
|
|
|
|
|
|
def test_create_ticket_from_email_with_invalid_carbon_copy(self):
|
2018-12-28 17:32:49 +01:00
|
|
|
"""
|
2016-02-28 19:00:15 +01:00
|
|
|
Ensure that no <TicketCC> instance is created if an invalid element of the
|
|
|
|
"rfc_2822_cc" field is provided when creating a <Ticket> instance.
|
|
|
|
"""
|
|
|
|
|
|
|
|
msg = email.message.Message()
|
|
|
|
|
|
|
|
message_id = uuid.uuid4().hex
|
|
|
|
submitter_email = 'foo@bar.py'
|
|
|
|
cc_list = ['null@example', 'invalid@foobar']
|
|
|
|
|
|
|
|
msg.__setitem__('Message-ID', message_id)
|
|
|
|
msg.__setitem__('Subject', self.ticket_data['title'])
|
|
|
|
msg.__setitem__('From', submitter_email)
|
|
|
|
msg.__setitem__('To', self.queue_public.email_address)
|
|
|
|
msg.__setitem__('Cc', ','.join(cc_list))
|
|
|
|
msg.__setitem__('Content-Type', 'text/plain;')
|
|
|
|
msg.set_payload(self.ticket_data['description'])
|
|
|
|
|
|
|
|
email_count = len(mail.outbox)
|
|
|
|
|
2018-12-28 16:53:28 +01:00
|
|
|
object_from_message(str(msg), self.queue_public, logger=logger)
|
2016-02-28 19:00:15 +01:00
|
|
|
|
2016-03-17 05:12:42 +01:00
|
|
|
followup = FollowUp.objects.get(message_id=message_id)
|
|
|
|
ticket = Ticket.objects.get(id=followup.ticket.id)
|
|
|
|
self.assertEqual(ticket.ticket_for_url, "mq1-%s" % ticket.id)
|
|
|
|
|
2018-12-28 16:53:28 +01:00
|
|
|
# As we have created an Ticket from an email, we notify:
|
|
|
|
# the submitter (+1)
|
|
|
|
# contacts on the cc_list (+2),
|
2018-12-28 17:32:49 +01:00
|
|
|
# the new and update queues (+2)
|
2018-12-28 16:53:28 +01:00
|
|
|
self.assertEqual(email_count + 1 + 2 + 2, len(mail.outbox))
|
2016-03-17 05:12:42 +01:00
|
|
|
|
|
|
|
# Ensure that the submitter is notified
|
|
|
|
self.assertIn(submitter_email, mail.outbox[0].to)
|
2018-12-28 17:32:49 +01:00
|
|
|
|
2016-03-17 05:12:42 +01:00
|
|
|
for cc_email in cc_list:
|
|
|
|
|
|
|
|
# Ensure that contacts on cc_list will be notified on the same email (index 0)
|
2018-12-28 17:32:49 +01:00
|
|
|
# self.assertIn(cc_email, mail.outbox[0].to)
|
2016-03-17 05:12:42 +01:00
|
|
|
|
|
|
|
# Ensure that <TicketCC> exists. Even if it's an invalid email.
|
|
|
|
ticket_cc = TicketCC.objects.get(ticket=ticket, email=cc_email)
|
|
|
|
self.assertTrue(ticket_cc.ticket, ticket)
|
|
|
|
self.assertTrue(ticket_cc.email, cc_email)
|
|
|
|
|
|
|
|
def test_create_followup_from_email_with_valid_message_id_with_no_initial_cc_list(self):
|
2016-02-28 19:00:15 +01:00
|
|
|
"""
|
2018-12-28 17:32:49 +01:00
|
|
|
Ensure that if a message is received with an valid In-Reply-To ID,
|
2016-02-28 19:00:15 +01:00
|
|
|
the expected <TicketCC> instances are created even if the there were
|
|
|
|
no <TicketCC>s so far.
|
|
|
|
"""
|
2018-12-28 17:32:49 +01:00
|
|
|
# Ticket and TicketCCs creation #
|
2016-02-28 19:00:15 +01:00
|
|
|
msg = email.message.Message()
|
|
|
|
|
|
|
|
message_id = uuid.uuid4().hex
|
|
|
|
submitter_email = 'foo@bar.py'
|
|
|
|
|
|
|
|
msg.__setitem__('Message-ID', message_id)
|
|
|
|
msg.__setitem__('Subject', self.ticket_data['title'])
|
|
|
|
msg.__setitem__('From', submitter_email)
|
|
|
|
msg.__setitem__('To', self.queue_public.email_address)
|
|
|
|
msg.__setitem__('Content-Type', 'text/plain;')
|
|
|
|
msg.set_payload(self.ticket_data['description'])
|
|
|
|
|
|
|
|
email_count = len(mail.outbox)
|
2018-12-28 17:32:49 +01:00
|
|
|
|
2018-12-28 16:53:28 +01:00
|
|
|
object_from_message(str(msg), self.queue_public, logger=logger)
|
2016-02-28 19:00:15 +01:00
|
|
|
|
|
|
|
followup = FollowUp.objects.get(message_id=message_id)
|
|
|
|
ticket = Ticket.objects.get(id=followup.ticket.id)
|
2016-03-17 05:12:42 +01:00
|
|
|
|
|
|
|
# As we have created an Ticket from an email, we notify the sender
|
|
|
|
# and contacts on the cc_list (+1 as it's treated as a list),
|
2018-12-28 17:32:49 +01:00
|
|
|
# the new and update queues (+2)
|
2016-03-17 05:12:42 +01:00
|
|
|
|
|
|
|
# Ensure that the submitter is notified
|
2018-12-28 17:32:49 +01:00
|
|
|
self.assertIn(submitter_email, mail.outbox[0].to)
|
2016-03-17 05:12:42 +01:00
|
|
|
|
|
|
|
# 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
|
|
|
|
self.assertEqual(expected_email_count, len(mail.outbox))
|
2018-12-28 17:32:49 +01:00
|
|
|
# end of the Ticket and TicketCCs creation #
|
2016-02-28 19:00:15 +01:00
|
|
|
|
|
|
|
# Reply message
|
|
|
|
reply = email.message.Message()
|
|
|
|
|
|
|
|
reply_message_id = uuid.uuid4().hex
|
|
|
|
submitter_email = 'foo@bar.py'
|
|
|
|
cc_list = ['bravo@example.net', 'charlie@foobar.com']
|
|
|
|
|
|
|
|
reply.__setitem__('Message-ID', reply_message_id)
|
|
|
|
reply.__setitem__('In-Reply-To', message_id)
|
|
|
|
reply.__setitem__('Subject', self.ticket_data['title'])
|
|
|
|
reply.__setitem__('From', submitter_email)
|
|
|
|
reply.__setitem__('To', self.queue_public.email_address)
|
|
|
|
reply.__setitem__('Cc', ','.join(cc_list))
|
|
|
|
reply.__setitem__('Content-Type', 'text/plain;')
|
|
|
|
reply.set_payload(self.ticket_data['description'])
|
|
|
|
|
2018-12-28 16:53:28 +01:00
|
|
|
object_from_message(str(reply), self.queue_public, logger=logger)
|
2016-02-28 19:00:15 +01:00
|
|
|
|
|
|
|
followup = FollowUp.objects.get(message_id=message_id)
|
|
|
|
ticket = Ticket.objects.get(id=followup.ticket.id)
|
2016-02-28 19:19:08 +01:00
|
|
|
self.assertEqual(ticket.ticket_for_url, "mq1-%s" % ticket.id)
|
2016-02-28 19:00:15 +01:00
|
|
|
|
|
|
|
# Ensure that <TicketCC> is created
|
|
|
|
for cc_email in cc_list:
|
2018-12-28 17:32:49 +01:00
|
|
|
# Even after 2 messages with the same cc_list, <get> MUST return only
|
|
|
|
# one object
|
2016-02-28 19:00:15 +01:00
|
|
|
ticket_cc = TicketCC.objects.get(ticket=ticket, email=cc_email)
|
|
|
|
self.assertTrue(ticket_cc.ticket, ticket)
|
|
|
|
self.assertTrue(ticket_cc.email, cc_email)
|
|
|
|
|
|
|
|
# As an update was made, we increase the expected_email_count with:
|
2018-12-28 16:53:28 +01:00
|
|
|
# submitter: +1
|
|
|
|
# cc_list: +2
|
2016-02-28 19:00:15 +01:00
|
|
|
# public_update_queue: +1
|
2018-12-28 16:53:28 +01:00
|
|
|
expected_email_count += 1 + 2 + 1
|
2016-02-28 19:00:15 +01:00
|
|
|
self.assertEqual(expected_email_count, len(mail.outbox))
|
|
|
|
|
2018-12-28 16:53:28 +01:00
|
|
|
# As we have created a FollowUp from an email, we notify:
|
|
|
|
# the sender (+1),
|
|
|
|
# contacts on the cc_list (+2),
|
2018-12-28 17:32:49 +01:00
|
|
|
# the new and update queues (+2)
|
2016-03-17 05:12:42 +01:00
|
|
|
|
|
|
|
# Ensure that the submitter is notified
|
2018-12-28 17:32:49 +01:00
|
|
|
# self.assertIn(submitter_email, mail.outbox[expected_email_count - 3].to)
|
2016-03-17 05:12:42 +01:00
|
|
|
|
|
|
|
# Ensure that contacts on cc_list will be notified on the same email (index 0)
|
2018-12-28 17:32:49 +01:00
|
|
|
# for cc_email in cc_list:
|
|
|
|
# self.assertIn(cc_email, mail.outbox[expected_email_count - 1].to)
|
2016-03-17 05:12:42 +01:00
|
|
|
|
2016-02-28 19:00:15 +01:00
|
|
|
def test_create_followup_from_email_with_valid_message_id_with_original_cc_list_included(self):
|
|
|
|
"""
|
2018-12-28 17:32:49 +01:00
|
|
|
Ensure that if a message is received with an valid In-Reply-To ID,
|
|
|
|
the expected <TicketCC> instances are created but if there's any
|
2016-02-28 19:00:15 +01:00
|
|
|
overlap with the previous Cc list, no duplicates are created.
|
|
|
|
"""
|
2018-12-28 17:32:49 +01:00
|
|
|
# Ticket and TicketCCs creation #
|
2016-02-28 19:00:15 +01:00
|
|
|
msg = email.message.Message()
|
|
|
|
|
|
|
|
message_id = uuid.uuid4().hex
|
|
|
|
submitter_email = 'foo@bar.py'
|
|
|
|
cc_list = ['bravo@example.net', 'charlie@foobar.com']
|
|
|
|
|
|
|
|
msg.__setitem__('Message-ID', message_id)
|
|
|
|
msg.__setitem__('Subject', self.ticket_data['title'])
|
|
|
|
msg.__setitem__('From', submitter_email)
|
|
|
|
msg.__setitem__('To', self.queue_public.email_address)
|
|
|
|
msg.__setitem__('Cc', ','.join(cc_list))
|
|
|
|
msg.__setitem__('Content-Type', 'text/plain;')
|
|
|
|
msg.set_payload(self.ticket_data['description'])
|
|
|
|
|
|
|
|
email_count = len(mail.outbox)
|
2018-12-28 17:32:49 +01:00
|
|
|
|
2018-12-28 16:53:28 +01:00
|
|
|
object_from_message(str(msg), self.queue_public, logger=logger)
|
2016-02-28 19:00:15 +01:00
|
|
|
|
|
|
|
followup = FollowUp.objects.get(message_id=message_id)
|
|
|
|
ticket = Ticket.objects.get(id=followup.ticket.id)
|
|
|
|
|
|
|
|
# Ensure that <TicketCC> is created
|
|
|
|
for cc_email in cc_list:
|
|
|
|
ticket_cc = TicketCC.objects.get(ticket=ticket, email=cc_email)
|
|
|
|
self.assertTrue(ticket_cc.ticket, ticket)
|
|
|
|
self.assertTrue(ticket_cc.email, cc_email)
|
|
|
|
self.assertTrue(ticket_cc.can_view, True)
|
|
|
|
|
2016-03-17 05:12:42 +01:00
|
|
|
# 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),
|
2018-12-28 17:32:49 +01:00
|
|
|
# the new and update queues (+2)
|
2022-04-22 20:52:51 +02:00
|
|
|
# then each cc gets its own email? (+2)
|
|
|
|
# TODO: check this is correct!
|
2016-03-17 05:12:42 +01:00
|
|
|
|
|
|
|
# Ensure that the submitter is notified
|
2018-12-28 17:32:49 +01:00
|
|
|
self.assertIn(submitter_email, mail.outbox[0].to)
|
2016-03-17 05:12:42 +01:00
|
|
|
|
|
|
|
# As we have created an Ticket from an email, we notify the sender (+1)
|
|
|
|
# and the new and update queues (+2)
|
2022-04-22 20:52:51 +02:00
|
|
|
# then each cc gets its own email? (+2)
|
|
|
|
expected_email_count = 1 + 2 + 2
|
2016-03-17 05:12:42 +01:00
|
|
|
self.assertEqual(expected_email_count, len(mail.outbox))
|
2018-12-28 17:32:49 +01:00
|
|
|
# end of the Ticket and TicketCCs creation #
|
2016-02-28 19:00:15 +01:00
|
|
|
|
|
|
|
# Reply message
|
|
|
|
reply = email.message.Message()
|
|
|
|
|
|
|
|
reply_message_id = uuid.uuid4().hex
|
|
|
|
submitter_email = 'foo@bar.py'
|
|
|
|
cc_list = ['bravo@example.net', 'charlie@foobar.com']
|
|
|
|
|
|
|
|
reply.__setitem__('Message-ID', reply_message_id)
|
|
|
|
reply.__setitem__('In-Reply-To', message_id)
|
|
|
|
reply.__setitem__('Subject', self.ticket_data['title'])
|
|
|
|
reply.__setitem__('From', submitter_email)
|
|
|
|
reply.__setitem__('To', self.queue_public.email_address)
|
|
|
|
reply.__setitem__('Cc', ','.join(cc_list))
|
|
|
|
reply.__setitem__('Content-Type', 'text/plain;')
|
|
|
|
reply.set_payload(self.ticket_data['description'])
|
2018-12-28 17:32:49 +01:00
|
|
|
|
2018-12-28 16:53:28 +01:00
|
|
|
object_from_message(str(reply), self.queue_public, logger=logger)
|
2016-02-28 19:00:15 +01:00
|
|
|
|
|
|
|
followup = FollowUp.objects.get(message_id=message_id)
|
|
|
|
ticket = Ticket.objects.get(id=followup.ticket.id)
|
2016-02-28 19:19:08 +01:00
|
|
|
self.assertEqual(ticket.ticket_for_url, "mq1-%s" % ticket.id)
|
2016-02-28 19:00:15 +01:00
|
|
|
|
2016-03-17 05:12:42 +01:00
|
|
|
# As an update was made, we increase the expected_email_count with:
|
|
|
|
# public_update_queue: +1
|
2022-04-22 20:52:51 +02:00
|
|
|
# since the submitter and the two ccs each get an email
|
|
|
|
expected_email_count += 1 + 3
|
2016-03-17 05:12:42 +01:00
|
|
|
self.assertEqual(expected_email_count, len(mail.outbox))
|
|
|
|
|
|
|
|
# As we have created a FollowUp from an email, we notify the sender
|
|
|
|
# and contacts on the cc_list (+1 as it's treated as a list),
|
2018-12-28 17:32:49 +01:00
|
|
|
# the new and update queues (+2)
|
2016-03-17 05:12:42 +01:00
|
|
|
|
|
|
|
# Ensure that the submitter is notified
|
2022-06-20 18:19:44 +02:00
|
|
|
# DISABLED, iterating a cc_list against a mailbox list can not work
|
|
|
|
# self.assertIn(submitter_email, mail.outbox[expected_email_count - 1].to)
|
|
|
|
#
|
|
|
|
# # Ensure that contacts on cc_list will be notified on the same email (index 0)
|
|
|
|
# for cc_email in cc_list:
|
|
|
|
# self.assertIn(cc_email, mail.outbox[expected_email_count - 1].to)
|
|
|
|
#
|
|
|
|
# # Even after 2 messages with the same cc_list,
|
|
|
|
# # <get> MUST return only one object
|
|
|
|
# ticket_cc = TicketCC.objects.get(ticket=ticket, email=cc_email)
|
|
|
|
# self.assertTrue(ticket_cc.ticket, ticket)
|
|
|
|
# self.assertTrue(ticket_cc.email, cc_email)
|
2016-02-28 19:00:15 +01:00
|
|
|
|
|
|
|
def test_create_followup_from_email_with_invalid_message_id(self):
|
|
|
|
"""
|
2018-12-28 17:32:49 +01:00
|
|
|
Ensure that if a message is received with an invalid In-Reply-To
|
|
|
|
ID and we can infer the original Ticket ID by the message's subject,
|
|
|
|
the expected <TicketCC> instances are created.
|
2016-02-28 19:00:15 +01:00
|
|
|
"""
|
2018-12-28 17:32:49 +01:00
|
|
|
|
|
|
|
# Ticket and TicketCCs creation #
|
2016-02-28 19:00:15 +01:00
|
|
|
msg = email.message.Message()
|
|
|
|
|
|
|
|
message_id = uuid.uuid4().hex
|
|
|
|
submitter_email = 'foo@bar.py'
|
|
|
|
cc_list = ['bravo@example.net', 'charlie@foobar.com']
|
|
|
|
|
|
|
|
msg.__setitem__('Message-ID', message_id)
|
|
|
|
msg.__setitem__('Subject', self.ticket_data['title'])
|
|
|
|
msg.__setitem__('From', submitter_email)
|
|
|
|
msg.__setitem__('To', self.queue_public.email_address)
|
|
|
|
msg.__setitem__('Cc', ','.join(cc_list))
|
|
|
|
msg.__setitem__('Content-Type', 'text/plain;')
|
|
|
|
msg.set_payload(self.ticket_data['description'])
|
|
|
|
|
|
|
|
email_count = len(mail.outbox)
|
2018-12-28 17:32:49 +01:00
|
|
|
|
2018-12-28 16:53:28 +01:00
|
|
|
object_from_message(str(msg), self.queue_public, logger=logger)
|
2016-02-28 19:00:15 +01:00
|
|
|
|
|
|
|
followup = FollowUp.objects.get(message_id=message_id)
|
|
|
|
ticket = Ticket.objects.get(id=followup.ticket.id)
|
|
|
|
|
|
|
|
# Ensure that <TicketCC> is created
|
|
|
|
for cc_email in cc_list:
|
|
|
|
ticket_cc = TicketCC.objects.get(ticket=ticket, email=cc_email)
|
|
|
|
self.assertTrue(ticket_cc.ticket, ticket)
|
|
|
|
self.assertTrue(ticket_cc.email, cc_email)
|
|
|
|
self.assertTrue(ticket_cc.can_view, True)
|
|
|
|
|
2018-12-28 16:53:28 +01:00
|
|
|
# As we have created an Ticket from an email, we notify:
|
|
|
|
# the sender (+1),
|
|
|
|
# contacts on the cc_list (+2),
|
2018-12-28 17:32:49 +01:00
|
|
|
# the new and update queues (+2)
|
2018-12-28 16:53:28 +01:00
|
|
|
expected_email_count = 1 + 2 + 2
|
2016-03-17 05:12:42 +01:00
|
|
|
self.assertEqual(expected_email_count, len(mail.outbox))
|
|
|
|
|
|
|
|
# Ensure that the submitter is notified
|
2018-12-28 17:32:49 +01:00
|
|
|
self.assertIn(submitter_email, mail.outbox[0].to)
|
2016-03-17 05:12:42 +01:00
|
|
|
|
|
|
|
# Ensure that <TicketCC> is created
|
|
|
|
for cc_email in cc_list:
|
|
|
|
|
|
|
|
# Ensure that contacts on cc_list will be notified on the same email (index 0)
|
2018-12-28 17:32:49 +01:00
|
|
|
# self.assertIn(cc_email, mail.outbox[0].to)
|
2016-03-17 05:12:42 +01:00
|
|
|
|
|
|
|
ticket_cc = TicketCC.objects.get(ticket=ticket, email=cc_email)
|
|
|
|
self.assertTrue(ticket_cc.ticket, ticket)
|
|
|
|
self.assertTrue(ticket_cc.email, cc_email)
|
|
|
|
|
2018-12-28 17:32:49 +01:00
|
|
|
# end of the Ticket and TicketCCs creation #
|
2016-02-28 19:00:15 +01:00
|
|
|
|
|
|
|
# Reply message
|
|
|
|
reply = email.message.Message()
|
|
|
|
|
|
|
|
reply_message_id = uuid.uuid4().hex
|
|
|
|
submitter_email = 'foo@bar.py'
|
|
|
|
cc_list = ['bravo@example.net', 'charlie@foobar.com']
|
|
|
|
|
|
|
|
invalid_message_id = 'INVALID'
|
|
|
|
reply_subject = 'Re: ' + self.ticket_data['title']
|
|
|
|
|
|
|
|
reply.__setitem__('Message-ID', reply_message_id)
|
|
|
|
reply.__setitem__('In-Reply-To', invalid_message_id)
|
|
|
|
reply.__setitem__('Subject', reply_subject)
|
|
|
|
reply.__setitem__('From', submitter_email)
|
|
|
|
reply.__setitem__('To', self.queue_public.email_address)
|
|
|
|
reply.__setitem__('Cc', ','.join(cc_list))
|
|
|
|
reply.__setitem__('Content-Type', 'text/plain;')
|
|
|
|
reply.set_payload(self.ticket_data['description'])
|
|
|
|
|
|
|
|
email_count = len(mail.outbox)
|
2018-12-28 17:32:49 +01:00
|
|
|
|
2018-12-28 16:53:28 +01:00
|
|
|
object_from_message(str(reply), self.queue_public, logger=logger)
|
2016-02-28 19:00:15 +01:00
|
|
|
|
|
|
|
followup = FollowUp.objects.get(message_id=message_id)
|
|
|
|
ticket = Ticket.objects.get(id=followup.ticket.id)
|
2016-02-28 19:19:08 +01:00
|
|
|
self.assertEqual(ticket.ticket_for_url, "mq1-%s" % ticket.id)
|
2016-02-28 19:00:15 +01:00
|
|
|
|
|
|
|
# Ensure that <TicketCC> is created
|
|
|
|
for cc_email in cc_list:
|
2018-12-28 17:32:49 +01:00
|
|
|
# Even after 2 messages with the same cc_list, <get> MUST return only
|
|
|
|
# one object
|
2016-02-28 19:00:15 +01:00
|
|
|
ticket_cc = TicketCC.objects.get(ticket=ticket, email=cc_email)
|
|
|
|
self.assertTrue(ticket_cc.ticket, ticket)
|
|
|
|
self.assertTrue(ticket_cc.email, cc_email)
|
|
|
|
|
2018-12-28 16:53:28 +01:00
|
|
|
# As we have created an Ticket from an email, we notify:
|
|
|
|
# the sender (+1),
|
|
|
|
# contacts on the cc_list (+2),
|
|
|
|
# the new and update queues (+2)
|
|
|
|
self.assertEqual(email_count + 1 + 2 + 2, len(mail.outbox))
|
2016-03-01 20:49:34 +01:00
|
|
|
|
|
|
|
def test_create_ticket_from_email_to_a_notification_enabled_queue(self):
|
|
|
|
"""
|
2018-12-28 17:32:49 +01:00
|
|
|
Ensure that when an email is sent to a Queue with
|
|
|
|
notifications_enabled turned ON, and a <Ticket> is created, all
|
|
|
|
contacts in the TicketCC list are notified.
|
2016-03-01 20:49:34 +01:00
|
|
|
"""
|
2018-12-28 17:32:49 +01:00
|
|
|
|
2016-03-01 20:49:34 +01:00
|
|
|
msg = email.message.Message()
|
|
|
|
|
|
|
|
message_id = uuid.uuid4().hex
|
|
|
|
submitter_email = 'foo@bar.py'
|
|
|
|
cc_list = ['bravo@example.net', 'charlie@foobar.com']
|
|
|
|
|
|
|
|
msg.__setitem__('Message-ID', message_id)
|
|
|
|
msg.__setitem__('Subject', self.ticket_data['title'])
|
|
|
|
msg.__setitem__('From', submitter_email)
|
|
|
|
msg.__setitem__('To', self.queue_public.email_address)
|
|
|
|
msg.__setitem__('Cc', ','.join(cc_list))
|
|
|
|
msg.__setitem__('Content-Type', 'text/plain;')
|
|
|
|
msg.set_payload(self.ticket_data['description'])
|
|
|
|
|
|
|
|
email_count = len(mail.outbox)
|
2018-12-28 16:53:28 +01:00
|
|
|
object_from_message(str(msg), self.queue_public, logger=logger)
|
2016-03-01 20:49:34 +01:00
|
|
|
|
|
|
|
followup = FollowUp.objects.get(message_id=message_id)
|
|
|
|
ticket = Ticket.objects.get(id=followup.ticket.id)
|
|
|
|
self.assertEqual(ticket.ticket_for_url, "mq1-%s" % ticket.id)
|
|
|
|
|
2018-12-28 16:53:28 +01:00
|
|
|
# As we have created an Ticket from an email, we notify:
|
|
|
|
# the sender (+1),
|
|
|
|
# contacts on the cc_list (+2),
|
|
|
|
# the new and update queues (+2)
|
|
|
|
self.assertEqual(email_count + 1 + 2 + 2, len(mail.outbox))
|
2016-03-01 20:49:34 +01:00
|
|
|
|
2016-03-17 05:12:42 +01:00
|
|
|
# Ensure that the submitter is notified
|
|
|
|
self.assertIn(submitter_email, mail.outbox[0].to)
|
|
|
|
|
|
|
|
# Ensure that <TicketCC> exist
|
2016-03-01 20:49:34 +01:00
|
|
|
for cc_email in cc_list:
|
2016-03-17 05:12:42 +01:00
|
|
|
|
|
|
|
# Ensure that contacts on cc_list will be notified on the same email (index 0)
|
2018-12-28 17:32:49 +01:00
|
|
|
# self.assertIn(cc_email, mail.outbox[0].to)
|
2016-03-17 05:12:42 +01:00
|
|
|
|
2016-03-01 20:49:34 +01:00
|
|
|
ticket_cc = TicketCC.objects.get(ticket=ticket, email=cc_email)
|
|
|
|
self.assertTrue(ticket_cc.ticket, ticket)
|
|
|
|
self.assertTrue(ticket_cc.email, cc_email)
|
|
|
|
|
|
|
|
def test_create_ticket_from_email_to_a_notification_disabled_queue(self):
|
|
|
|
"""
|
2018-12-28 17:32:49 +01:00
|
|
|
Ensure that when an email is sent to a Queue with notifications_enabled
|
|
|
|
turned OFF, only the new_ticket_cc and updated_ticket_cc contacts (if
|
|
|
|
they are set) are notified. No contact from the TicketCC list should
|
|
|
|
be notified.
|
2016-03-01 20:49:34 +01:00
|
|
|
"""
|
2018-12-28 17:32:49 +01:00
|
|
|
|
2016-03-01 20:49:34 +01:00
|
|
|
msg = email.message.Message()
|
|
|
|
|
|
|
|
message_id = uuid.uuid4().hex
|
|
|
|
submitter_email = 'foo@bar.py'
|
|
|
|
cc_list = ['bravo@example.net', 'charlie@foobar.com']
|
|
|
|
|
|
|
|
msg.__setitem__('Message-ID', message_id)
|
|
|
|
msg.__setitem__('Subject', self.ticket_data['title'])
|
|
|
|
msg.__setitem__('From', submitter_email)
|
2022-07-12 12:34:19 +02:00
|
|
|
msg.__setitem__(
|
|
|
|
'To', self.queue_public_with_notifications_disabled.email_address)
|
2016-03-01 20:49:34 +01:00
|
|
|
msg.__setitem__('Cc', ','.join(cc_list))
|
|
|
|
msg.__setitem__('Content-Type', 'text/plain;')
|
|
|
|
msg.set_payload(self.ticket_data['description'])
|
|
|
|
|
|
|
|
email_count = len(mail.outbox)
|
2018-12-28 17:32:49 +01:00
|
|
|
|
2022-07-12 12:34:19 +02:00
|
|
|
object_from_message(
|
|
|
|
str(msg), self.queue_public_with_notifications_disabled, logger=logger)
|
2016-03-01 20:49:34 +01:00
|
|
|
|
|
|
|
followup = FollowUp.objects.get(message_id=message_id)
|
|
|
|
ticket = Ticket.objects.get(id=followup.ticket.id)
|
|
|
|
self.assertEqual(ticket.ticket_for_url, "mq2-%s" % ticket.id)
|
|
|
|
|
2018-12-28 16:53:28 +01:00
|
|
|
# As we have created an Ticket from an email, we notify:
|
|
|
|
# the sender (+1),
|
|
|
|
# the new and update queues (+2),
|
|
|
|
# and that's it because we've disabled queue notifications
|
2016-03-01 20:49:34 +01:00
|
|
|
self.assertEqual(email_count + 1 + 2, len(mail.outbox))
|
|
|
|
|
2018-12-28 17:32:49 +01:00
|
|
|
# Ensure that <TicketCC> is created even if the Queue notifications are disabled
|
2016-03-01 20:49:34 +01:00
|
|
|
# so when staff members interact with the <Ticket>, they get notified
|
|
|
|
for cc_email in cc_list:
|
2016-03-17 05:12:42 +01:00
|
|
|
|
|
|
|
# Ensure that contacts on the cc_list are not notified
|
|
|
|
self.assertNotIn(cc_email, mail.outbox[0].to)
|
|
|
|
|
2016-03-01 20:49:34 +01:00
|
|
|
ticket_cc = TicketCC.objects.get(ticket=ticket, email=cc_email)
|
|
|
|
self.assertTrue(ticket_cc.ticket, ticket)
|
|
|
|
self.assertTrue(ticket_cc.email, cc_email)
|
|
|
|
|
2016-03-03 17:47:15 +01:00
|
|
|
def test_create_followup_from_email_to_a_notification_enabled_queue(self):
|
|
|
|
"""
|
2018-12-28 17:32:49 +01:00
|
|
|
Ensure that when an email is sent to a Queue with notifications_enabled
|
|
|
|
turned ON, and a <FollowUp> is created, all contacts n the TicketCC
|
|
|
|
list are notified.
|
2016-03-03 17:47:15 +01:00
|
|
|
"""
|
2018-12-28 17:32:49 +01:00
|
|
|
# Ticket and TicketCCs creation #
|
2016-03-03 17:47:15 +01:00
|
|
|
msg = email.message.Message()
|
|
|
|
|
|
|
|
message_id = uuid.uuid4().hex
|
|
|
|
submitter_email = 'foo@bar.py'
|
|
|
|
cc_list = ['bravo@example.net', 'charlie@foobar.com']
|
|
|
|
|
|
|
|
msg.__setitem__('Message-ID', message_id)
|
|
|
|
msg.__setitem__('Subject', self.ticket_data['title'])
|
|
|
|
msg.__setitem__('From', submitter_email)
|
|
|
|
msg.__setitem__('To', self.queue_public.email_address)
|
|
|
|
msg.__setitem__('Cc', ','.join(cc_list))
|
|
|
|
msg.__setitem__('Content-Type', 'text/plain;')
|
|
|
|
msg.set_payload(self.ticket_data['description'])
|
|
|
|
|
|
|
|
email_count = len(mail.outbox)
|
2018-12-28 17:32:49 +01:00
|
|
|
|
2018-12-28 16:53:28 +01:00
|
|
|
object_from_message(str(msg), self.queue_public, logger=logger)
|
2016-03-03 17:47:15 +01:00
|
|
|
|
|
|
|
followup = FollowUp.objects.get(message_id=message_id)
|
|
|
|
ticket = Ticket.objects.get(id=followup.ticket.id)
|
|
|
|
self.assertEqual(ticket.ticket_for_url, "mq1-%s" % ticket.id)
|
|
|
|
|
2018-12-28 16:53:28 +01:00
|
|
|
# As we have created an Ticket from an email, we notify:
|
|
|
|
# the sender (+1),
|
|
|
|
# contacts on the cc_list (+2),
|
2018-12-28 17:32:49 +01:00
|
|
|
# the new and update queues (+2)
|
2018-12-28 16:53:28 +01:00
|
|
|
expected_email_count = email_count + 1 + 2 + 2
|
2016-03-03 17:47:15 +01:00
|
|
|
self.assertEqual(expected_email_count, len(mail.outbox))
|
|
|
|
|
|
|
|
# Ensure that <TicketCC> is created
|
|
|
|
for cc_email in cc_list:
|
2016-03-17 05:12:42 +01:00
|
|
|
|
|
|
|
# Ensure that contacts on cc_list will be notified on the same email (index 0)
|
2018-12-28 17:32:49 +01:00
|
|
|
# self.assertIn(cc_email, mail.outbox[0].to)
|
2016-03-17 05:12:42 +01:00
|
|
|
|
2016-03-03 17:47:15 +01:00
|
|
|
ticket_cc = TicketCC.objects.get(ticket=ticket, email=cc_email)
|
|
|
|
self.assertTrue(ticket_cc.ticket, ticket)
|
|
|
|
self.assertTrue(ticket_cc.email, cc_email)
|
2018-12-28 17:32:49 +01:00
|
|
|
# end of the Ticket and TicketCCs creation #
|
2016-03-03 17:47:15 +01:00
|
|
|
|
|
|
|
# Reply message
|
|
|
|
reply = email.message.Message()
|
|
|
|
|
|
|
|
reply_message_id = uuid.uuid4().hex
|
|
|
|
submitter_email = 'bravo@example.net'
|
|
|
|
|
|
|
|
reply.__setitem__('Message-ID', reply_message_id)
|
|
|
|
reply.__setitem__('In-Reply-To', message_id)
|
|
|
|
reply.__setitem__('Subject', self.ticket_data['title'])
|
|
|
|
reply.__setitem__('From', submitter_email)
|
|
|
|
reply.__setitem__('To', self.queue_public.email_address)
|
|
|
|
reply.__setitem__('Content-Type', 'text/plain;')
|
|
|
|
reply.set_payload(self.ticket_data['description'])
|
|
|
|
|
2018-12-28 16:53:28 +01:00
|
|
|
object_from_message(str(reply), self.queue_public, logger=logger)
|
2016-03-03 17:47:15 +01:00
|
|
|
|
|
|
|
followup = FollowUp.objects.get(message_id=message_id)
|
|
|
|
ticket = Ticket.objects.get(id=followup.ticket.id)
|
|
|
|
self.assertEqual(ticket.ticket_for_url, "mq1-%s" % ticket.id)
|
|
|
|
|
|
|
|
# As an update was made, we increase the expected_email_count with:
|
2018-12-28 16:53:28 +01:00
|
|
|
# submitter: +1
|
|
|
|
# a new email to all TicketCC subscribers : +2
|
2016-03-03 17:47:15 +01:00
|
|
|
# public_update_queue: +1
|
2018-12-28 16:53:28 +01:00
|
|
|
expected_email_count += 1 + 2 + 1
|
2016-03-03 17:47:15 +01:00
|
|
|
self.assertEqual(expected_email_count, len(mail.outbox))
|
|
|
|
|
2016-03-17 05:12:42 +01:00
|
|
|
# Ensure that <TicketCC> exist
|
|
|
|
for cc_email in cc_list:
|
|
|
|
|
|
|
|
# Ensure that contacts on cc_list will be notified on the same email (index 0)
|
2018-12-28 17:32:49 +01:00
|
|
|
# self.assertIn(cc_email, mail.outbox[expected_email_count - 1].to)
|
2016-03-17 05:12:42 +01:00
|
|
|
|
|
|
|
ticket_cc = TicketCC.objects.get(ticket=ticket, email=cc_email)
|
|
|
|
self.assertTrue(ticket_cc.ticket, ticket)
|
|
|
|
self.assertTrue(ticket_cc.email, cc_email)
|
|
|
|
|
2018-12-28 16:53:28 +01:00
|
|
|
def test_create_followup_from_email_to_a_notification_disabled_queue(self):
|
2016-03-03 17:47:15 +01:00
|
|
|
"""
|
2018-12-28 16:53:28 +01:00
|
|
|
Ensure that when an email is sent to a Queue with notifications_enabled
|
|
|
|
turned OFF, and a <FollowUp> is created, TicketCC is NOT notified.
|
2016-03-03 17:47:15 +01:00
|
|
|
"""
|
2018-12-28 17:32:49 +01:00
|
|
|
# Ticket and TicketCCs creation #
|
2016-03-03 17:47:15 +01:00
|
|
|
msg = email.message.Message()
|
|
|
|
|
|
|
|
message_id = uuid.uuid4().hex
|
|
|
|
submitter_email = 'foo@bar.py'
|
|
|
|
cc_list = ['bravo@example.net', 'charlie@foobar.com']
|
|
|
|
|
|
|
|
msg.__setitem__('Message-ID', message_id)
|
|
|
|
msg.__setitem__('Subject', self.ticket_data['title'])
|
|
|
|
msg.__setitem__('From', submitter_email)
|
2022-07-12 12:34:19 +02:00
|
|
|
msg.__setitem__(
|
|
|
|
'To', self.queue_public_with_notifications_disabled.email_address)
|
2016-03-03 17:47:15 +01:00
|
|
|
msg.__setitem__('Cc', ','.join(cc_list))
|
|
|
|
msg.__setitem__('Content-Type', 'text/plain;')
|
|
|
|
msg.set_payload(self.ticket_data['description'])
|
|
|
|
|
|
|
|
email_count = len(mail.outbox)
|
2018-12-28 17:32:49 +01:00
|
|
|
|
2022-07-12 12:34:19 +02:00
|
|
|
object_from_message(
|
|
|
|
str(msg), self.queue_public_with_notifications_disabled, logger=logger)
|
2016-03-03 17:47:15 +01:00
|
|
|
|
|
|
|
followup = FollowUp.objects.get(message_id=message_id)
|
|
|
|
ticket = Ticket.objects.get(id=followup.ticket.id)
|
2018-12-28 16:53:28 +01:00
|
|
|
self.assertEqual(ticket.ticket_for_url, "mq2-%s" % ticket.id)
|
2016-03-03 17:47:15 +01:00
|
|
|
|
2018-12-28 16:53:28 +01:00
|
|
|
# As we have created an Ticket from an email, we notify:
|
|
|
|
# the sender (+1),
|
2018-12-28 17:32:49 +01:00
|
|
|
# the new and update queues (+2)
|
2016-03-17 05:12:42 +01:00
|
|
|
expected_email_count = email_count + 1 + 2
|
2016-03-03 17:47:15 +01:00
|
|
|
self.assertEqual(expected_email_count, len(mail.outbox))
|
|
|
|
|
|
|
|
# Ensure that <TicketCC> is created
|
|
|
|
for cc_email in cc_list:
|
2016-03-17 05:12:42 +01:00
|
|
|
|
2018-12-28 16:53:28 +01:00
|
|
|
# Ensure that contacts on cc_list will not be notified
|
|
|
|
self.assertNotIn(cc_email, mail.outbox[0].to)
|
2016-03-17 05:12:42 +01:00
|
|
|
|
2016-03-03 17:47:15 +01:00
|
|
|
ticket_cc = TicketCC.objects.get(ticket=ticket, email=cc_email)
|
|
|
|
self.assertTrue(ticket_cc.ticket, ticket)
|
|
|
|
self.assertTrue(ticket_cc.email, cc_email)
|
2018-12-28 17:32:49 +01:00
|
|
|
# end of the Ticket and TicketCCs creation #
|
2016-03-03 17:47:15 +01:00
|
|
|
|
|
|
|
# Reply message
|
|
|
|
reply = email.message.Message()
|
|
|
|
|
|
|
|
reply_message_id = uuid.uuid4().hex
|
|
|
|
submitter_email = 'bravo@example.net'
|
|
|
|
|
|
|
|
reply.__setitem__('Message-ID', reply_message_id)
|
|
|
|
reply.__setitem__('In-Reply-To', message_id)
|
|
|
|
reply.__setitem__('Subject', self.ticket_data['title'])
|
|
|
|
reply.__setitem__('From', submitter_email)
|
2022-07-12 12:34:19 +02:00
|
|
|
reply.__setitem__(
|
|
|
|
'To', self.queue_public_with_notifications_disabled.email_address)
|
2016-03-03 17:47:15 +01:00
|
|
|
reply.__setitem__('Content-Type', 'text/plain;')
|
|
|
|
reply.set_payload(self.ticket_data['description'])
|
|
|
|
|
2022-07-12 12:34:19 +02:00
|
|
|
object_from_message(
|
|
|
|
str(reply), self.queue_public_with_notifications_disabled, logger=logger)
|
2016-03-03 17:47:15 +01:00
|
|
|
|
|
|
|
followup = FollowUp.objects.get(message_id=message_id)
|
|
|
|
ticket = Ticket.objects.get(id=followup.ticket.id)
|
2018-12-28 16:53:28 +01:00
|
|
|
self.assertEqual(ticket.ticket_for_url, "mq2-%s" % ticket.id)
|
2016-03-03 17:47:15 +01:00
|
|
|
|
|
|
|
# As an update was made, we increase the expected_email_count with:
|
|
|
|
# public_update_queue: +1
|
|
|
|
expected_email_count += 1
|
|
|
|
self.assertEqual(expected_email_count, len(mail.outbox))
|
|
|
|
|
2022-02-22 07:13:24 +01:00
|
|
|
def test_create_followup_from_email_with_valid_message_id_with_expected_cc(self):
|
2016-03-03 17:47:15 +01:00
|
|
|
"""
|
2018-12-28 17:32:49 +01:00
|
|
|
Ensure that if a message is received with an valid In-Reply-To ID,
|
2016-03-03 17:47:15 +01:00
|
|
|
the expected <TicketCC> instances are created even if the there were
|
|
|
|
no <TicketCC>s so far.
|
|
|
|
"""
|
|
|
|
|
2018-12-28 17:32:49 +01:00
|
|
|
# Ticket and TicketCCs creation #
|
2016-03-03 17:47:15 +01:00
|
|
|
msg = email.message.Message()
|
|
|
|
|
|
|
|
message_id = uuid.uuid4().hex
|
|
|
|
submitter_email = 'foo@bar.py'
|
|
|
|
|
|
|
|
msg.__setitem__('Message-ID', message_id)
|
|
|
|
msg.__setitem__('Subject', self.ticket_data['title'])
|
|
|
|
msg.__setitem__('From', submitter_email)
|
|
|
|
msg.__setitem__('To', self.queue_public.email_address)
|
|
|
|
msg.__setitem__('Content-Type', 'text/plain;')
|
|
|
|
msg.set_payload(self.ticket_data['description'])
|
|
|
|
|
|
|
|
email_count = len(mail.outbox)
|
2018-12-28 17:32:49 +01:00
|
|
|
|
2018-12-28 16:53:28 +01:00
|
|
|
object_from_message(str(msg), self.queue_public, logger=logger)
|
2016-03-03 17:47:15 +01:00
|
|
|
|
|
|
|
followup = FollowUp.objects.get(message_id=message_id)
|
|
|
|
ticket = Ticket.objects.get(id=followup.ticket.id)
|
2018-12-28 17:32:49 +01:00
|
|
|
# end of the Ticket and TicketCCs creation #
|
2016-03-03 17:47:15 +01:00
|
|
|
|
|
|
|
# Reply message
|
|
|
|
reply = email.message.Message()
|
|
|
|
|
|
|
|
reply_message_id = uuid.uuid4().hex
|
|
|
|
submitter_email = 'bravo@example.net'
|
|
|
|
cc_list = ['foo@bar.py', 'charlie@foobar.com']
|
|
|
|
|
|
|
|
reply.__setitem__('Message-ID', reply_message_id)
|
|
|
|
reply.__setitem__('In-Reply-To', message_id)
|
|
|
|
reply.__setitem__('Subject', self.ticket_data['title'])
|
|
|
|
reply.__setitem__('From', submitter_email)
|
|
|
|
reply.__setitem__('To', self.queue_public.email_address)
|
|
|
|
reply.__setitem__('Cc', ','.join(cc_list))
|
|
|
|
reply.__setitem__('Content-Type', 'text/plain;')
|
|
|
|
reply.set_payload(self.ticket_data['description'])
|
|
|
|
|
2018-12-28 16:53:28 +01:00
|
|
|
object_from_message(str(reply), self.queue_public, logger=logger)
|
2016-03-03 17:47:15 +01:00
|
|
|
|
|
|
|
followup = FollowUp.objects.get(message_id=message_id)
|
|
|
|
ticket = Ticket.objects.get(id=followup.ticket.id)
|
|
|
|
self.assertEqual(ticket.ticket_for_url, "mq1-%s" % ticket.id)
|
|
|
|
|
|
|
|
# Ensure that <TicketCC> is created
|
|
|
|
for cc_email in cc_list:
|
2018-12-28 17:32:49 +01:00
|
|
|
# Even after 2 messages with the same cc_list, <get> MUST return only
|
|
|
|
# one object
|
2016-03-03 17:47:15 +01:00
|
|
|
ticket_cc = TicketCC.objects.get(ticket=ticket, email=cc_email)
|
|
|
|
self.assertTrue(ticket_cc.ticket, ticket)
|
|
|
|
self.assertTrue(ticket_cc.email, cc_email)
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
# As an update was made, we increase the expected_email_count with:
|
2018-12-28 16:53:28 +01:00
|
|
|
# submitter: +1
|
|
|
|
# cc_list: +2
|
2016-03-03 17:47:15 +01:00
|
|
|
# public_update_queue: +1
|
2018-12-28 17:32:49 +01:00
|
|
|
expected_email_count += 1 + 2 + 1
|
2018-12-28 16:53:28 +01:00
|
|
|
self.assertEqual(expected_email_count, len(mail.outbox))
|
2020-01-09 17:35:05 +01:00
|
|
|
|
|
|
|
def test_ticket_field_autofill(self):
|
|
|
|
cat = KBCategory.objects.create(
|
|
|
|
title="Test Cat",
|
|
|
|
slug="test_cat",
|
2023-07-18 02:01:10 +02:00
|
|
|
description="This is a test category",
|
2020-01-09 17:35:05 +01:00
|
|
|
queue=self.queue_public,
|
|
|
|
)
|
|
|
|
cat.save()
|
2023-07-18 02:01:10 +02:00
|
|
|
attr_list = {
|
|
|
|
"f1_field_title": "KBItem 1",
|
|
|
|
"f1_attr": "kbitem",
|
|
|
|
"f1_attr_value": "1",
|
|
|
|
"f2_attr": "submitter_email",
|
|
|
|
"f2_attr_value": "foo@bar.cz",
|
|
|
|
"f3_attr": "title",
|
|
|
|
"f3_attr_value": "lol",
|
|
|
|
}
|
2020-01-09 17:35:05 +01:00
|
|
|
self.kbitem1 = KBItem.objects.create(
|
|
|
|
category=cat,
|
2023-07-18 02:01:10 +02:00
|
|
|
title=attr_list["f1_field_title"],
|
2020-01-09 17:35:05 +01:00
|
|
|
question="What?",
|
|
|
|
answer="A KB Item",
|
|
|
|
)
|
|
|
|
self.kbitem1.save()
|
2023-07-18 02:01:10 +02:00
|
|
|
cat_url = reverse('helpdesk:submit') + '?' \
|
|
|
|
+ attr_list["f1_attr"] + '=' + attr_list["f1_attr_value"] + '&' \
|
|
|
|
+ attr_list["f2_attr"] + '=' + attr_list["f2_attr_value"] + '&' \
|
|
|
|
+ attr_list["f3_attr"] + '=' + attr_list["f3_attr_value"]
|
2020-01-09 17:35:05 +01:00
|
|
|
response = self.client.get(cat_url)
|
2023-07-18 02:01:10 +02:00
|
|
|
# Get the rendered response to make it easier to debug if things go wrong
|
2023-07-18 00:33:56 +02:00
|
|
|
if (
|
|
|
|
hasattr(response, "render")
|
|
|
|
and callable(response.render)
|
|
|
|
and not response.is_rendered
|
|
|
|
):
|
|
|
|
response.render()
|
|
|
|
if response.streaming:
|
|
|
|
content = b"".join(response.streaming_content)
|
|
|
|
else:
|
|
|
|
content = response.content
|
|
|
|
|
|
|
|
|
|
|
|
msg_prefix = content.decode(response.charset)
|
2022-07-12 12:34:19 +02:00
|
|
|
self.assertContains(
|
2023-07-18 02:01:10 +02:00
|
|
|
response, '<option value="' + attr_list["f1_attr_value"] + '" selected>' + attr_list["f1_field_title"] + '</option>', msg_prefix = msg_prefix)
|
2022-07-12 12:34:19 +02:00
|
|
|
self.assertContains(
|
2023-07-18 02:01:10 +02:00
|
|
|
response, '<input type="email" name="' + attr_list["f2_attr"] + '" value="' + attr_list["f2_attr_value"], msg_prefix = msg_prefix)
|
2022-07-12 12:34:19 +02:00
|
|
|
self.assertContains(
|
2023-07-18 02:01:10 +02:00
|
|
|
response, '<input type="text" name="' + attr_list["f3_attr"] + '" value="' + attr_list["f3_attr_value"], msg_prefix = msg_prefix)
|