Browse Source

Merge pull request #1 from ntsirintanis/9.0-mig-mail_edit

[ADD] unit tests
pull/356/head
Giovanni Capalbo (Therp) 6 years ago
committed by GitHub
parent
commit
2a09c92851
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      mail_edit/README.rst
  2. 1
      mail_edit/__init__.py
  3. 5
      mail_edit/tests/__init__.py
  4. 91
      mail_edit/tests/test_mail_edit.py

1
mail_edit/README.rst

@ -63,6 +63,7 @@ Contributors
* George Daramouskas <gdaramouskas@therp.nl>
* Holger Brunn <hbrunn@therp.nl>
* Giovanni Francesco Capalbo <giovanni@therp.nl>
* Nikos Tsirintanis <ntsirintanis@therp.nl>
Maintainer
----------

1
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

5
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

91
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': '<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))
Loading…
Cancel
Save