[IMP] mail, test_mail: use bus mock tools in tests
Purpose is to use available tools, easier for debug and asserts than doing everything manually. It prepares future changes in channel model that may have an impact on bus notifications. LINKS Task ID-2070632 (main task) Task ID-2419762 (followup task) COM PR odoo/odoo#62859 ENT PR odoo/enterprise#15172 UPG PR odoo/upgrade#2005
This commit is contained in:
@@ -32,6 +32,10 @@ class MockEmail(common.BaseCase):
|
||||
('cancel', 'Cancelled')
|
||||
"""
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# GATEWAY MOCK
|
||||
# ------------------------------------------------------------
|
||||
|
||||
@contextmanager
|
||||
def mock_mail_gateway(self, mail_unlink_sent=False, sim_error=None):
|
||||
build_email_origin = IrMailServer.build_email
|
||||
|
||||
@@ -9,6 +9,8 @@ from odoo.tests import tagged, Form
|
||||
from odoo.tests.common import users
|
||||
from odoo.tools import mute_logger, formataddr
|
||||
|
||||
|
||||
@tagged('mail_channel')
|
||||
class TestChannelAccessRights(MailCommon):
|
||||
|
||||
@classmethod
|
||||
@@ -139,6 +141,7 @@ class TestChannelAccessRights(MailCommon):
|
||||
})
|
||||
|
||||
|
||||
@tagged('mail_channel')
|
||||
class TestChannelInternals(MailCommon):
|
||||
|
||||
@classmethod
|
||||
@@ -395,7 +398,7 @@ class TestChannelInternals(MailCommon):
|
||||
self.assertTrue(initial_channel_info, 'should be able to chat with multi company user')
|
||||
|
||||
|
||||
@tagged('moderation')
|
||||
@tagged('moderation', 'mail_channel')
|
||||
class TestChannelModeration(MailCommon):
|
||||
|
||||
@classmethod
|
||||
@@ -440,24 +443,24 @@ class TestChannelModeration(MailCommon):
|
||||
self.assertFalse(msg_c1_admin1.channel_ids | msg_c1_admin2.channel_ids | msg_c1_emplo2.channel_ids)
|
||||
|
||||
# accept
|
||||
msg_c1_admin1.with_user(self.user_employee)._moderate('accept')
|
||||
with self.assertBus([(self.cr.dbname, 'mail.channel', self.channel.id)]):
|
||||
msg_c1_admin1.with_user(self.user_employee)._moderate('accept')
|
||||
self.assertEqual(msg_c1_admin1.channel_ids, self.channel)
|
||||
self.assertEqual(msg_c1_admin1.moderation_status, 'accepted')
|
||||
self.assertEqual(msg_c1_admin2.moderation_status, 'pending_moderation')
|
||||
self.assertBusNotifications([(self.cr.dbname, 'mail.channel', self.channel.id)])
|
||||
|
||||
# allow
|
||||
self._reset_bus()
|
||||
(msg_c1_admin1 | msg_c1_emplo2).with_user(self.user_employee)._moderate('allow')
|
||||
with self.assertBus([
|
||||
(self.cr.dbname, 'mail.channel', self.channel.id),
|
||||
(self.cr.dbname, 'mail.channel', self.channel.id)]):
|
||||
(msg_c1_admin1 | msg_c1_emplo2).with_user(self.user_employee)._moderate('allow')
|
||||
self.assertEqual(msg_c1_admin1.channel_ids, self.channel)
|
||||
self.assertEqual(msg_c1_admin2.channel_ids, self.channel)
|
||||
self.assertEqual(msg_c1_emplo2.channel_ids, self.channel)
|
||||
self.assertEqual(msg_c1_admin1.moderation_status, 'accepted')
|
||||
self.assertEqual(msg_c1_admin2.moderation_status, 'accepted')
|
||||
self.assertEqual(msg_c1_emplo2.moderation_status, 'accepted')
|
||||
self.assertBusNotifications([
|
||||
(self.cr.dbname, 'mail.channel', self.channel.id),
|
||||
(self.cr.dbname, 'mail.channel', self.channel.id)])
|
||||
|
||||
@mute_logger('odoo.models.unlink')
|
||||
def test_message_moderate_reject(self):
|
||||
@@ -481,17 +484,16 @@ class TestChannelModeration(MailCommon):
|
||||
|
||||
# test discard: silently remove
|
||||
self._reset_bus()
|
||||
(msg_c1_admin2 + msg_c1_portal).with_user(self.user_employee)._moderate_discard()
|
||||
|
||||
# check all generated bus notifications
|
||||
self.assertBusNotifications(
|
||||
[(self.cr.dbname, 'res.partner', self.partner_admin.id),
|
||||
(self.cr.dbname, 'res.partner', self.partner_employee.id),
|
||||
(self.cr.dbname, 'res.partner', self.partner_portal.id)],
|
||||
[{'type': 'deletion', 'message_ids': [id2]}, # author of 1 message
|
||||
{'type': 'deletion', 'message_ids': [id2, id4]}, # moderator
|
||||
{'type': 'deletion', 'message_ids': [id4]}] # author of 1 message
|
||||
)
|
||||
with self.assertBus(
|
||||
[(self.cr.dbname, 'res.partner', self.partner_admin.id),
|
||||
(self.cr.dbname, 'res.partner', self.partner_employee.id),
|
||||
(self.cr.dbname, 'res.partner', self.partner_portal.id)],
|
||||
message_items=[
|
||||
{'type': 'deletion', 'message_ids': [id2]}, # author of 1 message
|
||||
{'type': 'deletion', 'message_ids': [id2, id4]}, # moderator
|
||||
{'type': 'deletion', 'message_ids': [id4]} # author of 1 message
|
||||
]):
|
||||
(msg_c1_admin2 + msg_c1_portal).with_user(self.user_employee)._moderate_discard()
|
||||
|
||||
@mute_logger('odoo.models.unlink')
|
||||
def test_message_notify_moderators(self):
|
||||
|
||||
@@ -136,8 +136,14 @@ class TestDiscuss(TestMailCommon, TestRecipients):
|
||||
# mark all as read clear needactions
|
||||
msg1 = self.test_record.message_post(body='Test', message_type='comment', subtype_xmlid='mail.mt_comment', partner_ids=[employee_partner.id])
|
||||
self._reset_bus()
|
||||
employee_partner.env['mail.message'].mark_all_as_read(domain=[])
|
||||
self.assertBusNotifications([(self.cr.dbname, 'res.partner', employee_partner.id)], [{ 'type': 'mark_as_read', 'message_ids': [msg1.id], 'needaction_inbox_counter': 0 }])
|
||||
with self.assertBus(
|
||||
[(self.cr.dbname, 'res.partner', employee_partner.id)],
|
||||
message_items=[
|
||||
{'type': 'mark_as_read',
|
||||
'message_ids': [msg1.id],
|
||||
'needaction_inbox_counter': 0}
|
||||
]):
|
||||
employee_partner.env['mail.message'].mark_all_as_read(domain=[])
|
||||
na_count = employee_partner.get_needaction_count()
|
||||
self.assertEqual(na_count, 0, "mark all as read should conclude all needactions")
|
||||
|
||||
@@ -155,8 +161,14 @@ class TestDiscuss(TestMailCommon, TestRecipients):
|
||||
self.assertEqual(na_count, 1, "message not accessible is currently still counted")
|
||||
|
||||
self._reset_bus()
|
||||
employee_partner.env['mail.message'].mark_all_as_read(domain=[])
|
||||
self.assertBusNotifications([(self.cr.dbname, 'res.partner', employee_partner.id)], [{ 'type': 'mark_as_read', 'message_ids': [msg2.id], 'needaction_inbox_counter': 0 }])
|
||||
with self.assertBus(
|
||||
[(self.cr.dbname, 'res.partner', employee_partner.id)],
|
||||
message_items=[
|
||||
{'type': 'mark_as_read',
|
||||
'message_ids': [msg2.id],
|
||||
'needaction_inbox_counter': 0}
|
||||
]):
|
||||
employee_partner.env['mail.message'].mark_all_as_read(domain=[])
|
||||
na_count = employee_partner.get_needaction_count()
|
||||
self.assertEqual(na_count, 0, "mark all read should conclude all needactions even inacessible ones")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user