Skip to content

Commit abd375a

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@1c20511 Part-of: odoo#82330
1 parent c20e3b9 commit abd375a

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

odoo/addons/base/tests/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from . import test_ir_cron
1919
from . import test_ir_http
2020
from . import test_ir_filters
21+
from . import test_ir_mail_server
2122
from . import test_ir_model
2223
from . import test_ir_sequence
2324
from . import test_ir_sequence_date_range
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# -*- coding: utf-8 -*-
2+
# Part of Odoo. See LICENSE file for full copyright and licensing details.
3+
4+
from odoo import tools
5+
from odoo.addons.base.tests import test_mail_examples
6+
from odoo.tests import tagged
7+
from odoo.tests.common import TransactionCase
8+
9+
10+
@tagged('mail_server')
11+
class TestIrMailServer(TransactionCase):
12+
13+
def test_mail_body(self):
14+
bodies = [
15+
'content',
16+
'<p>content</p>',
17+
'<head><meta content="text/html; charset=utf-8" http-equiv="Content-Type"></head><body><p>content</p></body>',
18+
test_mail_examples.MISC_HTML_SOURCE,
19+
test_mail_examples.QUOTE_THUNDERBIRD_HTML,
20+
]
21+
expected_list = [
22+
'content',
23+
'content',
24+
'content',
25+
"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'\))",
26+
'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 ',
27+
]
28+
for body, expected in zip(bodies, expected_list):
29+
message = self.env['ir.mail_server'].build_email(
30+
31+
32+
body=body,
33+
subject='Subject',
34+
subtype='html',
35+
)
36+
body_alternative = False
37+
for part in message.walk():
38+
if part.get_content_maintype() == 'multipart':
39+
continue # skip container
40+
if part.get_content_type() == 'text/plain':
41+
if not part.get_payload():
42+
continue
43+
body_alternative = tools.ustr(part.get_content())
44+
# remove ending new lines as it just adds noise
45+
body_alternative = body_alternative.strip('\n')
46+
self.assertEqual(body_alternative, expected)

0 commit comments

Comments
 (0)