mirror of
https://gitea.mueller.network/extern/django-helpdesk.git
synced 2024-11-21 23:43:11 +01:00
PEP-8 fixes for mail threading merge
This commit is contained in:
parent
5f0d22a692
commit
43ed3ac773
@ -270,7 +270,7 @@ def create_ticket_cc(ticket, cc_list):
|
||||
|
||||
if not cc_list:
|
||||
return []
|
||||
|
||||
|
||||
# Local import to deal with non-defined / circular reference problem
|
||||
from helpdesk.views.staff import User, subscribe_to_ticket_updates
|
||||
|
||||
@ -285,7 +285,7 @@ def create_ticket_cc(ticket, cc_list):
|
||||
|
||||
try:
|
||||
user = User.objects.get(email=cced_email)
|
||||
except User.DoesNotExist:
|
||||
except User.DoesNotExist:
|
||||
pass
|
||||
|
||||
try:
|
||||
@ -318,7 +318,7 @@ def create_object_from_email_message(message, ticket_id, payload, files, logger)
|
||||
previous_followup = queryset.first()
|
||||
ticket = previous_followup.ticket
|
||||
except FollowUp.DoesNotExist:
|
||||
pass #play along. The header may be wrong
|
||||
pass # play along. The header may be wrong
|
||||
|
||||
if previous_followup is None and ticket_id is not None:
|
||||
try:
|
||||
@ -331,12 +331,12 @@ def create_object_from_email_message(message, ticket_id, payload, files, logger)
|
||||
if ticket is None:
|
||||
if not settings.QUEUE_EMAIL_BOX_UPDATE_ONLY:
|
||||
ticket = Ticket.objects.create(
|
||||
title = payload['subject'],
|
||||
queue = queue,
|
||||
submitter_email = sender_email,
|
||||
created = now,
|
||||
description = payload['body'],
|
||||
priority = payload['priority'],
|
||||
title=payload['subject'],
|
||||
queue=queue,
|
||||
submitter_email=sender_email,
|
||||
created=now,
|
||||
description=payload['body'],
|
||||
priority=payload['priority'],
|
||||
)
|
||||
ticket.save()
|
||||
logger.debug("Created new ticket %s-%s" % (ticket.queue.slug, ticket.id))
|
||||
@ -350,23 +350,23 @@ def create_object_from_email_message(message, ticket_id, payload, files, logger)
|
||||
ticket.save()
|
||||
|
||||
f = FollowUp(
|
||||
ticket = ticket,
|
||||
title = _('E-Mail Received from %(sender_email)s' % {'sender_email': sender_email}),
|
||||
date = now,
|
||||
public = True,
|
||||
comment = payload['body'],
|
||||
message_id = message_id,
|
||||
ticket=ticket,
|
||||
title=_('E-Mail Received from %(sender_email)s' % {'sender_email': sender_email}),
|
||||
date=now,
|
||||
public=True,
|
||||
comment=payload['body'],
|
||||
message_id=message_id
|
||||
)
|
||||
|
||||
if ticket.status == Ticket.REOPENED_STATUS:
|
||||
f.new_status = Ticket.REOPENED_STATUS
|
||||
f.title = _('Ticket Re-Opened by E-Mail Received from %(sender_email)s' % {'sender_email': sender_email})
|
||||
|
||||
|
||||
f.save()
|
||||
logger.debug("Created new FollowUp for Ticket")
|
||||
|
||||
logger.info("[%s-%s] %s" % (ticket.queue.slug, ticket.id, ticket.title,))
|
||||
|
||||
|
||||
attached = process_attachments(f, files)
|
||||
for att_file in attached:
|
||||
logger.info("Attachment '%s' (with size %s) successfully added to ticket from email." % (att_file[0], att_file[1].size))
|
||||
@ -376,15 +376,15 @@ def create_object_from_email_message(message, ticket_id, payload, files, logger)
|
||||
new_ticket_ccs = []
|
||||
new_ticket_ccs.append(create_ticket_cc(ticket, to_list + cc_list))
|
||||
|
||||
notifications_to_be_sent = [sender_email,]
|
||||
|
||||
notifications_to_be_sent = [sender_email]
|
||||
|
||||
if queue.enable_notifications_on_email_events and len(notifications_to_be_sent):
|
||||
|
||||
ticket_cc_list = TicketCC.objects.filter(ticket=ticket).all().values_list('email', flat=True)
|
||||
|
||||
for email in ticket_cc_list :
|
||||
for email in ticket_cc_list:
|
||||
notifications_to_be_sent.append(email)
|
||||
|
||||
|
||||
# send mail to appropriate people now depending on what objects
|
||||
# were created and who was CC'd
|
||||
if new:
|
||||
@ -399,13 +399,13 @@ def create_object_from_email_message(message, ticket_id, payload, files, logger)
|
||||
context.update(comment=f.comment)
|
||||
ticket.send(
|
||||
{'submitter': ('newticket_submitter', context),
|
||||
'assigned_to': ('updated_owner', context),},
|
||||
'assigned_to': ('updated_owner', context)},
|
||||
fail_silently=True,
|
||||
extra_headers={'In-Reply-To': message_id},
|
||||
)
|
||||
if queue.enable_notifications_on_email_events:
|
||||
ticket.send(
|
||||
{'ticket_cc': ('updated_cc', context),},
|
||||
{'ticket_cc': ('updated_cc', context)},
|
||||
fail_silently=True,
|
||||
extra_headers={'In-Reply-To': message_id},
|
||||
)
|
||||
@ -416,7 +416,7 @@ def create_object_from_email_message(message, ticket_id, payload, files, logger)
|
||||
def object_from_message(message, queue, logger):
|
||||
# 'message' must be an RFC822 formatted message.
|
||||
message = email.message_from_string(message)
|
||||
|
||||
|
||||
subject = message.get('subject', _('Comment from e-mail'))
|
||||
subject = decode_mail_headers(decodeUnknown(message.get_charset(), subject))
|
||||
for affix in STRIPPED_SUBJECT_STRINGS:
|
||||
@ -426,9 +426,9 @@ def object_from_message(message, queue, logger):
|
||||
sender = message.get('from', _('Unknown Sender'))
|
||||
sender = decode_mail_headers(decodeUnknown(message.get_charset(), sender))
|
||||
sender_email = email.utils.parseaddr(sender)[1]
|
||||
|
||||
|
||||
body_plain, body_html = '', ''
|
||||
|
||||
|
||||
cc = message.get_all('cc', None)
|
||||
if cc:
|
||||
# first, fixup the encoding if necessary
|
||||
@ -521,7 +521,7 @@ def object_from_message(message, queue, logger):
|
||||
smtp_importance = message.get('importance', '')
|
||||
high_priority_types = {'high', 'important', '1', 'urgent'}
|
||||
priority = 2 if high_priority_types & {smtp_priority, smtp_importance} else 3
|
||||
|
||||
|
||||
payload = {
|
||||
'body': body,
|
||||
'subject': subject,
|
||||
@ -530,6 +530,5 @@ def object_from_message(message, queue, logger):
|
||||
'priority': priority,
|
||||
'files': files,
|
||||
}
|
||||
|
||||
return create_object_from_email_message(message, ticket, payload, files, logger=logger)
|
||||
|
||||
return create_object_from_email_message(message, ticket, payload, files, logger=logger)
|
||||
|
@ -113,9 +113,9 @@ class Queue(models.Model):
|
||||
blank=True,
|
||||
default=False,
|
||||
help_text=_('When an email arrives to either create a ticket or to '
|
||||
'interact with an existing discussion. Should email notifications be sent ? '
|
||||
'Note: the new_ticket_cc and updated_ticket_cc work independently of this feature'),
|
||||
)
|
||||
'interact with an existing discussion. Should email notifications be sent ? '
|
||||
'Note: the new_ticket_cc and updated_ticket_cc work independently of this feature'),
|
||||
)
|
||||
|
||||
email_box_type = models.CharField(
|
||||
_('E-Mail Box Type'),
|
||||
@ -767,7 +767,7 @@ class FollowUp(models.Model):
|
||||
null=True,
|
||||
help_text=_("The Message ID of the submitter's email."),
|
||||
editable=False,
|
||||
)
|
||||
)
|
||||
|
||||
objects = FollowUpManager()
|
||||
|
||||
|
@ -40,7 +40,7 @@ def send_templated_mail(template_name,
|
||||
|
||||
files can be a list of tuples. Each tuple should be a filename to attach,
|
||||
along with the File objects to be read. files can be blank.
|
||||
|
||||
|
||||
extra_headers is a dictionary of extra email headers, needed to process
|
||||
email replies and keep proper threading.
|
||||
|
||||
|
@ -139,32 +139,35 @@ class TicketBasicsTestCase(TestCase):
|
||||
# Ensure only two e-mails were sent - submitter & updated.
|
||||
self.assertEqual(email_count + 2, len(mail.outbox))
|
||||
|
||||
|
||||
class EmailInteractionsTestCase(TestCase):
|
||||
fixtures = ['emailtemplate.json']
|
||||
|
||||
def setUp(self):
|
||||
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 = 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,
|
||||
)
|
||||
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,
|
||||
)
|
||||
|
||||
self.ticket_data = {
|
||||
'title': 'Test Ticket',
|
||||
'description': 'Some Test Ticket',
|
||||
}
|
||||
'title': 'Test Ticket',
|
||||
'description': 'Some Test Ticket',
|
||||
}
|
||||
|
||||
def test_create_ticket_from_email_with_message_id(self):
|
||||
|
||||
@ -178,10 +181,10 @@ class EmailInteractionsTestCase(TestCase):
|
||||
|
||||
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__('From', submitter_email)
|
||||
msg.__setitem__('To', self.queue_public.email_address)
|
||||
msg.__setitem__('Content-Type', 'text/plain;')
|
||||
msg.set_payload(self.ticket_data['description'])
|
||||
@ -195,12 +198,12 @@ class EmailInteractionsTestCase(TestCase):
|
||||
|
||||
self.assertEqual(ticket.ticket_for_url, "mq1-%s" % ticket.id)
|
||||
|
||||
# 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)
|
||||
self.assertEqual(email_count + 1 + 2, len(mail.outbox))
|
||||
|
||||
# Ensure that the submitter is notified
|
||||
self.assertIn(submitter_email,mail.outbox[0].to)
|
||||
self.assertIn(submitter_email, mail.outbox[0].to)
|
||||
|
||||
def test_create_ticket_from_email_without_message_id(self):
|
||||
|
||||
@ -214,7 +217,7 @@ class EmailInteractionsTestCase(TestCase):
|
||||
submitter_email = 'foo@bar.py'
|
||||
|
||||
msg.__setitem__('Subject', self.ticket_data['title'])
|
||||
msg.__setitem__('From', submitter_email)
|
||||
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'])
|
||||
@ -227,16 +230,15 @@ class EmailInteractionsTestCase(TestCase):
|
||||
|
||||
self.assertEqual(ticket.ticket_for_url, "mq1-%s" % ticket.id)
|
||||
|
||||
# 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)
|
||||
self.assertEqual(email_count + 1 + 2, len(mail.outbox))
|
||||
|
||||
# Ensure that the submitter is notified
|
||||
self.assertIn(submitter_email,mail.outbox[0].to)
|
||||
self.assertIn(submitter_email, mail.outbox[0].to)
|
||||
|
||||
def test_create_ticket_from_email_with_carbon_copy(self):
|
||||
|
||||
"""
|
||||
"""
|
||||
Ensure that an instance of <TicketCC> is created for every valid element of the
|
||||
"rfc_2822_cc" field when creating a <Ticket> instance.
|
||||
"""
|
||||
@ -256,7 +258,7 @@ class EmailInteractionsTestCase(TestCase):
|
||||
msg.set_payload(self.ticket_data['description'])
|
||||
|
||||
email_count = len(mail.outbox)
|
||||
|
||||
|
||||
object_from_message(str(msg), self.queue_public, logger=logger)
|
||||
|
||||
followup = FollowUp.objects.get(message_id=message_id)
|
||||
@ -266,17 +268,16 @@ class EmailInteractionsTestCase(TestCase):
|
||||
# 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)
|
||||
# the new and update queues (+2)
|
||||
self.assertEqual(email_count + 1 + 2 + 2, len(mail.outbox))
|
||||
|
||||
# Ensure that the submitter is notified
|
||||
self.assertIn(submitter_email,mail.outbox[0].to)
|
||||
self.assertIn(submitter_email, mail.outbox[0].to)
|
||||
|
||||
|
||||
for cc_email in cc_list:
|
||||
|
||||
# Ensure that contacts on cc_list will be notified on the same email (index 0)
|
||||
#self.assertIn(cc_email, mail.outbox[0].to)
|
||||
# self.assertIn(cc_email, mail.outbox[0].to)
|
||||
|
||||
# Ensure that <TicketCC> exists
|
||||
ticket_cc = TicketCC.objects.get(ticket=ticket, email=cc_email)
|
||||
@ -284,8 +285,7 @@ class EmailInteractionsTestCase(TestCase):
|
||||
self.assertTrue(ticket_cc.email, cc_email)
|
||||
|
||||
def test_create_ticket_from_email_to_multiple_emails(self):
|
||||
|
||||
"""
|
||||
"""
|
||||
Ensure that an instance of <TicketCC> is created for every valid element of the
|
||||
"rfc_2822_cc" field when creating a <Ticket> instance.
|
||||
"""
|
||||
@ -305,7 +305,7 @@ class EmailInteractionsTestCase(TestCase):
|
||||
msg.set_payload(self.ticket_data['description'])
|
||||
|
||||
email_count = len(mail.outbox)
|
||||
|
||||
|
||||
object_from_message(str(msg), self.queue_public, logger=logger)
|
||||
|
||||
followup = FollowUp.objects.get(message_id=message_id)
|
||||
@ -315,19 +315,19 @@ class EmailInteractionsTestCase(TestCase):
|
||||
# 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)
|
||||
# the new and update queues (+2)
|
||||
self.assertEqual(email_count + 1 + 2 + 2, len(mail.outbox))
|
||||
|
||||
# Ensure that the submitter is notified
|
||||
self.assertIn(submitter_email,mail.outbox[0].to)
|
||||
self.assertIn(submitter_email, mail.outbox[0].to)
|
||||
|
||||
# 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])
|
||||
|
||||
|
||||
for cc_email in cc_list:
|
||||
|
||||
# Ensure that contacts on cc_list will be notified on the same email (index 0)
|
||||
#self.assertIn(cc_email, mail.outbox[0].to)
|
||||
# self.assertIn(cc_email, mail.outbox[0].to)
|
||||
|
||||
# Ensure that <TicketCC> exists
|
||||
ticket_cc = TicketCC.objects.get(ticket=ticket, email=cc_email)
|
||||
@ -335,8 +335,7 @@ class EmailInteractionsTestCase(TestCase):
|
||||
self.assertTrue(ticket_cc.email, cc_email)
|
||||
|
||||
def test_create_ticket_from_email_with_invalid_carbon_copy(self):
|
||||
|
||||
"""
|
||||
"""
|
||||
Ensure that no <TicketCC> instance is created if an invalid element of the
|
||||
"rfc_2822_cc" field is provided when creating a <Ticket> instance.
|
||||
"""
|
||||
@ -366,16 +365,16 @@ class EmailInteractionsTestCase(TestCase):
|
||||
# As we have created an Ticket from an email, we notify:
|
||||
# the submitter (+1)
|
||||
# contacts on the cc_list (+2),
|
||||
# the new and update queues (+2)
|
||||
# the new and update queues (+2)
|
||||
self.assertEqual(email_count + 1 + 2 + 2, len(mail.outbox))
|
||||
|
||||
# Ensure that the submitter is notified
|
||||
self.assertIn(submitter_email, mail.outbox[0].to)
|
||||
|
||||
|
||||
for cc_email in cc_list:
|
||||
|
||||
# Ensure that contacts on cc_list will be notified on the same email (index 0)
|
||||
#self.assertIn(cc_email, mail.outbox[0].to)
|
||||
# self.assertIn(cc_email, mail.outbox[0].to)
|
||||
|
||||
# Ensure that <TicketCC> exists. Even if it's an invalid email.
|
||||
ticket_cc = TicketCC.objects.get(ticket=ticket, email=cc_email)
|
||||
@ -383,14 +382,12 @@ class EmailInteractionsTestCase(TestCase):
|
||||
self.assertTrue(ticket_cc.email, cc_email)
|
||||
|
||||
def test_create_followup_from_email_with_valid_message_id_with_no_initial_cc_list(self):
|
||||
|
||||
"""
|
||||
Ensure that if a message is received with an valid In-Reply-To ID,
|
||||
Ensure that if a message is received with an valid In-Reply-To ID,
|
||||
the expected <TicketCC> instances are created even if the there were
|
||||
no <TicketCC>s so far.
|
||||
"""
|
||||
|
||||
### Ticket and TicketCCs creation ###
|
||||
# Ticket and TicketCCs creation #
|
||||
msg = email.message.Message()
|
||||
|
||||
message_id = uuid.uuid4().hex
|
||||
@ -404,7 +401,7 @@ class EmailInteractionsTestCase(TestCase):
|
||||
msg.set_payload(self.ticket_data['description'])
|
||||
|
||||
email_count = len(mail.outbox)
|
||||
|
||||
|
||||
object_from_message(str(msg), self.queue_public, logger=logger)
|
||||
|
||||
followup = FollowUp.objects.get(message_id=message_id)
|
||||
@ -412,16 +409,16 @@ class EmailInteractionsTestCase(TestCase):
|
||||
|
||||
# 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),
|
||||
# the new and update queues (+2)
|
||||
# the new and update queues (+2)
|
||||
|
||||
# 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)
|
||||
# and the new and update queues (+2)
|
||||
expected_email_count = 1 + 2
|
||||
self.assertEqual(expected_email_count, len(mail.outbox))
|
||||
### end of the Ticket and TicketCCs creation ###
|
||||
# end of the Ticket and TicketCCs creation #
|
||||
|
||||
# Reply message
|
||||
reply = email.message.Message()
|
||||
@ -447,8 +444,8 @@ class EmailInteractionsTestCase(TestCase):
|
||||
|
||||
# Ensure that <TicketCC> is created
|
||||
for cc_email in cc_list:
|
||||
# Even after 2 messages with the same cc_list, <get> MUST return only
|
||||
# one object
|
||||
# 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)
|
||||
@ -463,24 +460,22 @@ class EmailInteractionsTestCase(TestCase):
|
||||
# As we have created a FollowUp from an email, we notify:
|
||||
# the sender (+1),
|
||||
# contacts on the cc_list (+2),
|
||||
# the new and update queues (+2)
|
||||
# the new and update queues (+2)
|
||||
|
||||
# Ensure that the submitter is notified
|
||||
#self.assertIn(submitter_email, mail.outbox[expected_email_count - 3].to)
|
||||
# self.assertIn(submitter_email, mail.outbox[expected_email_count - 3].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)
|
||||
# for cc_email in cc_list:
|
||||
# self.assertIn(cc_email, mail.outbox[expected_email_count - 1].to)
|
||||
|
||||
def test_create_followup_from_email_with_valid_message_id_with_original_cc_list_included(self):
|
||||
|
||||
"""
|
||||
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
|
||||
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
|
||||
overlap with the previous Cc list, no duplicates are created.
|
||||
"""
|
||||
|
||||
### Ticket and TicketCCs creation ###
|
||||
# Ticket and TicketCCs creation #
|
||||
msg = email.message.Message()
|
||||
|
||||
message_id = uuid.uuid4().hex
|
||||
@ -496,7 +491,7 @@ class EmailInteractionsTestCase(TestCase):
|
||||
msg.set_payload(self.ticket_data['description'])
|
||||
|
||||
email_count = len(mail.outbox)
|
||||
|
||||
|
||||
object_from_message(str(msg), self.queue_public, logger=logger)
|
||||
|
||||
followup = FollowUp.objects.get(message_id=message_id)
|
||||
@ -511,16 +506,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)
|
||||
# the new and update queues (+2)
|
||||
|
||||
# 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)
|
||||
# and the new and update queues (+2)
|
||||
expected_email_count = 1 + 2
|
||||
self.assertEqual(expected_email_count, len(mail.outbox))
|
||||
### end of the Ticket and TicketCCs creation ###
|
||||
# end of the Ticket and TicketCCs creation #
|
||||
|
||||
# Reply message
|
||||
reply = email.message.Message()
|
||||
@ -537,7 +532,7 @@ class EmailInteractionsTestCase(TestCase):
|
||||
reply.__setitem__('Cc', ','.join(cc_list))
|
||||
reply.__setitem__('Content-Type', 'text/plain;')
|
||||
reply.set_payload(self.ticket_data['description'])
|
||||
|
||||
|
||||
object_from_message(str(reply), self.queue_public, logger=logger)
|
||||
|
||||
followup = FollowUp.objects.get(message_id=message_id)
|
||||
@ -551,7 +546,7 @@ class EmailInteractionsTestCase(TestCase):
|
||||
|
||||
# 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),
|
||||
# the new and update queues (+2)
|
||||
# the new and update queues (+2)
|
||||
|
||||
# Ensure that the submitter is notified
|
||||
self.assertIn(submitter_email, mail.outbox[expected_email_count - 1].to)
|
||||
@ -560,21 +555,20 @@ class EmailInteractionsTestCase(TestCase):
|
||||
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
|
||||
# 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)
|
||||
|
||||
def test_create_followup_from_email_with_invalid_message_id(self):
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
|
||||
"""
|
||||
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
|
||||
"""
|
||||
|
||||
### Ticket and TicketCCs creation ###
|
||||
# Ticket and TicketCCs creation #
|
||||
msg = email.message.Message()
|
||||
|
||||
message_id = uuid.uuid4().hex
|
||||
@ -590,7 +584,7 @@ class EmailInteractionsTestCase(TestCase):
|
||||
msg.set_payload(self.ticket_data['description'])
|
||||
|
||||
email_count = len(mail.outbox)
|
||||
|
||||
|
||||
object_from_message(str(msg), self.queue_public, logger=logger)
|
||||
|
||||
followup = FollowUp.objects.get(message_id=message_id)
|
||||
@ -606,24 +600,24 @@ class EmailInteractionsTestCase(TestCase):
|
||||
# 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)
|
||||
# the new and update queues (+2)
|
||||
expected_email_count = 1 + 2 + 2
|
||||
self.assertEqual(expected_email_count, len(mail.outbox))
|
||||
|
||||
# Ensure that the submitter is notified
|
||||
self.assertIn(submitter_email,mail.outbox[0].to)
|
||||
self.assertIn(submitter_email, mail.outbox[0].to)
|
||||
|
||||
# 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)
|
||||
#self.assertIn(cc_email, mail.outbox[0].to)
|
||||
# self.assertIn(cc_email, mail.outbox[0].to)
|
||||
|
||||
ticket_cc = TicketCC.objects.get(ticket=ticket, email=cc_email)
|
||||
self.assertTrue(ticket_cc.ticket, ticket)
|
||||
self.assertTrue(ticket_cc.email, cc_email)
|
||||
|
||||
### end of the Ticket and TicketCCs creation ###
|
||||
# end of the Ticket and TicketCCs creation #
|
||||
|
||||
# Reply message
|
||||
reply = email.message.Message()
|
||||
@ -645,18 +639,17 @@ class EmailInteractionsTestCase(TestCase):
|
||||
reply.set_payload(self.ticket_data['description'])
|
||||
|
||||
email_count = len(mail.outbox)
|
||||
|
||||
|
||||
object_from_message(str(reply), self.queue_public, logger=logger)
|
||||
|
||||
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:
|
||||
# Even after 2 messages with the same cc_list, <get> MUST return only
|
||||
# one object
|
||||
# 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)
|
||||
@ -668,12 +661,12 @@ class EmailInteractionsTestCase(TestCase):
|
||||
self.assertEqual(email_count + 1 + 2 + 2, len(mail.outbox))
|
||||
|
||||
def test_create_ticket_from_email_to_a_notification_enabled_queue(self):
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
|
||||
"""
|
||||
Ensure that when an email is sent to a Queue with notifications_enabled turned ON,
|
||||
and a <Ticket> is created, all contacts n the TicketCC list are notified.
|
||||
"""
|
||||
|
||||
msg = email.message.Message()
|
||||
|
||||
message_id = uuid.uuid4().hex
|
||||
@ -690,7 +683,6 @@ class EmailInteractionsTestCase(TestCase):
|
||||
|
||||
email_count = len(mail.outbox)
|
||||
object_from_message(str(msg), self.queue_public, logger=logger)
|
||||
|
||||
|
||||
followup = FollowUp.objects.get(message_id=message_id)
|
||||
ticket = Ticket.objects.get(id=followup.ticket.id)
|
||||
@ -709,21 +701,20 @@ class EmailInteractionsTestCase(TestCase):
|
||||
for cc_email in cc_list:
|
||||
|
||||
# Ensure that contacts on cc_list will be notified on the same email (index 0)
|
||||
#self.assertIn(cc_email, mail.outbox[0].to)
|
||||
# self.assertIn(cc_email, mail.outbox[0].to)
|
||||
|
||||
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):
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
|
||||
msg = email.message.Message()
|
||||
|
||||
message_id = uuid.uuid4().hex
|
||||
@ -739,7 +730,7 @@ class EmailInteractionsTestCase(TestCase):
|
||||
msg.set_payload(self.ticket_data['description'])
|
||||
|
||||
email_count = len(mail.outbox)
|
||||
|
||||
|
||||
object_from_message(str(msg), self.queue_public_with_notifications_disabled, logger=logger)
|
||||
|
||||
followup = FollowUp.objects.get(message_id=message_id)
|
||||
@ -752,7 +743,7 @@ class EmailInteractionsTestCase(TestCase):
|
||||
# and that's it because we've disabled queue notifications
|
||||
self.assertEqual(email_count + 1 + 2, len(mail.outbox))
|
||||
|
||||
# Ensure that <TicketCC> is created even if the Queue notifications are disabled
|
||||
# Ensure that <TicketCC> is created even if the Queue notifications are disabled
|
||||
# so when staff members interact with the <Ticket>, they get notified
|
||||
for cc_email in cc_list:
|
||||
|
||||
@ -764,13 +755,12 @@ class EmailInteractionsTestCase(TestCase):
|
||||
self.assertTrue(ticket_cc.email, cc_email)
|
||||
|
||||
def test_create_followup_from_email_to_a_notification_enabled_queue(self):
|
||||
|
||||
"""
|
||||
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.
|
||||
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.
|
||||
"""
|
||||
|
||||
### Ticket and TicketCCs creation ###
|
||||
# Ticket and TicketCCs creation #
|
||||
msg = email.message.Message()
|
||||
|
||||
message_id = uuid.uuid4().hex
|
||||
@ -786,7 +776,7 @@ class EmailInteractionsTestCase(TestCase):
|
||||
msg.set_payload(self.ticket_data['description'])
|
||||
|
||||
email_count = len(mail.outbox)
|
||||
|
||||
|
||||
object_from_message(str(msg), self.queue_public, logger=logger)
|
||||
|
||||
followup = FollowUp.objects.get(message_id=message_id)
|
||||
@ -796,7 +786,7 @@ class EmailInteractionsTestCase(TestCase):
|
||||
# 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)
|
||||
# the new and update queues (+2)
|
||||
expected_email_count = email_count + 1 + 2 + 2
|
||||
self.assertEqual(expected_email_count, len(mail.outbox))
|
||||
|
||||
@ -804,12 +794,12 @@ class EmailInteractionsTestCase(TestCase):
|
||||
for cc_email in cc_list:
|
||||
|
||||
# Ensure that contacts on cc_list will be notified on the same email (index 0)
|
||||
#self.assertIn(cc_email, mail.outbox[0].to)
|
||||
# self.assertIn(cc_email, mail.outbox[0].to)
|
||||
|
||||
ticket_cc = TicketCC.objects.get(ticket=ticket, email=cc_email)
|
||||
self.assertTrue(ticket_cc.ticket, ticket)
|
||||
self.assertTrue(ticket_cc.email, cc_email)
|
||||
### end of the Ticket and TicketCCs creation ###
|
||||
# end of the Ticket and TicketCCs creation #
|
||||
|
||||
# Reply message
|
||||
reply = email.message.Message()
|
||||
@ -842,7 +832,7 @@ class EmailInteractionsTestCase(TestCase):
|
||||
for cc_email in cc_list:
|
||||
|
||||
# Ensure that contacts on cc_list will be notified on the same email (index 0)
|
||||
#self.assertIn(cc_email, mail.outbox[expected_email_count - 1].to)
|
||||
# self.assertIn(cc_email, mail.outbox[expected_email_count - 1].to)
|
||||
|
||||
ticket_cc = TicketCC.objects.get(ticket=ticket, email=cc_email)
|
||||
self.assertTrue(ticket_cc.ticket, ticket)
|
||||
@ -853,8 +843,7 @@ class EmailInteractionsTestCase(TestCase):
|
||||
Ensure that when an email is sent to a Queue with notifications_enabled
|
||||
turned OFF, and a <FollowUp> is created, TicketCC is NOT notified.
|
||||
"""
|
||||
|
||||
### Ticket and TicketCCs creation ###
|
||||
# Ticket and TicketCCs creation #
|
||||
msg = email.message.Message()
|
||||
|
||||
message_id = uuid.uuid4().hex
|
||||
@ -870,7 +859,7 @@ class EmailInteractionsTestCase(TestCase):
|
||||
msg.set_payload(self.ticket_data['description'])
|
||||
|
||||
email_count = len(mail.outbox)
|
||||
|
||||
|
||||
object_from_message(str(msg), self.queue_public_with_notifications_disabled, logger=logger)
|
||||
|
||||
followup = FollowUp.objects.get(message_id=message_id)
|
||||
@ -879,10 +868,9 @@ class EmailInteractionsTestCase(TestCase):
|
||||
|
||||
# As we have created an Ticket from an email, we notify:
|
||||
# the sender (+1),
|
||||
# the new and update queues (+2)
|
||||
# the new and update queues (+2)
|
||||
expected_email_count = email_count + 1 + 2
|
||||
self.assertEqual(expected_email_count, len(mail.outbox))
|
||||
|
||||
|
||||
# Ensure that <TicketCC> is created
|
||||
for cc_email in cc_list:
|
||||
@ -893,7 +881,7 @@ class EmailInteractionsTestCase(TestCase):
|
||||
ticket_cc = TicketCC.objects.get(ticket=ticket, email=cc_email)
|
||||
self.assertTrue(ticket_cc.ticket, ticket)
|
||||
self.assertTrue(ticket_cc.email, cc_email)
|
||||
### end of the Ticket and TicketCCs creation ###
|
||||
# end of the Ticket and TicketCCs creation #
|
||||
|
||||
# Reply message
|
||||
reply = email.message.Message()
|
||||
@ -920,16 +908,14 @@ class EmailInteractionsTestCase(TestCase):
|
||||
expected_email_count += 1
|
||||
self.assertEqual(expected_email_count, len(mail.outbox))
|
||||
|
||||
|
||||
def test_create_followup_from_email_with_valid_message_id_with_original_cc_list_included(self):
|
||||
|
||||
"""
|
||||
Ensure that if a message is received with an valid In-Reply-To ID,
|
||||
Ensure that if a message is received with an valid In-Reply-To ID,
|
||||
the expected <TicketCC> instances are created even if the there were
|
||||
no <TicketCC>s so far.
|
||||
"""
|
||||
|
||||
### Ticket and TicketCCs creation ###
|
||||
# Ticket and TicketCCs creation #
|
||||
msg = email.message.Message()
|
||||
|
||||
message_id = uuid.uuid4().hex
|
||||
@ -943,12 +929,12 @@ class EmailInteractionsTestCase(TestCase):
|
||||
msg.set_payload(self.ticket_data['description'])
|
||||
|
||||
email_count = len(mail.outbox)
|
||||
|
||||
|
||||
object_from_message(str(msg), self.queue_public, logger=logger)
|
||||
|
||||
followup = FollowUp.objects.get(message_id=message_id)
|
||||
ticket = Ticket.objects.get(id=followup.ticket.id)
|
||||
### end of the Ticket and TicketCCs creation ###
|
||||
# end of the Ticket and TicketCCs creation #
|
||||
|
||||
# Reply message
|
||||
reply = email.message.Message()
|
||||
@ -974,8 +960,8 @@ class EmailInteractionsTestCase(TestCase):
|
||||
|
||||
# Ensure that <TicketCC> is created
|
||||
for cc_email in cc_list:
|
||||
# Even after 2 messages with the same cc_list, <get> MUST return only
|
||||
# one object
|
||||
# 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)
|
||||
@ -988,5 +974,5 @@ class EmailInteractionsTestCase(TestCase):
|
||||
# submitter: +1
|
||||
# cc_list: +2
|
||||
# public_update_queue: +1
|
||||
expected_email_count += 1 + 2 + 1
|
||||
expected_email_count += 1 + 2 + 1
|
||||
self.assertEqual(expected_email_count, len(mail.outbox))
|
||||
|
@ -388,6 +388,7 @@ def return_ticketccstring_and_show_subscribe(user, ticket):
|
||||
|
||||
return ticketcc_string, show_subscribe
|
||||
|
||||
|
||||
def subscribe_to_ticket_updates(ticket, user=None, email=None, can_view=True, can_update=False):
|
||||
|
||||
if ticket is not None:
|
||||
@ -400,8 +401,8 @@ def subscribe_to_ticket_updates(ticket, user=None, email=None, can_view=True, ca
|
||||
|
||||
if user is None and len(email) < 5:
|
||||
raise ValidationError(
|
||||
_('When you add somebody on Cc, you must provide either a User or a valid email. Email: %s' %email)
|
||||
)
|
||||
_('When you add somebody on Cc, you must provide either a User or a valid email. Email: %s' % email)
|
||||
)
|
||||
|
||||
ticketcc = TicketCC(
|
||||
ticket=ticket,
|
||||
@ -411,14 +412,14 @@ def subscribe_to_ticket_updates(ticket, user=None, email=None, can_view=True, ca
|
||||
can_update=can_update
|
||||
)
|
||||
ticketcc.save()
|
||||
|
||||
|
||||
return ticketcc
|
||||
|
||||
|
||||
def subscribe_staff_member_to_ticket(ticket, user, email=''):
|
||||
"""used in view_ticket() and update_ticket()"""
|
||||
return subscribe_to_ticket_updates(ticket=ticket, user=user, email=email, can_view=can_view, can_update=can_update)
|
||||
|
||||
|
||||
|
||||
def update_ticket(request, ticket_id, public=False):
|
||||
if not (public or (
|
||||
|
Loading…
Reference in New Issue
Block a user