mirror of
https://gitea.mueller.network/extern/django-helpdesk.git
synced 2025-02-16 18:20:48 +01:00
Add test to verify that attachments as multipart are stored.
This commit is contained in:
parent
95e14b2ee7
commit
ae2f24b299
@ -12,7 +12,8 @@ import helpdesk.email
|
|||||||
from helpdesk.email import extract_part_data, object_from_message
|
from helpdesk.email import extract_part_data, object_from_message
|
||||||
from helpdesk.exceptions import DeleteIgnoredTicketException, IgnoreTicketException
|
from helpdesk.exceptions import DeleteIgnoredTicketException, IgnoreTicketException
|
||||||
from helpdesk.management.commands.get_email import Command
|
from helpdesk.management.commands.get_email import Command
|
||||||
from helpdesk.models import FollowUp, FollowUpAttachment, IgnoreEmail, Queue, Ticket, TicketCC
|
from helpdesk.models import FollowUp, FollowUpAttachment, IgnoreEmail, Queue, Ticket, TicketCC,\
|
||||||
|
Attachment
|
||||||
from helpdesk.tests import utils
|
from helpdesk.tests import utils
|
||||||
import itertools
|
import itertools
|
||||||
import logging
|
import logging
|
||||||
@ -231,6 +232,29 @@ class GetEmailCommonTests(TestCase):
|
|||||||
followup = ticket.followup_set.get()
|
followup = ticket.followup_set.get()
|
||||||
self.assertEqual(1, followup.followupattachment_set.count())
|
self.assertEqual(1, followup.followupattachment_set.count())
|
||||||
|
|
||||||
|
def test_email_with_multipart_as_attachment(self):
|
||||||
|
"""
|
||||||
|
Is a multipart attachment to an email correctly saved as an attachment
|
||||||
|
"""
|
||||||
|
att_filename = 'email_attachment.eml'
|
||||||
|
message, _, _ = utils.generate_multipart_email(type_list=['plain', 'html'])
|
||||||
|
email_attachment, _, _ = utils.generate_multipart_email(type_list=['plain', 'html'])
|
||||||
|
att_content = email_attachment.as_string()
|
||||||
|
message.attach(utils.generate_file_mime_part(filename=att_filename, content=att_content))
|
||||||
|
|
||||||
|
object_from_message(message.as_string(), self.queue_public, self.logger)
|
||||||
|
|
||||||
|
self.assertEqual(len(mail.outbox), 1)
|
||||||
|
self.assertEqual(f'[test-1] {message.get("subject")} (Opened)', mail.outbox[0].subject)
|
||||||
|
|
||||||
|
ticket = Ticket.objects.get()
|
||||||
|
followup = ticket.followup_set.get()
|
||||||
|
att_retrieved: Attachment = followup.followupattachment_set.get()
|
||||||
|
self.assertTrue(att_retrieved.filename.endswith(att_filename), "Filename of attached multipart not detected: %s" % (att_retrieved.filename))
|
||||||
|
with att_retrieved.file.open('r') as f:
|
||||||
|
retrieved_content = f.read()
|
||||||
|
self.assertEquals(att_content, retrieved_content, "Retrieved attachment content different to original :\n\n%s\n\n%s" % (att_content, retrieved_content))
|
||||||
|
|
||||||
|
|
||||||
class GetEmailParametricTemplate(object):
|
class GetEmailParametricTemplate(object):
|
||||||
"""TestCase that checks basic email functionality across methods and socks configs."""
|
"""TestCase that checks basic email functionality across methods and socks configs."""
|
||||||
|
Loading…
Reference in New Issue
Block a user