diff options
| author | Vidhin Mehta <vme@tinyerp.com> | 2013-08-23 10:36:02 +0530 |
|---|---|---|
| committer | Vidhin Mehta <vme@tinyerp.com> | 2013-08-23 10:36:02 +0530 |
| commit | 75ddd5ccbec73c4a671b6a74efaa3d41dc2ea2db (patch) | |
| tree | 50ed3620df15e8533760f5d47e754a1d39c1e856 /addons/mail/tests | |
| parent | 42f27a15275effd9c43dfe99e32c395ca6b3fd8a (diff) | |
| parent | a7f4b6aaa0359d12046e81183417c24f093cd7c3 (diff) | |
[MERGE]Trunk.
bzr revid: vme@tinyerp.com-20130823050602-33bqv07e7g8dhv7x
Diffstat (limited to 'addons/mail/tests')
| -rw-r--r-- | addons/mail/tests/test_mail_base.py | 7 | ||||
| -rw-r--r-- | addons/mail/tests/test_mail_features.py | 76 | ||||
| -rw-r--r-- | addons/mail/tests/test_mail_gateway.py | 473 |
3 files changed, 375 insertions, 181 deletions
diff --git a/addons/mail/tests/test_mail_base.py b/addons/mail/tests/test_mail_base.py index a3b90288f0b..b0f9f72b6f7 100644 --- a/addons/mail/tests/test_mail_base.py +++ b/addons/mail/tests/test_mail_base.py @@ -69,10 +69,11 @@ class TestMailBase(common.TransactionCase): self.group_employee_id = group_employee_ref and group_employee_ref[1] or False # Test users to use through the various tests + self.res_users.write(cr, uid, uid, {'name': 'Administrator'}) self.user_raoul_id = self.res_users.create(cr, uid, - {'name': 'Raoul Grosbedon', 'signature': 'SignRaoul', 'email': 'raoul@raoul.fr', 'login': 'raoul', 'groups_id': [(6, 0, [self.group_employee_id])]}) + {'name': 'Raoul Grosbedon', 'signature': 'SignRaoul', 'email': 'raoul@raoul.fr', 'login': 'raoul', 'alias_name': 'raoul', 'groups_id': [(6, 0, [self.group_employee_id])]}) self.user_bert_id = self.res_users.create(cr, uid, - {'name': 'Bert Tartignole', 'signature': 'SignBert', 'email': 'bert@bert.fr', 'login': 'bert', 'groups_id': [(6, 0, [])]}) + {'name': 'Bert Tartignole', 'signature': 'SignBert', 'email': 'bert@bert.fr', 'login': 'bert', 'alias_name': 'bert', 'groups_id': [(6, 0, [])]}) self.user_raoul = self.res_users.browse(cr, uid, self.user_raoul_id) self.user_bert = self.res_users.browse(cr, uid, self.user_bert_id) self.user_admin = self.res_users.browse(cr, uid, uid) @@ -82,7 +83,7 @@ class TestMailBase(common.TransactionCase): # Test 'pigs' group to use through the various tests self.group_pigs_id = self.mail_group.create(cr, uid, - {'name': 'Pigs', 'description': 'Fans of Pigs, unite !'}, + {'name': 'Pigs', 'description': 'Fans of Pigs, unite !', 'alias_name': 'group+pigs'}, {'mail_create_nolog': True}) self.group_pigs = self.mail_group.browse(cr, uid, self.group_pigs_id) diff --git a/addons/mail/tests/test_mail_features.py b/addons/mail/tests/test_mail_features.py index 46f4555349d..ae5555c01ca 100644 --- a/addons/mail/tests/test_mail_features.py +++ b/addons/mail/tests/test_mail_features.py @@ -22,7 +22,7 @@ from openerp.addons.mail.mail_mail import mail_mail from openerp.addons.mail.mail_thread import mail_thread from openerp.addons.mail.tests.test_mail_base import TestMailBase -from openerp.tools import mute_logger +from openerp.tools import mute_logger, email_split from openerp.tools.mail import html_sanitize @@ -32,17 +32,17 @@ class test_mail(TestMailBase): """ Test basic mail.alias setup works, before trying to use them for routing """ cr, uid = self.cr, self.uid self.user_valentin_id = self.res_users.create(cr, uid, - {'name': 'Valentin Cognito', 'email': 'valentin.cognito@gmail.com', 'login': 'valentin.cognito'}) + {'name': 'Valentin Cognito', 'email': 'valentin.cognito@gmail.com', 'login': 'valentin.cognito', 'alias_name': 'valentin.cognito'}) self.user_valentin = self.res_users.browse(cr, uid, self.user_valentin_id) self.assertEquals(self.user_valentin.alias_name, self.user_valentin.login, "Login should be used as alias") self.user_pagan_id = self.res_users.create(cr, uid, - {'name': 'Pagan Le Marchant', 'email': 'plmarchant@gmail.com', 'login': 'plmarchant@gmail.com'}) + {'name': 'Pagan Le Marchant', 'email': 'plmarchant@gmail.com', 'login': 'plmarchant@gmail.com', 'alias_name': 'plmarchant@gmail.com'}) self.user_pagan = self.res_users.browse(cr, uid, self.user_pagan_id) self.assertEquals(self.user_pagan.alias_name, 'plmarchant', "If login is an email, the alias should keep only the local part") self.user_barty_id = self.res_users.create(cr, uid, - {'name': 'Bartholomew Ironside', 'email': 'barty@gmail.com', 'login': 'b4r+_#_R3wl$$'}) + {'name': 'Bartholomew Ironside', 'email': 'barty@gmail.com', 'login': 'b4r+_#_R3wl$$', 'alias_name': 'b4r+_#_R3wl$$'}) self.user_barty = self.res_users.browse(cr, uid, self.user_barty_id) self.assertEquals(self.user_barty.alias_name, 'b4r+_-_r3wl-', 'Disallowed chars should be replaced by hyphens') @@ -479,7 +479,7 @@ class test_mail(TestMailBase): 'message_post: notification email sent to more than one email address instead of a precise partner') self.assertIn(sent_email['email_to'][0], test_emailto, 'message_post: notification email email_to incorrect') - self.assertEqual(sent_email['reply_to'], 'r@r', # was '"Followers of Pigs" <r@r>', but makes no sense + self.assertEqual(email_split(sent_email['reply_to']), ['r@r'], # was '"Followers of Pigs" <r@r>', but makes no sense 'message_post: notification email reply_to incorrect: should have raoul email') self.assertEqual(_mail_subject, sent_email['subject'], 'message_post: notification email subject incorrect') @@ -640,7 +640,7 @@ class test_mail(TestMailBase): }) compose = mail_compose.browse(cr, uid, compose_id) - # D: Post the comment, get created message for each group + # Do: Post the comment, get created message for each group mail_compose.send_mail(cr, user_raoul.id, [compose_id], context={ 'default_res_id': -1, 'active_ids': [self.group_pigs_id, group_bird_id] @@ -679,6 +679,37 @@ class test_mail(TestMailBase): self.assertEqual(set(bird_pids), set(test_pids), 'compose wizard: mail_post_autofollow and mail_create_nosubscribe context keys not correctly taken into account') + # Do: Compose in mass_mail, coming from list_view, we have an active_domain that should be supported + compose_id = mail_compose.create(cr, user_raoul.id, + { + 'subject': _subject, + 'body': '${object.description}', + 'partner_ids': [(4, p_c_id), (4, p_d_id)], + }, context={ + 'default_composition_mode': 'mass_mail', + 'default_model': 'mail.group', + 'default_res_id': False, + 'active_ids': [self.group_pigs_id], + 'active_domain': [('name', 'in', ['Pigs', 'Bird'])], + }) + compose = mail_compose.browse(cr, uid, compose_id) + + # Do: Post the comment, get created message for each group + mail_compose.send_mail( + cr, user_raoul.id, [compose_id], context={ + 'default_res_id': -1, + 'active_ids': [self.group_pigs_id, group_bird_id] + }) + group_pigs.refresh() + group_bird.refresh() + message1 = group_pigs.message_ids[0] + message2 = group_bird.message_ids[0] + + # Test: Pigs and Bird did receive their message + test_msg_ids = self.mail_message.search(cr, uid, [], limit=2) + self.assertIn(message1.id, test_msg_ids, 'compose wizard: Pigs did not receive its mass mailing message') + self.assertIn(message2.id, test_msg_ids, 'compose wizard: Bird did not receive its mass mailing message') + def test_30_needaction(self): """ Tests for mail.message needaction. """ cr, uid, user_admin, user_raoul, group_pigs = self.cr, self.uid, self.user_admin, self.user_raoul, self.group_pigs @@ -739,18 +770,21 @@ class test_mail(TestMailBase): self.ir_model_data.create(cr, uid, {'name': 'mt_private', 'model': 'mail.message.subtype', 'module': 'mail', 'res_id': mt_private_id}) mt_name_supername_id = self.mail_message_subtype.create(cr, uid, {'name': 'name_supername', 'description': 'Supername name'}) self.ir_model_data.create(cr, uid, {'name': 'mt_name_supername', 'model': 'mail.message.subtype', 'module': 'mail', 'res_id': mt_name_supername_id}) + mt_group_public_set_id = self.mail_message_subtype.create(cr, uid, {'name': 'group_public_set', 'description': 'Group set'}) + self.ir_model_data.create(cr, uid, {'name': 'mt_group_public_set', 'model': 'mail.message.subtype', 'module': 'mail', 'res_id': mt_group_public_set_id}) mt_group_public_id = self.mail_message_subtype.create(cr, uid, {'name': 'group_public', 'description': 'Group changed'}) self.ir_model_data.create(cr, uid, {'name': 'mt_group_public', 'model': 'mail.message.subtype', 'module': 'mail', 'res_id': mt_group_public_id}) # Data: alter mail_group model for testing purposes (test on classic, selection and many2one fields) self.mail_group._track = { 'public': { - 'mail.mt_private': lambda self, cr, uid, obj, ctx=None: obj['public'] == 'private', + 'mail.mt_private': lambda self, cr, uid, obj, ctx=None: obj.public == 'private', }, 'name': { - 'mail.mt_name_supername': lambda self, cr, uid, obj, ctx=None: obj['name'] == 'supername', + 'mail.mt_name_supername': lambda self, cr, uid, obj, ctx=None: obj.name == 'supername', }, 'group_public_id': { + 'mail.mt_group_public_set': lambda self, cr, uid, obj, ctx=None: obj.group_public_id, 'mail.mt_group_public': lambda self, cr, uid, obj, ctx=None: True, }, } @@ -787,21 +821,37 @@ class test_mail(TestMailBase): self.assertIn(u'Public\u2192Private', _strip_string_spaces(last_msg.body), 'tracked: message body incorrect') self.assertIn(u'Pigs\u2192supername', _strip_string_spaces(last_msg.body), 'tracked feature: message body does not hold always tracked field') - # Test: change public as public, group_public_id -> 1 subtype, name always tracked + # Test: change public as public, group_public_id -> 2 subtypes, name always tracked self.mail_group.write(cr, self.user_raoul_id, [self.group_pigs_id], {'public': 'public', 'group_public_id': group_system_id}) self.group_pigs.refresh() - self.assertEqual(len(self.group_pigs.message_ids), 4, 'tracked: one message should have been produced') - # Test: first produced message: mt_group_public_id, with name always tracked, public tracked on change + self.assertEqual(len(self.group_pigs.message_ids), 5, 'tracked: one message should have been produced') + # Test: first produced message: mt_group_public_set_id, with name always tracked, public tracked on change last_msg = self.group_pigs.message_ids[-4] - self.assertEqual(last_msg.subtype_id.id, mt_group_public_id, 'tracked: message should not be linked to any subtype') + self.assertEqual(last_msg.subtype_id.id, mt_group_public_set_id, 'tracked: message should be linked to mt_group_public_set_id') + self.assertIn('Group set', last_msg.body, 'tracked: message body does not hold the subtype description') + self.assertIn(u'Private\u2192Public', _strip_string_spaces(last_msg.body), 'tracked: message body does not hold changed tracked field') + self.assertIn(u'HumanResources/Employee\u2192Administration/Settings', _strip_string_spaces(last_msg.body), 'tracked: message body does not hold always tracked field') + # Test: second produced message: mt_group_public_id, with name always tracked, public tracked on change + last_msg = self.group_pigs.message_ids[-5] + self.assertEqual(last_msg.subtype_id.id, mt_group_public_id, 'tracked: message should be linked to mt_group_public_id') self.assertIn('Group changed', last_msg.body, 'tracked: message body does not hold the subtype description') self.assertIn(u'Private\u2192Public', _strip_string_spaces(last_msg.body), 'tracked: message body does not hold changed tracked field') self.assertIn(u'HumanResources/Employee\u2192Administration/Settings', _strip_string_spaces(last_msg.body), 'tracked: message body does not hold always tracked field') + # Test: change group_public_id to False -> 1 subtype, name always tracked + self.mail_group.write(cr, self.user_raoul_id, [self.group_pigs_id], {'group_public_id': False}) + self.group_pigs.refresh() + self.assertEqual(len(self.group_pigs.message_ids), 6, 'tracked: one message should have been produced') + # Test: first produced message: mt_group_public_set_id, with name always tracked, public tracked on change + last_msg = self.group_pigs.message_ids[-6] + self.assertEqual(last_msg.subtype_id.id, mt_group_public_id, 'tracked: message should be linked to mt_group_public_id') + self.assertIn('Group changed', last_msg.body, 'tracked: message body does not hold the subtype description') + self.assertIn(u'Administration/Settings\u2192', _strip_string_spaces(last_msg.body), 'tracked: message body does not hold always tracked field') + # Test: change not tracked field, no tracking message self.mail_group.write(cr, self.user_raoul_id, [self.group_pigs_id], {'description': 'Dummy'}) self.group_pigs.refresh() - self.assertEqual(len(self.group_pigs.message_ids), 4, 'tracked: No message should have been produced') + self.assertEqual(len(self.group_pigs.message_ids), 6, 'tracked: No message should have been produced') # Data: removed changes public_col.track_visibility = None diff --git a/addons/mail/tests/test_mail_gateway.py b/addons/mail/tests/test_mail_gateway.py index 5615e22b2c2..fade38869f1 100644 --- a/addons/mail/tests/test_mail_gateway.py +++ b/addons/mail/tests/test_mail_gateway.py @@ -99,20 +99,20 @@ class TestMailgateway(TestMailBase): # -------------------------------------------------- # Do: find partner with email -> first partner should be found - partner_info = self.mail_thread.message_find_partner_from_emails(cr, uid, None, ['Maybe Raoul <test@test.fr>'], link_mail=False)[0] + partner_info = self.mail_thread.message_partner_info_from_emails(cr, uid, None, ['Maybe Raoul <test@test.fr>'], link_mail=False)[0] self.assertEqual(partner_info['full_name'], 'Maybe Raoul <test@test.fr>', - 'mail_thread: message_find_partner_from_emails did not handle email') + 'mail_thread: message_partner_info_from_emails did not handle email') self.assertEqual(partner_info['partner_id'], p_a_id, - 'mail_thread: message_find_partner_from_emails wrong partner found') + 'mail_thread: message_partner_info_from_emails wrong partner found') # Data: add some data about partners # 2 - User BRaoul p_b_id = self.res_partner.create(cr, uid, {'name': 'BRaoul', 'email': 'test@test.fr', 'user_ids': [(4, user_raoul.id)]}) # Do: find partner with email -> first user should be found - partner_info = self.mail_thread.message_find_partner_from_emails(cr, uid, None, ['Maybe Raoul <test@test.fr>'], link_mail=False)[0] + partner_info = self.mail_thread.message_partner_info_from_emails(cr, uid, None, ['Maybe Raoul <test@test.fr>'], link_mail=False)[0] self.assertEqual(partner_info['partner_id'], p_b_id, - 'mail_thread: message_find_partner_from_emails wrong partner found') + 'mail_thread: message_partner_info_from_emails wrong partner found') # -------------------------------------------------- # CASE1: with object @@ -120,90 +120,106 @@ class TestMailgateway(TestMailBase): # Do: find partner in group where there is a follower with the email -> should be taken self.mail_group.message_subscribe(cr, uid, [group_pigs.id], [p_b_id]) - partner_info = self.mail_group.message_find_partner_from_emails(cr, uid, group_pigs.id, ['Maybe Raoul <test@test.fr>'], link_mail=False)[0] + partner_info = self.mail_group.message_partner_info_from_emails(cr, uid, group_pigs.id, ['Maybe Raoul <test@test.fr>'], link_mail=False)[0] self.assertEqual(partner_info['partner_id'], p_b_id, - 'mail_thread: message_find_partner_from_emails wrong partner found') + 'mail_thread: message_partner_info_from_emails wrong partner found') def test_05_mail_message_mail_mail(self): """ Tests designed for testing email values based on mail.message, aliases, ... """ - cr, uid = self.cr, self.uid - - # Data: clean catchall domain + cr, uid, user_raoul_id = self.cr, self.uid, self.user_raoul_id + + # Data: update + generic variables + reply_to1 = '_reply_to1@example.com' + reply_to2 = '_reply_to2@example.com' + email_from1 = 'from@example.com' + alias_domain = 'schlouby.fr' + raoul_from = 'Raoul Grosbedon <raoul@raoul.fr>' + raoul_from_alias = 'Raoul Grosbedon <raoul@schlouby.fr>' + raoul_reply = '"Followers of Pigs" <raoul@raoul.fr>' + raoul_reply_alias = '"Followers of Pigs" <group+pigs@schlouby.fr>' + # Data: remove alias_domain to see emails with alias param_ids = self.registry('ir.config_parameter').search(cr, uid, [('key', '=', 'mail.catchall.domain')]) self.registry('ir.config_parameter').unlink(cr, uid, param_ids) - # Do: create a mail_message with a reply_to, without message-id - msg_id = self.mail_message.create(cr, uid, {'subject': 'Subject', 'body': 'Body', 'reply_to': 'custom@example.com'}) - msg = self.mail_message.browse(cr, uid, msg_id) + # Do: free message; specified values > default values + msg_id = self.mail_message.create(cr, user_raoul_id, {'reply_to': reply_to1, 'email_from': email_from1}) + msg = self.mail_message.browse(cr, user_raoul_id, msg_id) # Test: message content self.assertIn('reply_to', msg.message_id, - 'mail_message: message_id should be specific to a mail_message with a given reply_to') - self.assertEqual('custom@example.com', msg.reply_to, - 'mail_message: incorrect reply_to') - # Do: create a mail_mail with the previous mail_message and specified reply_to - mail_id = self.mail_mail.create(cr, uid, {'mail_message_id': msg_id, 'reply_to': 'other@example.com', 'state': 'cancel'}) - mail = self.mail_mail.browse(cr, uid, mail_id) - # Test: mail_mail content - self.assertEqual(mail.reply_to, 'other@example.com', - 'mail_mail: reply_to should be equal to the one coming from creation values') + 'mail_message: message_id should be specific to a mail_message with a given reply_to') + self.assertEqual(msg.reply_to, reply_to1, + 'mail_message: incorrect reply_to: should come from values') + self.assertEqual(msg.email_from, email_from1, + 'mail_message: incorrect email_from: should come from values') # Do: create a mail_mail with the previous mail_message - self.mail_message.write(cr, uid, [msg_id], {'reply_to': 'custom@example.com'}) - msg.refresh() - mail_id = self.mail_mail.create(cr, uid, {'mail_message_id': msg_id, 'state': 'cancel'}) - mail = self.mail_mail.browse(cr, uid, mail_id) + mail_id = self.mail_mail.create(cr, user_raoul_id, {'mail_message_id': msg_id, 'state': 'cancel'}) + mail = self.mail_mail.browse(cr, user_raoul_id, mail_id) # Test: mail_mail content - self.assertEqual(mail.reply_to, msg.reply_to, - 'mail_mail: reply_to should be equal to the one coming from the mail_message') - - # Do: create a mail_message without a reply_to - msg_id = self.mail_message.create(cr, uid, {'subject': 'Subject', 'body': 'Body', 'model': 'mail.group', 'res_id': self.group_pigs_id, 'email_from': False}) - msg = self.mail_message.browse(cr, uid, msg_id) + self.assertEqual(mail.reply_to, reply_to1, + 'mail_mail: incorrect reply_to: should come from mail.message') + self.assertEqual(mail.email_from, email_from1, + 'mail_mail: incorrect email_from: should come from mail.message') + # Do: create a mail_mail with the previous mail_message + specified reply_to + mail_id = self.mail_mail.create(cr, user_raoul_id, {'mail_message_id': msg_id, 'state': 'cancel', 'reply_to': reply_to2}) + mail = self.mail_mail.browse(cr, user_raoul_id, mail_id) + # Test: mail_mail content + self.assertEqual(mail.reply_to, reply_to2, + 'mail_mail: incorrect reply_to: should come from values') + self.assertEqual(mail.email_from, email_from1, + 'mail_mail: incorrect email_from: should come from mail.message') + + # Do: mail_message attached to a document + msg_id = self.mail_message.create(cr, user_raoul_id, {'model': 'mail.group', 'res_id': self.group_pigs_id}) + msg = self.mail_message.browse(cr, user_raoul_id, msg_id) # Test: message content self.assertIn('mail.group', msg.message_id, - 'mail_message: message_id should contain model') + 'mail_message: message_id should contain model') self.assertIn('%s' % self.group_pigs_id, msg.message_id, - 'mail_message: message_id should contain res_id') + 'mail_message: message_id should contain res_id') self.assertFalse(msg.reply_to, - 'mail_message: should not generate a reply_to address when not specified') - # Do: create a mail_mail based on the previous mail_message - mail_id = self.mail_mail.create(cr, uid, {'mail_message_id': msg_id, 'state': 'cancel'}) - mail = self.mail_mail.browse(cr, uid, mail_id) - # Test: mail_mail content - self.assertFalse(mail.reply_to, - 'mail_mail: reply_to should not have been guessed') - # Update message - self.mail_message.write(cr, uid, [msg_id], {'email_from': 'someone@example.com'}) - msg.refresh() + 'mail_message: incorrect reply_to: should not be generated if not specified') + self.assertEqual(msg.email_from, raoul_from, + 'mail_message: incorrect email_from: should be Raoul') # Do: create a mail_mail based on the previous mail_message - mail_id = self.mail_mail.create(cr, uid, {'mail_message_id': msg_id, 'state': 'cancel'}) - mail = self.mail_mail.browse(cr, uid, mail_id) + mail_id = self.mail_mail.create(cr, user_raoul_id, {'mail_message_id': msg_id, 'state': 'cancel'}) + mail = self.mail_mail.browse(cr, user_raoul_id, mail_id) # Test: mail_mail content - self.assertEqual(mail.reply_to, msg.email_from, - 'mail_mail: reply_to should be equal to mail_message.email_from when having no document or default alias') + self.assertEqual(mail.reply_to, raoul_reply, + 'mail_mail: incorrect reply_to: should be Raoul') # Data: set catchall domain - self.registry('ir.config_parameter').set_param(cr, uid, 'mail.catchall.domain', 'schlouby.fr') + self.registry('ir.config_parameter').set_param(cr, uid, 'mail.catchall.domain', alias_domain) self.registry('ir.config_parameter').unlink(cr, uid, self.registry('ir.config_parameter').search(cr, uid, [('key', '=', 'mail.catchall.alias')])) # Update message - self.mail_message.write(cr, uid, [msg_id], {'email_from': False, 'reply_to': False}) + self.mail_message.write(cr, user_raoul_id, [msg_id], {'email_from': False, 'reply_to': False}) msg.refresh() # Do: create a mail_mail based on the previous mail_message - mail_id = self.mail_mail.create(cr, uid, {'mail_message_id': msg_id, 'state': 'cancel'}) - mail = self.mail_mail.browse(cr, uid, mail_id) + mail_id = self.mail_mail.create(cr, user_raoul_id, {'mail_message_id': msg_id, 'state': 'cancel'}) + mail = self.mail_mail.browse(cr, user_raoul_id, mail_id) # Test: mail_mail content - self.assertEqual(mail.reply_to, '"Followers of Pigs" <group+pigs@schlouby.fr>', - 'mail_mail: reply_to should equal the mail.group alias') + self.assertEqual(mail.reply_to, raoul_reply_alias, + 'mail_mail: incorrect reply_to: should be Pigs alias') + + # Update message: test alias on email_from + msg_id = self.mail_message.create(cr, user_raoul_id, {}) + msg = self.mail_message.browse(cr, user_raoul_id, msg_id) + # Do: create a mail_mail based on the previous mail_message + mail_id = self.mail_mail.create(cr, user_raoul_id, {'mail_message_id': msg_id, 'state': 'cancel'}) + mail = self.mail_mail.browse(cr, user_raoul_id, mail_id) + # Test: mail_mail content + self.assertEqual(mail.reply_to, raoul_from_alias, + 'mail_mail: incorrect reply_to: should be message email_from using Raoul alias') # Update message - self.mail_message.write(cr, uid, [msg_id], {'res_id': False, 'email_from': 'someone@schlouby.fr', 'reply_to': False}) + self.mail_message.write(cr, user_raoul_id, [msg_id], {'res_id': False, 'email_from': 'someone@schlouby.fr', 'reply_to': False}) msg.refresh() # Do: create a mail_mail based on the previous mail_message - mail_id = self.mail_mail.create(cr, uid, {'mail_message_id': msg_id, 'state': 'cancel'}) - mail = self.mail_mail.browse(cr, uid, mail_id) + mail_id = self.mail_mail.create(cr, user_raoul_id, {'mail_message_id': msg_id, 'state': 'cancel'}) + mail = self.mail_mail.browse(cr, user_raoul_id, mail_id) # Test: mail_mail content self.assertEqual(mail.reply_to, msg.email_from, - 'mail_mail: reply_to should equal the mail_message email_from') + 'mail_mail: incorrect reply_to: should be message email_from') # Data: set catchall alias self.registry('ir.config_parameter').set_param(self.cr, self.uid, 'mail.catchall.alias', 'gateway') @@ -214,23 +230,23 @@ class TestMailgateway(TestMailBase): # Do: create a mail_mail based on the previous mail_message mail_id = self.mail_mail.create(cr, uid, {'mail_message_id': msg_id, 'state': 'cancel'}) mail = self.mail_mail.browse(cr, uid, mail_id) - # Test: mail_mail content + # Test: mail_mail Content-Type self.assertEqual(mail.reply_to, 'gateway@schlouby.fr', - 'mail_mail: reply_to should equal the catchall email alias') + 'mail_mail: reply_to should equal the catchall email alias') # Do: create a mail_mail mail_id = self.mail_mail.create(cr, uid, {'state': 'cancel'}) mail = self.mail_mail.browse(cr, uid, mail_id) # Test: mail_mail content self.assertEqual(mail.reply_to, 'gateway@schlouby.fr', - 'mail_mail: reply_to should equal the catchall email alias') + 'mail_mail: reply_to should equal the catchall email alias') # Do: create a mail_mail mail_id = self.mail_mail.create(cr, uid, {'state': 'cancel', 'reply_to': 'someone@example.com'}) mail = self.mail_mail.browse(cr, uid, mail_id) # Test: mail_mail content self.assertEqual(mail.reply_to, 'someone@example.com', - 'mail_mail: reply_to should equal the rpely_to given to create') + 'mail_mail: reply_to should equal the rpely_to given to create') @mute_logger('openerp.addons.mail.mail_thread', 'openerp.osv.orm') def test_10_message_process(self): @@ -238,9 +254,9 @@ class TestMailgateway(TestMailBase): cr, uid, user_raoul = self.cr, self.uid, self.user_raoul def format_and_process(template, to='groups@example.com, other@gmail.com', subject='Frogs', - extra='', email_from='Sylvie Lelitre <test.sylvie.lelitre@agrolait.com>', - msg_id='<1198923581.41972151344608186760.JavaMail@agrolait.com>', - model=None): + extra='', email_from='Sylvie Lelitre <test.sylvie.lelitre@agrolait.com>', + msg_id='<1198923581.41972151344608186760.JavaMail@agrolait.com>', + model=None): self.assertEqual(self.mail_group.search(cr, uid, [('name', '=', subject)]), []) mail = template.format(to=to, subject=subject, extra=extra, email_from=email_from, msg_id=msg_id) self.mail_thread.message_process(cr, uid, model, mail) @@ -255,7 +271,10 @@ class TestMailgateway(TestMailBase): alias_id = self.mail_alias.create(cr, uid, { 'alias_name': 'groups', 'alias_user_id': False, - 'alias_model_id': self.mail_group_model_id}) + 'alias_model_id': self.mail_group_model_id, + 'alias_parent_model_id': self.mail_group_model_id, + 'alias_parent_thread_id': self.group_pigs_id, + 'alias_contact': 'everyone'}) # -------------------------------------------------- # Test1: new record creation @@ -270,155 +289,244 @@ class TestMailgateway(TestMailBase): frog_group = self.mail_group.browse(cr, uid, frog_groups[0]) res = self.mail_group.perm_read(cr, uid, [frog_group.id], details=False) self.assertEqual(res[0].get('create_uid'), uid, - 'message_process: group should have been created by uid as alias_user__id is False on the alias') + 'message_process: group should have been created by uid as alias_user__id is False on the alias') # Test: one message that is the incoming email self.assertEqual(len(frog_group.message_ids), 1, - 'message_process: newly created group should have the incoming email in message_ids') + 'message_process: newly created group should have the incoming email in message_ids') msg = frog_group.message_ids[0] self.assertEqual('Frogs', msg.subject, - 'message_process: newly created group should have the incoming email as first message') + 'message_process: newly created group should have the incoming email as first message') self.assertIn('Please call me as soon as possible this afternoon!', msg.body, - 'message_process: newly created group should have the incoming email as first message') + 'message_process: newly created group should have the incoming email as first message') self.assertEqual('email', msg.type, - 'message_process: newly created group should have an email as first message') + 'message_process: newly created group should have an email as first message') self.assertEqual('Discussions', msg.subtype_id.name, - 'message_process: newly created group should not have a log first message but an email') + 'message_process: newly created group should not have a log first message but an email') # Test: message: unknown email address -> message has email_from, not author_id self.assertFalse(msg.author_id, - 'message_process: message on created group should not have an author_id') + 'message_process: message on created group should not have an author_id') self.assertIn('test.sylvie.lelitre@agrolait.com', msg.email_from, - 'message_process: message on created group should have an email_from') + 'message_process: message on created group should have an email_from') # Test: followers: nobody self.assertEqual(len(frog_group.message_follower_ids), 0, 'message_process: newly create group should not have any follower') # Test: sent emails: no-one self.assertEqual(len(sent_emails), 0, - 'message_process: should create emails without any follower added') + 'message_process: should create emails without any follower added') # Data: unlink group frog_group.unlink() - # Do: incoming email from a known partner on an alias with known recipients, alias is owned by user that can create a group - self.mail_alias.write(cr, uid, [alias_id], {'alias_user_id': self.user_raoul_id}) + # Do: incoming email from an unknown partner on a Partners only alias -> bounce + self._init_mock_build_email() + self.mail_alias.write(cr, uid, [alias_id], {'alias_contact': 'partners'}) + frog_groups = format_and_process(MAIL_TEMPLATE, to='groups@example.com, other2@gmail.com') + # Test: no group created + self.assertTrue(len(frog_groups) == 0) + # Test: email bounced + sent_emails = self._build_email_kwargs_list + self.assertEqual(len(sent_emails), 1, + 'message_process: incoming email on Partners alias should send a bounce email') + self.assertIn('Frogs', sent_emails[0].get('subject'), + 'message_process: bounce email on Partners alias should contain the original subject') + self.assertIn('test.sylvie.lelitre@agrolait.com', sent_emails[0].get('email_to'), + 'message_process: bounce email on Partners alias should have original email sender as recipient') + + # Do: incoming email from an unknown partner on a Followers only alias -> bounce + self._init_mock_build_email() + self.mail_alias.write(cr, uid, [alias_id], {'alias_contact': 'followers'}) + frog_groups = format_and_process(MAIL_TEMPLATE, to='groups@example.com, other3@gmail.com') + # Test: no group created + self.assertTrue(len(frog_groups) == 0) + # Test: email bounced + sent_emails = self._build_email_kwargs_list + self.assertEqual(len(sent_emails), 1, + 'message_process: incoming email on Followers alias should send a bounce email') + self.assertIn('Frogs', sent_emails[0].get('subject'), + 'message_process: bounce email on Followers alias should contain the original subject') + self.assertIn('test.sylvie.lelitre@agrolait.com', sent_emails[0].get('email_to'), + 'message_process: bounce email on Followers alias should have original email sender as recipient') + + # Do: incoming email from a known partner on a Partners alias -> ok (+ test on alias.user_id) + self.mail_alias.write(cr, uid, [alias_id], {'alias_user_id': self.user_raoul_id, 'alias_contact': 'partners'}) p1id = self.res_partner.create(cr, uid, {'name': 'Sylvie Lelitre', 'email': 'test.sylvie.lelitre@agrolait.com'}) - p2id = self.res_partner.create(cr, uid, {'name': 'Other Poilvache', 'email': 'other@gmail.com'}) + p2id = self.res_partner.create(cr, uid, {'name': 'Other Poilvache', 'email': 'other4@gmail.com'}) self._init_mock_build_email() - frog_groups = format_and_process(MAIL_TEMPLATE, to='groups@example.com, other@gmail.com') + frog_groups = format_and_process(MAIL_TEMPLATE, to='groups@example.com, other4@gmail.com') sent_emails = self._build_email_kwargs_list # Test: one group created by Raoul self.assertEqual(len(frog_groups), 1, 'message_process: a new mail.group should have been created') frog_group = self.mail_group.browse(cr, uid, frog_groups[0]) res = self.mail_group.perm_read(cr, uid, [frog_group.id], details=False) self.assertEqual(res[0].get('create_uid'), self.user_raoul_id, - 'message_process: group should have been created by alias_user_id') + 'message_process: group should have been created by alias_user_id') # Test: one message that is the incoming email self.assertEqual(len(frog_group.message_ids), 1, - 'message_process: newly created group should have the incoming email in message_ids') + 'message_process: newly created group should have the incoming email in message_ids') msg = frog_group.message_ids[0] - # Test: message: unknown email address -> message has email_from, not author_id + # Test: message: author found self.assertEqual(p1id, msg.author_id.id, - 'message_process: message on created group should have Sylvie as author_id') + 'message_process: message on created group should have Sylvie as author_id') self.assertIn('Sylvie Lelitre <test.sylvie.lelitre@agrolait.com>', msg.email_from, - 'message_process: message on created group should have have an email_from') - # Test: author (not recipient and not raoul (as alias owner)) added as follower + 'message_process: message on created group should have have an email_from') + # Test: author (not recipient and not Raoul (as alias owner)) added as follower frog_follower_ids = set([p.id for p in frog_group.message_follower_ids]) self.assertEqual(frog_follower_ids, set([p1id]), - 'message_process: newly created group should have 1 follower (author, not creator, not recipients)') + 'message_process: newly created group should have 1 follower (author, not creator, not recipients)') # Test: sent emails: no-one, no bounce effet + sent_emails = self._build_email_kwargs_list self.assertEqual(len(sent_emails), 0, - 'message_process: should not bounce incoming emails') + 'message_process: should not bounce incoming emails') # Data: unlink group frog_group.unlink() - # Do: incoming email from a known partner that is also an user that can create a mail.group - self.res_users.create(cr, uid, {'partner_id': p1id, 'login': 'sylvie', 'groups_id': [(6, 0, [self.group_employee_id])]}) - frog_groups = format_and_process(MAIL_TEMPLATE, to='groups@example.com, other@gmail.com') + # Do: incoming email from a not follower Partner on a Followers only alias -> bounce + self._init_mock_build_email() + self.mail_alias.write(cr, uid, [alias_id], {'alias_user_id': False, 'alias_contact': 'followers'}) + frog_groups = format_and_process(MAIL_TEMPLATE, to='groups@example.com, other5@gmail.com') + # Test: no group created + self.assertTrue(len(frog_groups) == 0) + # Test: email bounced + sent_emails = self._build_email_kwargs_list + self.assertEqual(len(sent_emails), 1, + 'message_process: incoming email on Partners alias should send a bounce email') + + # Do: incoming email from a parent document follower on a Followers only alias -> ok + self._init_mock_build_email() + self.mail_group.message_subscribe(cr, uid, [self.group_pigs_id], [p1id]) + frog_groups = format_and_process(MAIL_TEMPLATE, to='groups@example.com, other6@gmail.com') # Test: one group created by Raoul (or Sylvie maybe, if we implement it) self.assertEqual(len(frog_groups), 1, 'message_process: a new mail.group should have been created') frog_group = self.mail_group.browse(cr, uid, frog_groups[0]) # Test: one message that is the incoming email self.assertEqual(len(frog_group.message_ids), 1, - 'message_process: newly created group should have the incoming email in message_ids') + 'message_process: newly created group should have the incoming email in message_ids') # Test: author (and not recipient) added as follower frog_follower_ids = set([p.id for p in frog_group.message_follower_ids]) self.assertEqual(frog_follower_ids, set([p1id]), - 'message_process: newly created group should have 1 follower (author, not creator, not recipients)') + 'message_process: newly created group should have 1 follower (author, not creator, not recipients)') # Test: sent emails: no-one, no bounce effet + sent_emails = self._build_email_kwargs_list self.assertEqual(len(sent_emails), 0, - 'message_process: should not bounce incoming emails') + 'message_process: should not bounce incoming emails') # -------------------------------------------------- - # Test2: discussion update + # Test2: update-like alias # -------------------------------------------------- - # Do: even with a wrong destination, a reply should end up in the correct thread - frog_groups = format_and_process(MAIL_TEMPLATE, email_from='other@gmail.com', - msg_id='<1198923581.41972151344608186760.JavaMail.diff1@agrolait.com>', - to='erroneous@example.com>', subject='Re: news', - extra='In-Reply-To: <12321321-openerp-%d-mail.group@example.com>\n' % frog_group.id) + # Do: Pigs alias is restricted, should bounce + self._init_mock_build_email() + self.mail_group.write(cr, uid, [frog_group.id], {'alias_name': 'frogs', 'alias_contact': 'followers', 'alias_force_thread_id': frog_group.id}) + frog_groups = format_and_process(MAIL_TEMPLATE, email_from='other4@gmail.com', + msg_id='<1198923581.41972151344608186760.JavaMail.diff1@agrolait.com>', + to='frogs@example.com>', subject='Re: news') + # Test: no group 'Re: news' created, still only 1 Frogs group + self.assertEqual(len(frog_groups), 0, + 'message_process: reply on Frogs should not have created a new group with new subject') + frog_groups = self.mail_group.search(cr, uid, [('name', '=', 'Frogs')]) + self.assertEqual(len(frog_groups), 1, + 'message_process: reply on Frogs should not have created a duplicate group with old subject') + frog_group = self.mail_group.browse(cr, uid, frog_groups[0]) + # Test: email bounced + sent_emails = self._build_email_kwargs_list + self.assertEqual(len(sent_emails), 1, + 'message_process: incoming email on Followers alias should send a bounce email') + self.assertIn('Re: news', sent_emails[0].get('subject'), + 'message_process: bounce email on Followers alias should contain the original subject') + + # Do: Pigs alias is restricted, should accept Followers + self._init_mock_build_email() + self.mail_group.message_subscribe(cr, uid, [frog_group.id], [p2id]) + frog_groups = format_and_process(MAIL_TEMPLATE, email_from='other4@gmail.com', + msg_id='<1198923581.41972151344608186799.JavaMail.diff1@agrolait.com>', + to='frogs@example.com>', subject='Re: cats') # Test: no group 'Re: news' created, still only 1 Frogs group self.assertEqual(len(frog_groups), 0, - 'message_process: reply on Frogs should not have created a new group with new subject') + 'message_process: reply on Frogs should not have created a new group with new subject') frog_groups = self.mail_group.search(cr, uid, [('name', '=', 'Frogs')]) self.assertEqual(len(frog_groups), 1, - 'message_process: reply on Frogs should not have created a duplicate group with old subject') + 'message_process: reply on Frogs should not have created a duplicate group with old subject') frog_group = self.mail_group.browse(cr, uid, frog_groups[0]) # Test: one new message self.assertEqual(len(frog_group.message_ids), 2, 'message_process: group should contain 2 messages after reply') + # Test: sent emails: 1 (Sylvie copy of the incoming email, but no bounce) + sent_emails = self._build_email_kwargs_list + self.assertEqual(len(sent_emails), 1, + 'message_process: one email should have been generated') + self.assertIn('test.sylvie.lelitre@agrolait.com', sent_emails[0].get('email_to')[0], + 'message_process: email should be sent to Sylvie') + self.mail_group.message_unsubscribe(cr, uid, [frog_group.id], [p2id]) + + # -------------------------------------------------- + # Test3: discussion and replies + # -------------------------------------------------- + + # Do: even with a wrong destination, a reply should end up in the correct thread + frog_groups = format_and_process(MAIL_TEMPLATE, email_from='other4@gmail.com', + msg_id='<1198923581.41972151344608186760.JavaMail.diff1@agrolait.com>', + to='erroneous@example.com>', subject='Re: news', + extra='In-Reply-To: <12321321-openerp-%d-mail.group@example.com>\n' % frog_group.id) + # Test: no group 'Re: news' created, still only 1 Frogs group + self.assertEqual(len(frog_groups), 0, + 'message_process: reply on Frogs should not have created a new group with new subject') + frog_groups = self.mail_group.search(cr, uid, [('name', '=', 'Frogs')]) + self.assertEqual(len(frog_groups), 1, + 'message_process: reply on Frogs should not have created a duplicate group with old subject') + frog_group = self.mail_group.browse(cr, uid, frog_groups[0]) + # Test: one new message + self.assertEqual(len(frog_group.message_ids), 3, 'message_process: group should contain 2 messages after reply') # Test: author (and not recipient) added as follower frog_follower_ids = set([p.id for p in frog_group.message_follower_ids]) self.assertEqual(frog_follower_ids, set([p1id, p2id]), - 'message_process: after reply, group should have 2 followers') + 'message_process: after reply, group should have 2 followers') # Do: due to some issue, same email goes back into the mailgateway - frog_groups = format_and_process(MAIL_TEMPLATE, email_from='other@gmail.com', - msg_id='<1198923581.41972151344608186760.JavaMail.diff1@agrolait.com>', - subject='Re: news', extra='In-Reply-To: <12321321-openerp-%d-mail.group@example.com>\n' % frog_group.id) + frog_groups = format_and_process(MAIL_TEMPLATE, email_from='other4@gmail.com', + msg_id='<1198923581.41972151344608186760.JavaMail.diff1@agrolait.com>', + subject='Re: news', extra='In-Reply-To: <12321321-openerp-%d-mail.group@example.com>\n' % frog_group.id) # Test: no group 'Re: news' created, still only 1 Frogs group self.assertEqual(len(frog_groups), 0, - 'message_process: reply on Frogs should not have created a new group with new subject') + 'message_process: reply on Frogs should not have created a new group with new subject') frog_groups = self.mail_group.search(cr, uid, [('name', '=', 'Frogs')]) self.assertEqual(len(frog_groups), 1, - 'message_process: reply on Frogs should not have created a duplicate group with old subject') + 'message_process: reply on Frogs should not have created a duplicate group with old subject') frog_group = self.mail_group.browse(cr, uid, frog_groups[0]) # Test: no new message - self.assertEqual(len(frog_group.message_ids), 2, 'message_process: message with already existing message_id should not have been duplicated') + self.assertEqual(len(frog_group.message_ids), 3, 'message_process: message with already existing message_id should not have been duplicated') # Test: message_id is still unique msg_ids = self.mail_message.search(cr, uid, [('message_id', 'ilike', '<1198923581.41972151344608186760.JavaMail.diff1@agrolait.com>')]) self.assertEqual(len(msg_ids), 1, - 'message_process: message with already existing message_id should not have been duplicated') + 'message_process: message with already existing message_id should not have been duplicated') # -------------------------------------------------- - # Test3: email_from and partner finding + # Test4: email_from and partner finding # -------------------------------------------------- # Data: extra partner with Raoul's email -> test the 'better author finding' extra_partner_id = self.res_partner.create(cr, uid, {'name': 'A-Raoul', 'email': 'test_raoul@email.com'}) - # extra_user_id = self.res_users.create(cr, uid, {'name': 'B-Raoul', 'email': self.user_raoul.email}) - # extra_user_pid = self.res_users.browse(cr, uid, extra_user_id).partner_id.id # Do: post a new message, with a known partner -> duplicate emails -> partner format_and_process(MAIL_TEMPLATE, email_from='Lombrik Lubrik <test_raoul@email.com>', - to='erroneous@example.com>', subject='Re: news (2)', - msg_id='<1198923581.41972151344608186760.JavaMail.new1@agrolait.com>', - extra='In-Reply-To: <12321321-openerp-%d-mail.group@example.com>\n' % frog_group.id) + to='erroneous@example.com>', subject='Re: news (2)', + msg_id='<1198923581.41972151344608186760.JavaMail.new1@agrolait.com>', + extra='In-Reply-To: <12321321-openerp-%d-mail.group@example.com>\n' % frog_group.id) frog_groups = self.mail_group.search(cr, uid, [('name', '=', 'Frogs')]) frog_group = self.mail_group.browse(cr, uid, frog_groups[0]) # Test: author is A-Raoul (only existing) self.assertEqual(frog_group.message_ids[0].author_id.id, extra_partner_id, - 'message_process: email_from -> author_id wrong') + 'message_process: email_from -> author_id wrong') # Do: post a new message, with a known partner -> duplicate emails -> user frog_group.message_unsubscribe([extra_partner_id]) raoul_email = self.user_raoul.email self.res_users.write(cr, uid, self.user_raoul_id, {'email': 'test_raoul@email.com'}) format_and_process(MAIL_TEMPLATE, email_from='Lombrik Lubrik <test_raoul@email.com>', - to='erroneous@example.com>', subject='Re: news (3)', - msg_id='<1198923581.41972151344608186760.JavaMail.new2@agrolait.com>', - extra='In-Reply-To: <12321321-openerp-%d-mail.group@example.com>\n' % frog_group.id) + to='erroneous@example.com>', subject='Re: news (3)', + msg_id='<1198923581.41972151344608186760.JavaMail.new2@agrolait.com>', + extra='In-Reply-To: <12321321-openerp-%d-mail.group@example.com>\n' % frog_group.id) frog_groups = self.mail_group.search(cr, uid, [('name', '=', 'Frogs')]) frog_group = self.mail_group.browse(cr, uid, frog_groups[0]) # Test: author is Raoul (user), not A-Raoul self.assertEqual(frog_group.message_ids[0].author_id.id, self.partner_raoul_id, - 'message_process: email_from -> author_id wrong') + 'message_process: email_from -> author_id wrong') # Do: post a new message, with a known partner -> duplicate emails -> partner because is follower frog_group.message_unsubscribe([self.partner_raoul_id]) @@ -426,54 +534,54 @@ class TestMailgateway(TestMailBase): raoul_email = self.user_raoul.email self.res_users.write(cr, uid, self.user_raoul_id, {'email': 'test_raoul@email.com'}) format_and_process(MAIL_TEMPLATE, email_from='Lombrik Lubrik <test_raoul@email.com>', - to='erroneous@example.com>', subject='Re: news (3)', - msg_id='<1198923581.41972151344608186760.JavaMail.new3@agrolait.com>', - extra='In-Reply-To: <12321321-openerp-%d-mail.group@example.com>\n' % frog_group.id) + to='erroneous@example.com>', subject='Re: news (3)', + msg_id='<1198923581.41972151344608186760.JavaMail.new3@agrolait.com>', + extra='In-Reply-To: <12321321-openerp-%d-mail.group@example.com>\n' % frog_group.id) frog_groups = self.mail_group.search(cr, uid, [('name', '=', 'Frogs')]) frog_group = self.mail_group.browse(cr, uid, frog_groups[0]) # Test: author is Raoul (user), not A-Raoul self.assertEqual(frog_group.message_ids[0].author_id.id, extra_partner_id, - 'message_process: email_from -> author_id wrong') + 'message_process: email_from -> author_id wrong') self.res_users.write(cr, uid, self.user_raoul_id, {'email': raoul_email}) # -------------------------------------------------- - # Test4: misc gateway features + # Test5: misc gateway features # -------------------------------------------------- # Do: incoming email with model that does not accepts incoming emails must raise self.assertRaises(AssertionError, - format_and_process, - MAIL_TEMPLATE, - to='noone@example.com', subject='spam', extra='', model='res.country', - msg_id='<1198923581.41972151344608186760.JavaMail.new4@agrolait.com>') + format_and_process, + MAIL_TEMPLATE, + to='noone@example.com', subject='spam', extra='', model='res.country', + msg_id='<1198923581.41972151344608186760.JavaMail.new4@agrolait.com>') # Do: incoming email without model and without alias must raise self.assertRaises(AssertionError, - format_and_process, - MAIL_TEMPLATE, - to='noone@example.com', subject='spam', extra='', - msg_id='<1198923581.41972151344608186760.JavaMail.new5@agrolait.com>') + format_and_process, + MAIL_TEMPLATE, + to='noone@example.com', subject='spam', extra='', + msg_id='<1198923581.41972151344608186760.JavaMail.new5@agrolait.com>') # Do: incoming email with model that accepting incoming emails as fallback frog_groups = format_and_process(MAIL_TEMPLATE, - to='noone@example.com', - subject='Spammy', extra='', model='mail.group', - msg_id='<1198923581.41972151344608186760.JavaMail.new6@agrolait.com>') + to='noone@example.com', + subject='Spammy', extra='', model='mail.group', + msg_id='<1198923581.41972151344608186760.JavaMail.new6@agrolait.com>') self.assertEqual(len(frog_groups), 1, - 'message_process: erroneous email but with a fallback model should have created a new mail.group') + 'message_process: erroneous email but with a fallback model should have created a new mail.group') # Do: incoming email in plaintext should be stored as html frog_groups = format_and_process(MAIL_TEMPLATE_PLAINTEXT, - to='groups@example.com', subject='Frogs Return', extra='', - msg_id='<deadcafe.1337@smtp.agrolait.com>') + to='groups@example.com', subject='Frogs Return', extra='', + msg_id='<deadcafe.1337@smtp.agrolait.com>') # Test: one group created with one message self.assertEqual(len(frog_groups), 1, 'message_process: a new mail.group should have been created') frog_group = self.mail_group.browse(cr, uid, frog_groups[0]) msg = frog_group.message_ids[0] # Test: plain text content should be wrapped and stored as html - self.assertEqual(msg.body, '<pre>\nPlease call me as soon as possible this afternoon!\n\n--\nSylvie\n</pre>', - 'message_process: plaintext incoming email incorrectly parsed') + self.assertIn('<pre>\nPlease call me as soon as possible this afternoon!\n\n--\nSylvie\n</pre>', msg.body, + 'message_process: plaintext incoming email incorrectly parsed') @mute_logger('openerp.addons.mail.mail_thread', 'openerp.osv.orm') def test_20_thread_parent_resolution(self): @@ -494,26 +602,26 @@ class TestMailgateway(TestMailBase): # Reply to msg1, make sure the reply is properly attached using the various reply identification mechanisms # 0. Direct alias match reply_msg1 = format(MAIL_TEMPLATE, to='Pretty Pigs <group+pigs@example.com>', - extra='In-Reply-To: %s' % msg1.message_id, - msg_id='<1198923581.41972151344608186760.JavaMail.2@agrolait.com>') + extra='In-Reply-To: %s' % msg1.message_id, + msg_id='<1198923581.41972151344608186760.JavaMail.2@agrolait.com>') self.mail_group.message_process(cr, uid, None, reply_msg1) # 1. In-Reply-To header reply_msg2 = format(MAIL_TEMPLATE, to='erroneous@example.com', - extra='In-Reply-To: %s' % msg1.message_id, - msg_id='<1198923581.41972151344608186760.JavaMail.3@agrolait.com>') + extra='In-Reply-To: %s' % msg1.message_id, + msg_id='<1198923581.41972151344608186760.JavaMail.3@agrolait.com>') self.mail_group.message_process(cr, uid, None, reply_msg2) # 2. References header reply_msg3 = format(MAIL_TEMPLATE, to='erroneous@example.com', - extra='References: <2233@a.com>\r\n\t<3edss_dsa@b.com> %s' % msg1.message_id, - msg_id='<1198923581.41972151344608186760.JavaMail.4@agrolait.com>') + extra='References: <2233@a.com>\r\n\t<3edss_dsa@b.com> %s' % msg1.message_id, + msg_id='<1198923581.41972151344608186760.JavaMail.4@agrolait.com>') self.mail_group.message_process(cr, uid, None, reply_msg3) # 3. Subject contains [<ID>] + model passed to message+process -> only attached to group, but not to mail (not in msg1.child_ids) reply_msg4 = format(MAIL_TEMPLATE, to='erroneous@example.com', - extra='', subject='Re: [%s] 1' % self.group_pigs_id, - msg_id='<1198923581.41972151344608186760.JavaMail.5@agrolait.com>') + extra='', subject='Re: [%s] 1' % self.group_pigs_id, + msg_id='<1198923581.41972151344608186760.JavaMail.5@agrolait.com>') self.mail_group.message_process(cr, uid, 'mail.group', reply_msg4) group_pigs.refresh() @@ -525,12 +633,19 @@ class TestMailgateway(TestMailBase): """ Testing private discussion between partners. """ cr, uid = self.cr, self.uid + def format(template, to='Pretty Pigs <group+pigs@example.com>, other@gmail.com', subject='Re: 1', + extra='', email_from='Sylvie Lelitre <test.sylvie.lelitre@agrolait.com>', + msg_id='<1198923581.41972151344608186760.JavaMail@agrolait.com>'): + return template.format(to=to, subject=subject, extra=extra, email_from=email_from, msg_id=msg_id) + # Do: Raoul writes to Bert and Administrator, with a thread_model in context that should not be taken into account msg1_pids = [self.partner_admin_id, self.partner_bert_id] - msg1_id = self.mail_thread.message_post(cr, self.user_raoul_id, False, - partner_ids=msg1_pids, - subtype='mail.mt_comment', - context={'thread_model': 'mail.group'}) + msg1_id = self.mail_thread.message_post( + cr, self.user_raoul_id, False, + partner_ids=msg1_pids, + subtype='mail.mt_comment', + context={'thread_model': 'mail.group'} + ) # Test: message recipients msg = self.mail_message.browse(cr, uid, msg1_id) @@ -539,16 +654,26 @@ class TestMailgateway(TestMailBase): test_pids = msg1_pids test_nids = msg1_pids self.assertEqual(set(msg_pids), set(test_pids), - 'message_post: private discussion: incorrect recipients') + 'message_post: private discussion: incorrect recipients') self.assertEqual(set(msg_nids), set(test_nids), - 'message_post: private discussion: incorrect notified recipients') + 'message_post: private discussion: incorrect notified recipients') self.assertEqual(msg.model, False, - 'message_post: private discussion: context key "thread_model" not correctly ignored when having no res_id') + 'message_post: private discussion: context key "thread_model" not correctly ignored when having no res_id') + # Test: message reply_to and message-id + self.assertFalse(msg.reply_to, + 'message_post: private discussion: initial message should not have any reply_to specified') + self.assertIn('openerp-private', msg.message_id, + 'message_post: private discussion: message-id should contain the private keyword') # Do: Bert replies through mailgateway (is a customer) - msg2_id = self.mail_thread.message_post(cr, uid, False, - author_id=self.partner_bert_id, - parent_id=msg1_id, subtype='mail.mt_comment') + reply_message = format(MAIL_TEMPLATE, to='not_important@mydomain.com', + email_from='bert@bert.fr', + extra='In-Reply-To: %s' % msg.message_id, + msg_id='<test30.JavaMail.0@agrolait.com>') + self.mail_thread.message_process(cr, uid, None, reply_message) + + # Test: last mail_message created + msg2_id = self.mail_message.search(cr, uid, [], limit=1)[0] # Test: message recipients msg = self.mail_message.browse(cr, uid, msg2_id) @@ -556,14 +681,32 @@ class TestMailgateway(TestMailBase): msg_nids = [p.id for p in msg.notified_partner_ids] test_pids = [self.partner_admin_id, self.partner_raoul_id] test_nids = test_pids + self.assertEqual(msg.author_id.id, self.partner_bert_id, + 'message_post: private discussion: wrong author through mailgatewya based on email') + self.assertEqual(set(msg_pids), set(test_pids), + 'message_post: private discussion: incorrect recipients when replying') + self.assertEqual(set(msg_nids), set(test_nids), + 'message_post: private discussion: incorrect notified recipients when replying') + + # Do: Bert replies through chatter (is a customer) + msg3_id = self.mail_thread.message_post( + cr, uid, False, + author_id=self.partner_bert_id, + parent_id=msg1_id, subtype='mail.mt_comment') + + # Test: message recipients + msg = self.mail_message.browse(cr, uid, msg3_id) + msg_pids = [p.id for p in msg.partner_ids] + msg_nids = [p.id for p in msg.notified_partner_ids] + test_pids = [self.partner_admin_id, self.partner_raoul_id] + test_nids = test_pids self.assertEqual(set(msg_pids), set(test_pids), - 'message_post: private discussion: incorrect recipients when replying') + 'message_post: private discussion: incorrect recipients when replying') self.assertEqual(set(msg_nids), set(test_nids), - 'message_post: private discussion: incorrect notified recipients when replying') + 'message_post: private discussion: incorrect notified recipients when replying') # Do: Administrator replies - msg3_id = self.mail_thread.message_post(cr, uid, False, - parent_id=msg2_id, subtype='mail.mt_comment') + msg3_id = self.mail_thread.message_post(cr, uid, False, parent_id=msg3_id, subtype='mail.mt_comment') # Test: message recipients msg = self.mail_message.browse(cr, uid, msg3_id) @@ -572,6 +715,6 @@ class TestMailgateway(TestMailBase): test_pids = [self.partner_bert_id, self.partner_raoul_id] test_nids = test_pids self.assertEqual(set(msg_pids), set(test_pids), - 'message_post: private discussion: incorrect recipients when replying') + 'message_post: private discussion: incorrect recipients when replying') self.assertEqual(set(msg_nids), set(test_nids), - 'message_post: private discussion: incorrect notified recipients when replying') + 'message_post: private discussion: incorrect notified recipients when replying') |
