mirror of
https://gitea.mueller.network/extern/django-helpdesk.git
synced 2024-11-22 07:53:19 +01:00
PEP-8 fixes for mail threading merge
This commit is contained in:
parent
5f0d22a692
commit
43ed3ac773
@ -355,7 +355,7 @@ def create_object_from_email_message(message, ticket_id, payload, files, logger)
|
||||
date=now,
|
||||
public=True,
|
||||
comment=payload['body'],
|
||||
message_id = message_id,
|
||||
message_id=message_id
|
||||
)
|
||||
|
||||
if ticket.status == Ticket.REOPENED_STATUS:
|
||||
@ -376,7 +376,7 @@ 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):
|
||||
|
||||
@ -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},
|
||||
)
|
||||
@ -532,4 +532,3 @@ def object_from_message(message, queue, logger):
|
||||
}
|
||||
|
||||
return create_object_from_email_message(message, ticket, payload, files, logger=logger)
|
||||
|
||||
|
@ -139,11 +139,13 @@ 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',
|
||||
self.queue_public = Queue.objects.create(
|
||||
title='Mail Queue 1',
|
||||
slug='mq1',
|
||||
email_address='queue-1@example.com',
|
||||
allow_public_submission=True,
|
||||
@ -152,7 +154,8 @@ class EmailInteractionsTestCase(TestCase):
|
||||
enable_notifications_on_email_events=True,
|
||||
)
|
||||
|
||||
self.queue_public_with_notifications_disabled = Queue.objects.create(title='Mail Queue 2',
|
||||
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,
|
||||
@ -235,7 +238,6 @@ class EmailInteractionsTestCase(TestCase):
|
||||
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.
|
||||
@ -272,7 +274,6 @@ class EmailInteractionsTestCase(TestCase):
|
||||
# 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)
|
||||
@ -284,7 +285,6 @@ 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.
|
||||
@ -335,7 +335,6 @@ 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.
|
||||
@ -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,
|
||||
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
|
||||
@ -421,7 +418,7 @@ class EmailInteractionsTestCase(TestCase):
|
||||
# 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()
|
||||
@ -473,14 +470,12 @@ class EmailInteractionsTestCase(TestCase):
|
||||
# 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
|
||||
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
|
||||
@ -520,7 +515,7 @@ class EmailInteractionsTestCase(TestCase):
|
||||
# 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()
|
||||
@ -567,14 +562,13 @@ class EmailInteractionsTestCase(TestCase):
|
||||
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
|
||||
@ -623,7 +617,7 @@ class EmailInteractionsTestCase(TestCase):
|
||||
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()
|
||||
@ -652,7 +646,6 @@ class EmailInteractionsTestCase(TestCase):
|
||||
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
|
||||
@ -668,10 +661,10 @@ 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 n 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 in the TicketCC list are notified.
|
||||
"""
|
||||
|
||||
msg = email.message.Message()
|
||||
@ -691,7 +684,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)
|
||||
self.assertEqual(ticket.ticket_for_url, "mq1-%s" % ticket.id)
|
||||
@ -715,13 +707,12 @@ class EmailInteractionsTestCase(TestCase):
|
||||
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()
|
||||
@ -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
|
||||
@ -809,7 +799,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()
|
||||
@ -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
|
||||
@ -883,7 +872,6 @@ class EmailInteractionsTestCase(TestCase):
|
||||
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,
|
||||
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
|
||||
@ -948,7 +934,7 @@ class EmailInteractionsTestCase(TestCase):
|
||||
|
||||
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()
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user