Browse Source
Merge pull request #1 from ntsirintanis/9.0-mig-mail_edit
Merge pull request #1 from ntsirintanis/9.0-mig-mail_edit
[ADD] unit testspull/356/head
Giovanni Capalbo (Therp)
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 98 additions and 0 deletions
-
1mail_edit/README.rst
-
1mail_edit/__init__.py
-
5mail_edit/tests/__init__.py
-
91mail_edit/tests/test_mail_edit.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 |
@ -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': '<p>This is not a test message</p>', |
|||
}) |
|||
|
|||
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)) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue