From 7be0398c2e06a3a2e3866198f3cd3586e0c28501 Mon Sep 17 00:00:00 2001 From: George Daramouskas Date: Fri, 28 Jun 2019 11:00:31 +0200 Subject: [PATCH] fixup! fixup! fixup! fixup! fixup! [ADD] mail_embed_image module --- mail_embed_image/models/ir_mail_server.py | 2 +- .../tests/test_mail_embed_image.py | 28 +++++++++++-------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/mail_embed_image/models/ir_mail_server.py b/mail_embed_image/models/ir_mail_server.py index dc44cdab..7f95adf0 100644 --- a/mail_embed_image/models/ir_mail_server.py +++ b/mail_embed_image/models/ir_mail_server.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- # Copyright 2019 Therp BV # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -import requests import uuid +import requests from odoo import models from odoo.addons.base.ir.ir_mail_server import encode_header_param from lxml.html.soupparser import fromstring diff --git a/mail_embed_image/tests/test_mail_embed_image.py b/mail_embed_image/tests/test_mail_embed_image.py index 810fd69a..002ee211 100644 --- a/mail_embed_image/tests/test_mail_embed_image.py +++ b/mail_embed_image/tests/test_mail_embed_image.py @@ -2,6 +2,7 @@ # Copyright 2019 Therp BV # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo.tests.common import TransactionCase +from mock import patch from requests import get from base64 import b64encode from lxml.html.soupparser import fromstring @@ -13,7 +14,11 @@ class TestMailEmbedImage(TransactionCase): post_install = True at_install = False - def test_mail_embed_image(self): + @patch( + 'odoo.fields.html_sanitize', + side_effect=lambda *args, **kwargs: args[0], + ) + def test_mail_embed_image(self, html_sanitize): """ The following are tested here: 1) Create an email with no image, send it. 2) Create an email with three images, one base64 content, one http @@ -27,12 +32,13 @@ class TestMailEmbedImage(TransactionCase): image_url = base_url + '/mail_embed_image/static/description/icon.png' image = get(image_url).content body1 = '
this is an email
' - email1 = model_mail_mail.create({'body': body1}) + email1 = model_mail_mail.create({ + 'body_html': body1, + 'body': body1, + 'email_to': 'test@example.com', + }) email1.send() - message_body = self.env.cr.execute( - "SELECT body FROM mail_message WHERE message_id = %s LIMIT 1", - (email1.message_id, )) - self.assertEquals(message_body, body1) + self.assertEquals(email1.body_html, body1) body2 = """
this is an email @@ -44,12 +50,12 @@ class TestMailEmbedImage(TransactionCase): image_url, '/web/image/res.partner/1/image', ) - email2 = model_mail_mail.create({'body': body2}) + email2 = model_mail_mail.create({ + 'body_html': body2, + 'email_to': 'test@example.com', + }) email2.send() - message_body = self.env.cr.execute( - "SELECT body FROM mail_message WHERE message_id = %s LIMIT 1", - (email1.message_id, )) - body2final = fromstring(message_body) + body2final = fromstring(email2.body_html) self.assertEquals(len(body2final.xpath('//img')), 3) srcs = [x.get('src') for x in body2final.xpath('//img')] self.assertIn('base64:', srcs[0])