summaryrefslogtreecommitdiff
path: root/addons/mail/tests
diff options
context:
space:
mode:
authorXavier Morel <xmo@odoo.com>2017-04-28 15:32:10 +0200
committerOlivier Dony <odo@openerp.com>2017-08-20 23:25:54 +0200
commit3824b5dcc13678d3985ad45ac21dcf9ac9202c20 (patch)
tree46502fb28fc4716c78da39a9ada868a0992fcc12 /addons/mail/tests
parent1b6871319d1a8b76b3e61ff258dcc4d514d40471 (diff)
[FIX] P3: fix base64 and StringIO uses
* StringIO removed from stdlib, replace with io * try to correctly handle BytesIO/StringIO (one is for bytes the other is for text) * fix base64: Python 3 removed bytes-encoding and bytes-bytes codecs (via #encode) so replace all calls to str.encode('base64'), also b64encode is a bytes->bytes conversion so attempt to properly handle that issue #8530
Diffstat (limited to 'addons/mail/tests')
-rw-r--r--addons/mail/tests/test_mail_features.py7
-rw-r--r--addons/mail/tests/test_mail_message.py4
-rw-r--r--addons/mail/tests/test_mail_template.py4
3 files changed, 8 insertions, 7 deletions
diff --git a/addons/mail/tests/test_mail_features.py b/addons/mail/tests/test_mail_features.py
index 92613f55e51..a6fce59c10a 100644
--- a/addons/mail/tests/test_mail_features.py
+++ b/addons/mail/tests/test_mail_features.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
+import base64
from odoo.addons.mail.tests.common import TestMail
from odoo.addons.mail.tests.test_mail_gateway import MAIL_TEMPLATE_PLAINTEXT
@@ -89,8 +90,8 @@ class TestMessagePost(TestMail):
_body, _body_alt = '<p>Test Body</p>', 'Test Body'
_subject = 'Test Subject'
_attachments = [
- ('List1', 'My first attachment'),
- ('List2', 'My second attachment')
+ ('List1', b'My first attachment'),
+ ('List2', b'My second attachment')
]
_attach_1 = self.env['ir.attachment'].sudo(self.user_employee).create({
'name': 'Attach1', 'datas_fname': 'Attach1',
@@ -129,7 +130,7 @@ class TestMessagePost(TestMail):
'message_post: all atttachments should be linked to the mail.test model')
self.assertEqual(set(msg.attachment_ids.mapped('res_id')), set([self.test_pigs.id]),
'message_post: all atttachments should be linked to the pigs group')
- self.assertEqual(set([x.decode('base64') for x in msg.attachment_ids.mapped('datas')]),
+ self.assertEqual(set([base64.b64decode(x) for x in msg.attachment_ids.mapped('datas')]),
set(['migration test', _attachments[0][1], _attachments[1][1]]))
self.assertTrue(set([_attach_1.id, _attach_2.id]).issubset(msg.attachment_ids.ids),
'message_post: mail.message attachments duplicated')
diff --git a/addons/mail/tests/test_mail_message.py b/addons/mail/tests/test_mail_message.py
index db6dc9457a5..566a038d9ef 100644
--- a/addons/mail/tests/test_mail_message.py
+++ b/addons/mail/tests/test_mail_message.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
-
+import base64
import itertools
from odoo.addons.mail.tests.common import TestMail
@@ -215,7 +215,7 @@ class TestMailMessageAccess(TestMail):
def test_mail_message_access_read_notification(self):
attachment = self.env['ir.attachment'].create({
- 'datas': 'My attachment'.encode('base64'),
+ 'datas': base64.b64encode(b'My attachment'),
'name': 'doc.txt',
'datas_fname': 'doc.txt'})
# attach the attachment to the message
diff --git a/addons/mail/tests/test_mail_template.py b/addons/mail/tests/test_mail_template.py
index 60df04f0654..e5da1c628ae 100644
--- a/addons/mail/tests/test_mail_template.py
+++ b/addons/mail/tests/test_mail_template.py
@@ -17,13 +17,13 @@ class TestMailTemplate(TestMail):
'name': '_Test_First',
'datas_fname':
'first.txt',
- 'datas': base64.b64encode('My first attachment'),
+ 'datas': base64.b64encode(b'My first attachment'),
'res_model': 'res.partner',
'res_id': self.user_admin.partner_id.id
}, {
'name': '_Test_Second',
'datas_fname': 'second.txt',
- 'datas': base64.b64encode('My second attachment'),
+ 'datas': base64.b64encode(b'My second attachment'),
'res_model': 'res.partner',
'res_id': self.user_admin.partner_id.id
}]