2018-12-27 09:26:36 +01:00
|
|
|
# Copyright 2017 Tecnativa - Pedro M. Baeza
|
2020-09-17 11:54:25 +02:00
|
|
|
# Copyright 2020 Onestein - Andrea Stirpe
|
2021-02-05 09:05:36 +01:00
|
|
|
# Copyright 2021 Sodexis
|
2021-09-14 10:38:47 +02:00
|
|
|
# Copyright 2021 Tecnativa - João Marques
|
2018-12-27 09:26:36 +01:00
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|
|
|
|
|
|
|
from odoo.tests import common
|
2020-09-17 11:54:25 +02:00
|
|
|
from odoo.tools.misc import mute_logger
|
2018-12-27 09:26:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TestMailDebrand(common.TransactionCase):
|
|
|
|
def setUp(self):
|
|
|
|
super().setUp()
|
2021-02-05 09:05:36 +01:00
|
|
|
self.default_template = self.env.ref("mail.message_notification_email")
|
|
|
|
self.paynow_template = self.env.ref("mail.mail_notification_paynow")
|
2018-12-27 09:26:36 +01:00
|
|
|
|
2021-03-15 19:44:13 +01:00
|
|
|
def test_debrand_binary_value(self):
|
|
|
|
"""
|
|
|
|
Regression test: ensure binary input is gracefully handled
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
self.env["mail.template"].remove_href_odoo(
|
|
|
|
b"Binary value with more than 20 characters"
|
|
|
|
)
|
|
|
|
except TypeError:
|
|
|
|
self.fail("Debranding binary string raised TypeError")
|
|
|
|
|
2018-12-27 09:26:36 +01:00
|
|
|
def test_default_debrand(self):
|
2021-02-05 09:05:36 +01:00
|
|
|
self.assertIn("using", self.default_template.arch)
|
|
|
|
res = self.env["mail.template"]._render_template(
|
|
|
|
self.default_template.arch, "ir.ui.view", [self.default_template]
|
|
|
|
)
|
2020-03-20 16:15:04 +01:00
|
|
|
self.assertNotIn("using", res)
|
2018-12-27 09:26:36 +01:00
|
|
|
|
|
|
|
def test_paynow_debrand(self):
|
2021-02-05 09:05:36 +01:00
|
|
|
self.assertIn("Powered by", self.paynow_template.arch)
|
|
|
|
res = self.env["mail.template"]._render_template(
|
|
|
|
self.paynow_template.arch, "ir.ui.view", [self.paynow_template]
|
|
|
|
)
|
2020-03-20 16:15:04 +01:00
|
|
|
self.assertNotIn("Powered by", res)
|
2020-09-17 11:54:25 +02:00
|
|
|
|
|
|
|
def test_lang_paynow_debrand(self):
|
|
|
|
with mute_logger("odoo.addons.base.models.ir_translation"):
|
|
|
|
self.env["base.language.install"].create(
|
|
|
|
{"lang": "nl_NL", "overwrite": True}
|
|
|
|
).lang_install()
|
|
|
|
with mute_logger("odoo.tools.translate"):
|
|
|
|
self.env["base.update.translations"].create({"lang": "nl_NL"}).act_update()
|
|
|
|
ctx = dict(lang="nl_NL")
|
2021-12-16 14:56:38 +01:00
|
|
|
paynow_arch = self.paynow_template.with_context(**ctx).arch
|
2020-09-17 11:54:25 +02:00
|
|
|
self.assertIn("Aangeboden door", paynow_arch)
|
2021-12-16 14:56:38 +01:00
|
|
|
res = self.env["mail.template"]
|
2020-09-17 11:54:25 +02:00
|
|
|
self.assertNotIn("Aangeboden door", res)
|
2021-05-25 22:07:40 +02:00
|
|
|
|
|
|
|
def test_plaintext_email(self):
|
|
|
|
MailMessage = self.env["mail.mail"]
|
|
|
|
email_values = {
|
|
|
|
"email_from": "customer@example.com",
|
|
|
|
"subject": "Hello",
|
|
|
|
"email_to": "contact@example.com",
|
|
|
|
"reply_to": "contact@example.com",
|
|
|
|
}
|
|
|
|
# No exception expected
|
|
|
|
MailMessage.create(email_values)
|
2021-09-14 10:38:47 +02:00
|
|
|
|
|
|
|
def test_body_intact(self):
|
|
|
|
"""The message body should never be changed"""
|
|
|
|
MailMessage = self.env["mail.mail"]
|
|
|
|
original_body = (
|
|
|
|
"<p>And if I send odoo.example.com<br><br>And odoo.com"
|
|
|
|
'<br><br>And <a target="_blank" rel="noreferrer noopener" '
|
|
|
|
'href="https://odoo.com">https://odoo.com</a><br><br>And '
|
|
|
|
'<a target="_blank" rel="noreferrer noopener" '
|
|
|
|
'href="https://odoo.example.com">https://odoo.example.com</a></p>'
|
|
|
|
)
|
|
|
|
email_values = {
|
|
|
|
"email_from": "customer@example.com",
|
|
|
|
"subject": "Hello",
|
|
|
|
"email_to": "contact@example.com",
|
|
|
|
"reply_to": "contact@example.com",
|
|
|
|
"body": original_body,
|
|
|
|
"body_html": (
|
|
|
|
"\n<div>\n\n\n<div><p>And if I send odoo.example.com<br><br>"
|
|
|
|
'And odoo.com<br><br>And <a target="_blank" '
|
|
|
|
'rel="noreferrer noopener" href="https://odoo.com">'
|
|
|
|
'https://odoo.com</a><br><br>And <a target="_blank" '
|
|
|
|
'rel="noreferrer noopener" href="https://odoo.example.com">'
|
|
|
|
"https://odoo.example.com</a></p></div>\n\n"
|
|
|
|
'<div style="font-size: 13px;"><span data-o-mail-quote="1">-- '
|
|
|
|
'<br data-o-mail-quote="1">\nAdministrator</span></div>\n'
|
|
|
|
'<p style="color: #555555; margin-top:32px;">\n Sent\n '
|
|
|
|
'<span>\n by\n <a style="text-decoration:none; '
|
|
|
|
'color: #875A7B;" href="http://www.example.com">\n '
|
|
|
|
"<span>YourCompany</span>\n </a>\n \n </span>\n "
|
|
|
|
'using\n <a target="_blank" '
|
|
|
|
'href="https://www.odoo.com?utm_source=db&utm_medium=email"'
|
|
|
|
' style="text-decoration:none; color: #875A7B;">Odoo'
|
|
|
|
"</a>.\n</p>\n</div>\n "
|
|
|
|
),
|
|
|
|
}
|
|
|
|
# No exception expected
|
|
|
|
message = MailMessage.create(email_values)
|
|
|
|
self.assertTrue(original_body in message._send_prepare_body())
|