From b3d8e1f7fcc2248b8aff784156e2f4cea8871257 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 1 Oct 2012 15:05:30 +0200 Subject: [PATCH] [IMP] mail: test bzr revid: chm@openerp.com-20121001130530-w1k2b4vzst44jwa3 --- addons/mail/mail_thread.py | 4 +-- addons/mail/tests/test_mail.py | 31 ++++++++-------------- addons/mail/wizard/mail_compose_message.py | 6 +++-- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 07ffba4589c..b5a0e5dc5b6 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -610,7 +610,7 @@ class mail_thread(osv.AbstractModel): "now deprecated res.log.") self.message_post(cr, uid, [id], message, context=context) - def message_post(self, cr, uid, thread_id, body='', subject=False, type='notification', + def message_post(self, cr, uid, thread_id, body='', subject=None, type='notification', subtype=None, parent_id=False, attachments=None, context=None, **kwargs): """ Post a new message in an existing thread, returning the new mail.message ID. Extra keyword arguments will be used as default @@ -672,7 +672,7 @@ class mail_thread(osv.AbstractModel): 'model': model, 'res_id': thread_id or False, 'body': body, - 'subject': subject, + 'subject': subject or False, 'type': type, 'parent_id': parent_id, 'attachment_ids': attachment_ids, diff --git a/addons/mail/tests/test_mail.py b/addons/mail/tests/test_mail.py index 0c2e6a4dc6d..4f544a9f0a1 100644 --- a/addons/mail/tests/test_mail.py +++ b/addons/mail/tests/test_mail.py @@ -318,8 +318,6 @@ class test_mail(TestMailMockups): user_admin = self.res_users.browse(cr, uid, uid) group_pigs = self.mail_group.browse(cr, uid, self.group_pigs_id) - # 0 - Admin - p_a_id = user_admin.partner_id.id # 1 - Bert Tartopoils, with email, should receive emails for comments and emails p_b_id = self.res_partner.create(cr, uid, {'name': 'Bert Tartopoils', 'email': 'b@b'}) # 2 - Carine Poilvache, with email, should never receive emails @@ -363,7 +361,7 @@ class test_mail(TestMailMockups): self.assertIn(sent_email['body_alternative'], _mail_bodyalt1 + '\nBert Tartopoils\n', 'sent_email body_alternative is incorrect') # Test: mail_message: partner_ids = group followers message_pids = set([partner.id for partner in message.partner_ids]) - test_pids = set([p_a_id, p_b_id, p_c_id]) + test_pids = set([p_b_id, p_c_id]) self.assertEqual(test_pids, message_pids, 'mail.message partners incorrect') # Test: notification linked to this message = group followers = partner_ids notif_ids = self.mail_notification.search(cr, uid, [('message_id', '=', message.id)]) @@ -397,7 +395,7 @@ class test_mail(TestMailMockups): self.assertIn(_mail_bodyalt2, sent_email['body_alternative'], 'sent_email body_alternative incorrect') # Test: mail_message: partner_ids = group followers message_pids = set([partner.id for partner in message.partner_ids]) - test_pids = set([p_a_id, p_b_id, p_c_id, p_d_id]) + test_pids = set([p_b_id, p_c_id, p_d_id]) self.assertEqual(message_pids, test_pids, 'mail.message partners incorrect') # Test: notifications linked to this message = group followers = partner_ids notif_ids = self.mail_notification.search(cr, uid, [('message_id', '=', message.id)]) @@ -435,8 +433,6 @@ class test_mail(TestMailMockups): _attachments_test = [('first.txt', 'My first attachment'), ('second.txt', 'My second attachment')] # Create partners - # 0 - Admin - p_a_id = user_admin.partner_id.id # 1 - Bert Tartopoils, with email, should receive emails for comments and emails p_b_id = self.res_partner.create(cr, uid, {'name': 'Bert Tartopoils', 'email': 'b@b'}) # 2 - Carine Poilvache, with email, should never receive emails @@ -470,9 +466,10 @@ class test_mail(TestMailMockups): self.assertEqual(message.body, _msg_body, 'mail.message incorrect body') # Test: mail.message: partner_ids = entries in mail.notification: group_pigs fans (a, b) + mail.compose.message partner_ids (c, d) msg_pids = [partner.id for partner in message.partner_ids] - test_pids = [p_a_id, p_b_id, p_c_id, p_d_id] + test_pids = [p_b_id, p_c_id, p_d_id] notif_ids = self.mail_notification.search(cr, uid, [('message_id', '=', message.id)]) - self.assertEqual(len(notif_ids), 4, 'mail.message: too much notifications created') + + self.assertEqual(len(notif_ids), 3, 'mail.message: too much notifications created') self.assertEqual(set(msg_pids), set(test_pids), 'mail.message partner_ids incorrect') # ---------------------------------------- @@ -490,22 +487,15 @@ class test_mail(TestMailMockups): self.assertEqual(compose.res_id, self.group_pigs_id, 'mail.compose.message incorrect res_id') self.assertEqual(compose.parent_id.id, message.id, 'mail.compose.message incorrect parent_id') self.assertEqual(compose.content_subtype, 'html', 'mail.compose.message incorrect content_subtype') - - # 2. Post the comment, get created message - parent_id = message.id - mail_compose.send_mail(cr, uid, [compose_id]) - group_pigs.refresh() - message = group_pigs.message_ids[0] # Test: mail.message: subject as Re:.., body in html, parent_id - self.assertEqual(message.subject, _msg_reply, 'mail.message incorrect subject') - self.assertIn('Administrator wrote:
Pigs rules
', message.body, 'mail.message body is incorrect') - self.assertEqual(message.parent_id and message.parent_id.id, parent_id, 'mail.message parent_id incorrect') + self.assertEqual(compose.subject, _msg_reply, 'mail.message incorrect subject') + self.assertIn('Administrator wrote:
Pigs rules
', compose.body, 'mail.message body is incorrect') + self.assertEqual(compose.parent_id and compose.parent_id.id, message.id, 'mail.message parent_id incorrect') # Test: mail.message: attachments - for attach in message.attachment_ids: + for attach in compose.attachment_ids: self.assertEqual(attach.res_model, 'mail.group', 'mail.message attachment res_model incorrect') self.assertEqual(attach.res_id, self.group_pigs_id, 'mail.message attachment res_id incorrect') - self.assertIn((attach.name, attach.datas.decode('base64')), _attachments_test, - 'mail.message attachment name / data incorrect') + self.assertIn((attach.datas_fname, attach.datas.decode('base64')), _attachments_test, 'mail.message attachment name / data incorrect') # ---------------------------------------- # CASE3: mass_mail on Pigs and Bird @@ -547,6 +537,7 @@ class test_mail(TestMailMockups): def _compare_structures(struct1, struct2, n=0): # print '%scompare structure' % ('\t' * n) # self.assertEqual(len(struct1), len(struct2), 'message_read structure number of childs incorrect') + for x in range(len(struct1)): if struct1[x].get('type') == 'expandable': continue diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index 0e5c65ab3c0..c2e514dc9eb 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -249,9 +249,11 @@ class mail_compose_message(osv.TransientModel): post_values.update(email_dict) # post the message active_model_pool.message_post(cr, uid, [res_id], type='comment', subtype='mt_comment', context=context, **post_values) - # post process: update attachments, because id is not necessarily known when adding attachments in Chatter - self.pool.get('ir.attachment').write(cr, uid, [attach.id for attach in wizard.attachment_ids], {'res_id': wizard.id}, context=context) + # post process: update attachments, because id is not necessarily known when adding attachments in Chatter + self.pool.get('ir.attachment').write(cr, uid, [attach.id for attach in wizard.attachment_ids], { + 'res_id': wizard.id, 'res_model': wizard.model or False}, context=context) + if context.get('mail_action_wizard_close'): return {'type': 'ir.actions.act_window_close'} else: