diff options
Diffstat (limited to 'addons/test_mail/tests')
| -rw-r--r-- | addons/test_mail/tests/test_mail_channel.py | 67 | ||||
| -rw-r--r-- | addons/test_mail/tests/test_performance.py | 2 |
2 files changed, 68 insertions, 1 deletions
diff --git a/addons/test_mail/tests/test_mail_channel.py b/addons/test_mail/tests/test_mail_channel.py index 239e76ccb41..e33570277e9 100644 --- a/addons/test_mail/tests/test_mail_channel.py +++ b/addons/test_mail/tests/test_mail_channel.py @@ -349,6 +349,73 @@ class TestChannelFeatures(TestMailCommon): initial_channel_info = self.env['mail.channel'].with_user(test_user_1).with_context(allowed_company_ids=company_A.ids).channel_get(test_user_2.partner_id.ids) self.assertTrue(initial_channel_info, 'should be able to chat with multi company user') + def test_multi_company_message_post_notifications(self): + company_1 = self.company_admin + company_2 = self.env['res.company'].create({'name': 'Company 2'}) + + # Company 1 and notification_type == "inbox" + user_1 = self.user_employee + + # Company 1 and notification_type == "email" + user_2 = self.user_admin + user_2.notification_type = 'email' + + user_3 = mail_new_test_user( + self.env, login='user3', email='user3@example.com', groups='base.group_user', + company_id=company_2.id, company_ids=[(6, 0, company_2.ids)], + name='user3', notification_type='inbox') + + user_4 = mail_new_test_user( + self.env, login='user4', email='user4@example.com', groups='base.group_user', + company_id=company_2.id, company_ids=[(6, 0, company_2.ids)], + name='user4', notification_type='email') + + partner_without_user = self.env['res.partner'].create({ + 'name': 'Partner', + 'email': 'partner_test_123@example.com', + }) + mail_channel = self.env['mail.channel'].with_user(user_1).create({ + 'name': 'Channel', + 'channel_partner_ids': [ + (4, user_1.partner_id.id), + (4, user_2.partner_id.id), + (4, user_3.partner_id.id), + (4, user_4.partner_id.id), + (4, partner_without_user.id), + ], + 'email_send': True, + }) + + mail_channel.invalidate_cache() + (user_1 | user_2 | user_3 | user_4).invalidate_cache() + + with self.mock_mail_gateway(): + mail_channel.with_user(user_1).with_company(company_1).message_post( + body='Test body message 1337', + channel_ids=mail_channel.ids, + ) + + self.assertSentEmail(user_1.partner_id, [user_2.partner_id]) + self.assertSentEmail(user_1.partner_id, [user_4.partner_id]) + self.assertEqual(len(self._mails), 3, 'Should have send only 3 emails to user 2, user 4 and the partner') + + self.assertBusNotifications([(self.cr.dbname, 'mail.channel', mail_channel.id)]) + + # Should not create mail notifications for user 1 & 3 + self.assertFalse(self.env['mail.notification'].search([('res_partner_id', '=', user_1.partner_id.id)])) + self.assertFalse(self.env['mail.notification'].search([('res_partner_id', '=', user_3.partner_id.id)])) + + # Should create mail notifications for user 2 & 4 + self.assertTrue(self.env['mail.notification'].search([('res_partner_id', '=', user_2.partner_id.id)])) + self.assertTrue(self.env['mail.notification'].search([('res_partner_id', '=', user_4.partner_id.id)])) + + # Check that we did not send a "channel_seen" notifications + # for the users which receive the notifications by email + notification_seen_user_2 = self.env['bus.bus'].search([('create_uid', '=', user_2.id)]) + self.assertFalse(notification_seen_user_2, 'Should not have sent a notification as user 2') + notification_seen_user_4 = self.env['bus.bus'].search([('create_uid', '=', user_4.id)]) + self.assertFalse(notification_seen_user_4, 'Should not have sent a notification as user 4') + @tagged('moderation', 'mail_channel') class TestChannelModeration(TestMailCommon): diff --git a/addons/test_mail/tests/test_performance.py b/addons/test_mail/tests/test_performance.py index 658e353a81e..6862160acea 100644 --- a/addons/test_mail/tests/test_performance.py +++ b/addons/test_mail/tests/test_performance.py @@ -998,7 +998,7 @@ class TestMailHeavyPerformancePost(BaseMailPerformance): ] self.attachements = self.env['ir.attachment'].with_user(self.env.user).create(self.vals) attachement_ids = self.attachements.ids - with self.assertQueryCount(emp=82): + with self.assertQueryCount(emp=80): self.cr.sql_log = self.warm and self.cr.sql_log_count record.with_context({}).message_post( body='<p>Test body <img src="cid:cid1"> <img src="cid:cid2"></p>', |
