Browse Source

fixup! fixup! fixup! fixup! fixup! [ADD] mail_embed_image module

pull/404/head
George Daramouskas 5 years ago
parent
commit
7be0398c2e
No known key found for this signature in database GPG Key ID: 5B4EF742F8CD859C
  1. 2
      mail_embed_image/models/ir_mail_server.py
  2. 28
      mail_embed_image/tests/test_mail_embed_image.py

2
mail_embed_image/models/ir_mail_server.py

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Therp BV <https://therp.nl>
# 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

28
mail_embed_image/tests/test_mail_embed_image.py

@ -2,6 +2,7 @@
# Copyright 2019 Therp BV <https://therp.nl>
# 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 = '<div>this is an email</div>'
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 = """
<div>
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])

Loading…
Cancel
Save