Skip to content
Snippets Groups Projects
Commit abd375a6 authored by Thibault Delavallée's avatar Thibault Delavallée
Browse files

[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: odoo/odoo@1c20511e056c5e8dfeefe0ece196c48f6eb7d42c
Part-of: odoo/odoo#82330
parent c20e3b95
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,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
......
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import tools
from odoo.addons.base.tests import test_mail_examples
from odoo.tests import tagged
from odoo.tests.common import TransactionCase
@tagged('mail_server')
class TestIrMailServer(TransactionCase):
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment