[IMP] mail: add test for messages notification and for parented messages notification - CHM revision back to repair the merge.

bzr revid: tde@openerp.com-20121211092405-gir4r95oph2rwv11
This commit is contained in:
Thibault Delavallée 2012-12-11 10:24:05 +01:00
parent bf40c23e00
commit 3005251333
3 changed files with 37 additions and 1 deletions

View File

@ -841,6 +841,9 @@ class mail_message(osv.Model):
# An error appear when a user receive a notify to a message without notify to his parent message.
# Add a notification with read = true to the parented message if there are no notification
if message.parent_id:
# all notified_partner_ids of the mail.message have to be notified for the parented messages
if message.notified_partner_ids:
partners_to_notify |= set(message.notified_partner_ids)
partners_to_parent_notify = set(partners_to_notify) - set(message.parent_id.notified_partner_ids)
for partner in partners_to_parent_notify:
notification_obj.create(cr, uid, {

View File

@ -427,6 +427,38 @@ class test_mail(test_mail_mockup.TestMailMockups):
message = self.mail_message.browse(cr, uid, msg_id3)
self.assertEqual(message.parent_id.id, msg_id, 'message_post did not flatten the thread structure')
def test_22_message_post_notification(self):
""" Tests designed for message_post. """
cr, uid, user_admin, group_pigs = self.cr, self.uid, self.user_admin, self.group_pigs
self.res_users.write(cr, uid, [uid], {'signature': 'Admin', 'email': 'a@a'})
# 1 - Bert Tartopoils, without email, should receive emails for every message
p_b_id = self.res_partner.create(cr, uid, {'name': 'Bert Tartopoils', 'email': 'b@b', 'notification_email_send': 'all'})
# 2 - Dédé Grosbedon, without email, should receive emails for every message
p_c_id = self.res_partner.create(cr, uid, {'name': 'Dédé Grosbedon', 'email': 'c@c','notification_email_send': 'all'})
# Data: comment subtype for mail.message creation
ref = self.registry('ir.model.data').get_object_reference(cr, uid, 'mail', 'mt_comment')
subtype_id = ref and ref[1] or False
msg_id1 = self.mail_message.create(cr, uid, {'body': 'Test', 'subtype_id': subtype_id})
msg_id2 = self.mail_message.create(cr, uid, {'body': 'Test', 'subtype_id': subtype_id, 'parent_id': msg_id1 })
msg_id3 = self.mail_message.create(cr, uid, {'body': 'Test', 'subtype_id': subtype_id, 'parent_id': msg_id1, 'partner_ids': [(4, p_b_id)] , 'notified_partner_ids': [(4, p_c_id)] })
test_pids = set([p_b_id, p_c_id])
# Test: p_b_id is notified for the current message
message = self.mail_message.browse(cr, uid, msg_id3)
message_pids = set([partner.id for partner in message.notified_partner_ids] + [partner.id for partner in message.partner_ids])
self.assertEqual(test_pids, message_pids, 'mail.message : the partner is not notified for his message')
# Test: p_b_id is not notified for the others messages of this thread
message = self.mail_message.browse(cr, uid, msg_id2)
message_pids = set([partner.id for partner in message.notified_partner_ids] + [partner.id for partner in message.partner_ids])
self.assertFalse(message_pids, 'mail.message the partner is notified for an other message')
# Test: p_b_id is notified for the parented message
message = self.mail_message.browse(cr, uid, msg_id1)
message_pids = set([partner.id for partner in message.notified_partner_ids] + [partner.id for partner in message.partner_ids])
self.assertEqual(test_pids, message_pids, 'mail.message the partner is not notified for the parented message')
def test_25_message_compose_wizard(self):
""" Tests designed for the mail.compose.message wizard. """
cr, uid, user_admin, group_pigs = self.cr, self.uid, self.user_admin, self.group_pigs

View File

@ -86,7 +86,7 @@ class test_mail_access_rights(test_mail_mockup.TestMailMockups):
msg_ids = self.mail_message.search(cr, uid, [('subject', 'like', '_Test')])
self.assertEqual(set([msg_id1, msg_id2, msg_id3, msg_id4, msg_id5, msg_id6, msg_id7, msg_id8]), set(msg_ids), 'mail_message search failed')
@mute_logger('openerp.addons.base.ir.ir_model','openerp.osv.orm')
#@mute_logger('openerp.addons.base.ir.ir_model','openerp.osv.orm')
def test_05_mail_message_read_access_rights(self):
""" Test basic mail_message read access rights. """
cr, uid = self.cr, self.uid
@ -134,6 +134,7 @@ class test_mail_access_rights(test_mail_mockup.TestMailMockups):
self.assertRaises(except_orm, self.mail_message.read,
cr, user_bert_id, message_id)
@mute_logger('openerp.addons.base.ir.ir_model','openerp.osv.orm')
def test_10_mail_flow_access_rights(self):
""" Test a Chatter-looks alike flow. """