diff --git a/mail_edit/README.rst b/mail_edit/README.rst index 2ff511dd..e8f9e2ee 100644 --- a/mail_edit/README.rst +++ b/mail_edit/README.rst @@ -63,6 +63,7 @@ Contributors * George Daramouskas * Holger Brunn * Giovanni Francesco Capalbo +* Nikos Tsirintanis Maintainer ---------- diff --git a/mail_edit/__init__.py b/mail_edit/__init__.py index 94469cde..662943ae 100644 --- a/mail_edit/__init__.py +++ b/mail_edit/__init__.py @@ -3,3 +3,4 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from . import models +from . import tests diff --git a/mail_edit/tests/__init__.py b/mail_edit/tests/__init__.py new file mode 100644 index 00000000..dfce47fe --- /dev/null +++ b/mail_edit/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# flake8: noqa + +from . import test_mail_edit diff --git a/mail_edit/tests/test_mail_edit.py b/mail_edit/tests/test_mail_edit.py new file mode 100644 index 00000000..4a3795fd --- /dev/null +++ b/mail_edit/tests/test_mail_edit.py @@ -0,0 +1,91 @@ +# -*- coding: utf-8 -*- +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openerp.tests.common import TransactionCase + + +class TestMailEdit(TransactionCase): + + def setUp(self, *args, **kwargs): + # make sale.order and res_partner allowed to edit + super(TestMailEdit, self).setUp(*args, **kwargs) + self.rrl_partner = self.env['res.request.link'].create({ + 'name': 'A partner', + 'object': 'res.partner', + 'priority': 1, + 'mail_edit': True, + }) + self.rrl_partner_2 = self.env['res.request.link'].create({ + 'name': 'Another partner', + 'object': 'res.partner', + 'priority': 2, + 'mail_edit': True, + }) + self.sender = self.env['res.partner'].create({ + 'name': 'Test sender', + 'email': 'sender@example.com', + 'notify_email': 'always', + }) + self.recipient = self.env['res.partner'].create({ + 'name': 'Test recipient', + 'email': 'recipient@example.com', + 'notify_email': 'always', + }) + self.message = self.env['mail.message'].create({ + 'subject': 'Message test', + 'author_id': self.sender.id, + 'email_from': self.sender.email, + 'message_type': 'comment', + 'model': 'res.partner', + 'res_id': self.recipient.id, + 'partner_ids': [(4, self.recipient.id)], + 'body': '

This is not a test message

', + }) + + def test_change_destination_object(self): + objects = self.message._get_model_selection() + self.assertEqual(len(objects), 3) + self.assertFalse(self.message.destination_object_id) + self.assertTrue( + self.message.model and + self.message.res_id and + self.message.record_name + ) + # call onchange manually to nullify .model, .res_id, .record_name + self.message.change_destination_object() + self.assertFalse( + self.message.model and + self.message.res_id and + self.message.record_name + ) + # create an arbitrary object from base + arbitrary_object = self.env['res.request.link'].create({ + 'name': 'Colombia', + 'object': 'res.country', + 'priority': 3, + 'mail_edit': True, + }) + # recalculate selection to include arbitrary_object + self.message._get_model_selection() + # Set a value to reference field + self.message.destination_object_id = "{},{}".format( + arbitrary_object.object, arbitrary_object.id + ) + self.assertTrue(self.message.destination_object_id) + # call onchange manually to get values from reference + self.message.change_destination_object() + self.assertTrue( + self.message.model and + self.message.res_id and + self.message.record_name + ) + self.assertEqual(self.message.model, 'res.country') + self.assertEqual(self.message.res_id, arbitrary_object.id) + + def test_message_read_dict_postprocess(self): + message = [self.message._message_read_dict()] + all_messages = self.env['mail.message'].search([]) + message_tree = dict((m.id, m) for m in all_messages) + # do stuff to the message + self.message._message_read_dict_postprocess(message, message_tree) + message_list = self.message.message_format() + self.assertTrue(message_list[0].get('is_superuser', False))