[IMP] base: test body alternative done in build_email
Purpose of this commit is to add some tests about body alternative done in build_email when none is given. It uses a library we are about to remove and testing it is therefore necessary. Task-2702034 X-original-commit: 92b102c87bbdb9073f794a414a41460e4146acd2 Part-of: odoo/odoo#82486
This commit is contained in:
@@ -20,6 +20,7 @@ from . import test_ir_attachment
|
||||
from . import test_ir_cron
|
||||
from . import test_ir_http
|
||||
from . import test_ir_filters
|
||||
from . import test_ir_mail_server
|
||||
from . import test_ir_model
|
||||
from . import test_ir_sequence
|
||||
from . import test_ir_sequence_date_range
|
||||
@@ -51,4 +52,3 @@ from . import test_form_create
|
||||
from . import test_cloc
|
||||
from . import test_profiler
|
||||
from . import test_pdf
|
||||
from . import test_ir_mail_server
|
||||
|
||||
@@ -3,10 +3,15 @@
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from odoo import tools
|
||||
from odoo.addons.base.tests import test_mail_examples
|
||||
from odoo.addons.base.tests.common import MockSmtplibCase
|
||||
from odoo.tests import tagged
|
||||
from odoo.tests.common import TransactionCase
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
|
||||
@tagged('mail_server')
|
||||
class TestIrMailServer(TransactionCase, MockSmtplibCase):
|
||||
|
||||
def setUp(self):
|
||||
@@ -48,6 +53,41 @@ class TestIrMailServer(TransactionCase, MockSmtplibCase):
|
||||
for email, from_filter in tests:
|
||||
self.assertFalse(match_from_filter(email, from_filter))
|
||||
|
||||
def test_mail_body(self):
|
||||
bodies = [
|
||||
'content',
|
||||
'<p>content</p>',
|
||||
'<head><meta content="text/html; charset=utf-8" http-equiv="Content-Type"></head><body><p>content</p></body>',
|
||||
test_mail_examples.MISC_HTML_SOURCE,
|
||||
test_mail_examples.QUOTE_THUNDERBIRD_HTML,
|
||||
]
|
||||
expected_list = [
|
||||
'content',
|
||||
'content',
|
||||
'content',
|
||||
"test1\n\n**test2**\n\n_test3_\n\n_test4_\n\n~~test5~~\n\ntest6\n\n * test7\n * test8\n\n 1. test9\n 2. test10\n\n> test11\n\n> > test12\n>>\n\n>> \n>\n\n[google](http://google.com) [test link](javascript:alert\('malicious code'\))",
|
||||
'On 01/05/2016 10:24 AM, Raoul Poilvache wrote: \n\n> **_Test reply. The suite._** \n>\n>\n> \n>\n>\n> \-- \n>\n>\n> Raoul Poilvache\n\nTop cool !!! \n \n\n \n \n -- \n Raoul Poilvache\n ',
|
||||
]
|
||||
for body, expected in zip(bodies, expected_list):
|
||||
message = self.env['ir.mail_server'].build_email(
|
||||
'john.doe@from.example.com',
|
||||
'destinataire@to.example.com',
|
||||
body=body,
|
||||
subject='Subject',
|
||||
subtype='html',
|
||||
)
|
||||
body_alternative = False
|
||||
for part in message.walk():
|
||||
if part.get_content_maintype() == 'multipart':
|
||||
continue # skip container
|
||||
if part.get_content_type() == 'text/plain':
|
||||
if not part.get_payload():
|
||||
continue
|
||||
body_alternative = tools.ustr(part.get_content())
|
||||
# remove ending new lines as it just adds noise
|
||||
body_alternative = body_alternative.strip('\n')
|
||||
self.assertEqual(body_alternative, expected)
|
||||
|
||||
@mute_logger('odoo.models.unlink')
|
||||
def test_mail_server_priorities(self):
|
||||
"""Test if we choose the right mail server to send an email.
|
||||
|
||||
Reference in New Issue
Block a user