From dbaeee703fc16027bf17552acc6bb3c409d21958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 22 Mar 2013 16:57:34 +0100 Subject: [IMP] mail: alias_contact on alias. However, not sure this will be usefull, to discuss. bzr revid: tde@openerp.com-20130322155734-9jfc7w8nw8oiytd4 --- addons/mail/tests/test_mail_gateway.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'addons/mail/tests') diff --git a/addons/mail/tests/test_mail_gateway.py b/addons/mail/tests/test_mail_gateway.py index a68011298c7..74cdd06ed63 100644 --- a/addons/mail/tests/test_mail_gateway.py +++ b/addons/mail/tests/test_mail_gateway.py @@ -105,7 +105,8 @@ 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_contact': 'everyone'}) # -------------------------------------------------- # Test1: new record creation @@ -146,6 +147,21 @@ class TestMailgateway(TestMailBase): # Data: unlink group frog_group.unlink() + # Do: incoming email from an unknown partner on a restricted alias + 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, other@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 private alias should send a bounce email') + self.assertIn('Frogs', sent_emails[0].get('subject'), + 'message_process: bounce email on private alias should contain the original subject') + self.assertIn('test.sylvie.lelitre@agrolait.com', sent_emails[0].get('email_to'), + 'message_process: bounce email on private alias should have original email sender as recipient') + # 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}) p1id = self.res_partner.create(cr, uid, {'name': 'Sylvie Lelitre', 'email': 'test.sylvie.lelitre@agrolait.com'}) -- cgit v1.2.3 From a3de5c872f7c26ec085dc62b95cfc62382ab970a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 9 Apr 2013 13:11:58 +0200 Subject: [REF] [IMP] mail_alias improvement alias_name is not required anymore crm, hr_job, project, mail_group, res_users: alias creation is now different and done more like other inherits, except an alias_model_name that is given to the context to find the alias alias_model_id. crm, jr_job, project, mail_group, res_users: updated form views using aliases mail_alias: added a filter on 'inactive' aliases (alias_name False) and added a button to redirect to the related document if any bzr revid: tde@openerp.com-20130409111158-bv04n5o01z9l3c17 --- addons/mail/tests/test_mail_base.py | 6 +++--- addons/mail/tests/test_mail_features.py | 9 ++++----- 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'addons/mail/tests') diff --git a/addons/mail/tests/test_mail_base.py b/addons/mail/tests/test_mail_base.py index a3b90288f0b..0de2dc322ec 100644 --- a/addons/mail/tests/test_mail_base.py +++ b/addons/mail/tests/test_mail_base.py @@ -70,9 +70,9 @@ class TestMailBase(common.TransactionCase): # Test users to use through the various tests 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 +82,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 7eea66b3b90..f23440d8af4 100644 --- a/addons/mail/tests/test_mail_features.py +++ b/addons/mail/tests/test_mail_features.py @@ -24,26 +24,25 @@ from openerp.tools.mail import html_sanitize class test_mail(TestMailBase): - + def test_000_alias_setup(self): """ 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') - def test_00_followers_function_field(self): """ Tests designed for the many2many function field 'follower_ids'. We will test to perform writes using the many2many commands 0, 3, 4, -- cgit v1.2.3 From 7f6a47559094c57d2e858e1749b6c37237f96582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 16 Apr 2013 15:28:13 +0200 Subject: [IMP] [REF] mail_thread: refactored a bit message_parse, message_route and various find_partner methods. Now handles private aliases (alias_contact as partners or followers). message_route now works in 2 steps : 1/ finding all possible routes, as before 2/ checks and filtrates those routes, by finding the most relevant message author and using it to check alias contact settings. Also refactored the various partner finding method in one method that checks in res.partner, for: partners, partners that are users, partners that follow a given document. bzr revid: tde@openerp.com-20130416132813-zcm1r5kx0dwrfeic --- addons/mail/tests/test_mail_gateway.py | 46 +++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 14 deletions(-) (limited to 'addons/mail/tests') diff --git a/addons/mail/tests/test_mail_gateway.py b/addons/mail/tests/test_mail_gateway.py index b0cf785cbb7..6c46a9e75c9 100644 --- a/addons/mail/tests/test_mail_gateway.py +++ b/addons/mail/tests/test_mail_gateway.py @@ -20,6 +20,7 @@ ############################################################################## from openerp.addons.mail.tests.test_mail_base import TestMailBase +from openerp.tools import mute_logger MAIL_TEMPLATE = """Return-Path: To: {to} @@ -98,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 '], link_mail=False)[0] + partner_info = self.mail_thread.message_partner_info_from_emails(cr, uid, None, ['Maybe Raoul '], link_mail=False)[0] self.assertEqual(partner_info['full_name'], 'Maybe Raoul ', - '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 '], link_mail=False)[0] + partner_info = self.mail_thread.message_partner_info_from_emails(cr, uid, None, ['Maybe Raoul '], 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 @@ -119,10 +120,11 @@ 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 '], link_mail=False)[0] + partner_info = self.mail_group.message_partner_info_from_emails(cr, uid, group_pigs.id, ['Maybe Raoul '], 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') + @mute_logger('openerp.addons.mail.mail_thread', 'openerp.osv.orm') def test_10_message_process(self): """ Testing incoming emails processing. """ cr, uid, user_raoul = self.cr, self.uid, self.user_raoul @@ -187,27 +189,42 @@ class TestMailgateway(TestMailBase): # Data: unlink group frog_group.unlink() - # Do: incoming email from an unknown partner on a restricted alias + # Do: incoming email from an unknown partner on an Authenticated 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, other@gmail.com') + 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 private alias should send a bounce email') + '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 private alias should contain the original 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 private alias should have original email sender as recipient') + '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 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}) + 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'}) 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') @@ -381,6 +398,7 @@ class TestMailgateway(TestMailBase): self.assertEqual(msg.body, '
\nPlease call me as soon as possible this afternoon!\n\n--\nSylvie\n
', 'message_process: plaintext incoming email incorrectly parsed') + @mute_logger('openerp.addons.mail.mail_thread', 'openerp.osv.orm') def test_20_thread_parent_resolution(self): """ Testing parent/child relationships are correctly established when processing incoming mails """ cr, uid = self.cr, self.uid -- cgit v1.2.3 From 88e3505554038350ae0274e9359bbffff342b9d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 16 May 2013 18:42:07 +0200 Subject: [IMP] mail_alias: added reference to the parent record. The parent record is the record that holds the alias. It is different from the record updated or created using the alias. For example projects have aliases whose parent is the given projet, and that creates new task inside the project. Updated alias creation and management accordingly. This ownership concept is used to compute the 'followers' contact settings of aliases. bzr revid: tde@openerp.com-20130516164207-1zr0q6abw6a34ndf --- addons/mail/tests/test_mail_gateway.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'addons/mail/tests') diff --git a/addons/mail/tests/test_mail_gateway.py b/addons/mail/tests/test_mail_gateway.py index 6c46a9e75c9..39f96c81674 100644 --- a/addons/mail/tests/test_mail_gateway.py +++ b/addons/mail/tests/test_mail_gateway.py @@ -148,6 +148,8 @@ class TestMailgateway(TestMailBase): 'alias_name': 'groups', 'alias_user_id': False, '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'}) # -------------------------------------------------- -- cgit v1.2.3 From 2f2d833a4a98fb33416b3f2a0d804943f618023e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 17 May 2013 17:13:21 +0200 Subject: [TEST] mail: added and fixed tests bzr revid: tde@openerp.com-20130517151321-9qu4bw6222lx3pa2 --- addons/mail/tests/test_mail_gateway.py | 91 +++++++++++++++++++++++++++++----- 1 file changed, 78 insertions(+), 13 deletions(-) (limited to 'addons/mail/tests') diff --git a/addons/mail/tests/test_mail_gateway.py b/addons/mail/tests/test_mail_gateway.py index 39f96c81674..abb00841a8f 100644 --- a/addons/mail/tests/test_mail_gateway.py +++ b/addons/mail/tests/test_mail_gateway.py @@ -206,10 +206,25 @@ class TestMailgateway(TestMailBase): 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 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, 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 Partners 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 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') + frog_groups = format_and_process(MAIL_TEMPLATE, to='groups@example.com, other4@gmail.com') # Test: no group created self.assertTrue(len(frog_groups) == 0) # Test: email bounced @@ -226,7 +241,7 @@ class TestMailgateway(TestMailBase): 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'}) self._init_mock_build_email() - frog_groups = format_and_process(MAIL_TEMPLATE, to='groups@example.com, other4@gmail.com') + frog_groups = format_and_process(MAIL_TEMPLATE, to='groups@example.com, other@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') @@ -238,7 +253,7 @@ class TestMailgateway(TestMailBase): self.assertEqual(len(frog_group.message_ids), 1, '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') self.assertIn('Sylvie Lelitre ', msg.email_from, @@ -248,14 +263,17 @@ class TestMailgateway(TestMailBase): self.assertEqual(frog_follower_ids, set([p1id]), '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') # 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 -> ok + self._init_mock_build_email() + self.mail_alias.write(cr, uid, [alias_id], {'alias_contact': 'followers'}) + 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]) @@ -267,11 +285,60 @@ class TestMailgateway(TestMailBase): self.assertEqual(frog_follower_ids, set([p1id]), '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') # -------------------------------------------------- - # Test2: discussion update + # Test2: update-like alias + # -------------------------------------------------- + + # 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='other@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]) + self.mail_group.write(cr, uid, [frog_group.id], {'alias_name': 'frogs', 'alias_contact': 'followers'}) + frog_groups = format_and_process(MAIL_TEMPLATE, email_from='other@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') + 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), 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 @@ -287,7 +354,7 @@ class TestMailgateway(TestMailBase): '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') + 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]), @@ -305,20 +372,18 @@ class TestMailgateway(TestMailBase): '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') # -------------------------------------------------- - # 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 ', @@ -363,7 +428,7 @@ class TestMailgateway(TestMailBase): 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 -- cgit v1.2.3 From fd90140d7bd05820aeac7bd7e22539893f87319d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 24 Jun 2013 17:18:27 +0200 Subject: [REF] mail_thread: refactored message_route improvement, to be closer to the original code + call to a new method that checks the route, instead of doing everything in one method. bzr revid: tde@openerp.com-20130624151827-hxwaelefs540pvca --- addons/mail/tests/test_mail_gateway.py | 136 ++++++--------------------------- 1 file changed, 25 insertions(+), 111 deletions(-) (limited to 'addons/mail/tests') diff --git a/addons/mail/tests/test_mail_gateway.py b/addons/mail/tests/test_mail_gateway.py index 7f1adf6cbe9..2e0ba336dc4 100644 --- a/addons/mail/tests/test_mail_gateway.py +++ b/addons/mail/tests/test_mail_gateway.py @@ -189,6 +189,7 @@ class TestMailgateway(TestMailBase): # Data: set catchall domain 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, user_raoul_id, [msg_id], {'email_from': False, 'reply_to': False}) @@ -220,87 +221,6 @@ class TestMailgateway(TestMailBase): self.assertEqual(mail.reply_to, msg.email_from, 'mail_mail: incorrect reply_to: should be message email_from') - 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 - 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) - # 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') - # 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) - # 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) - # Test: message content - self.assertIn('mail.group', msg.message_id, - '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') - 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() - # 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.assertEqual(email_split(mail.reply_to), email_split(msg.email_from), - 'mail_mail: reply_to should be equal to mail_message.email_from when having no document or default alias') - - # Data: set catchall domain - self.registry('ir.config_parameter').set_param(cr, uid, 'mail.catchall.domain', 'schlouby.fr') - 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}) - 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) - # Test: mail_mail content - self.assertEqual(mail.reply_to, '"Followers of Pigs" ', - 'mail_mail: reply_to should equal the mail.group alias') - - # Update message - self.mail_message.write(cr, uid, [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) - # Test: mail_mail content - self.assertEqual(mail.reply_to, msg.email_from, - 'mail_mail: reply_to should equal the mail_message email_from') - # Data: set catchall alias self.registry('ir.config_parameter').set_param(self.cr, self.uid, 'mail.catchall.alias', 'gateway') @@ -310,7 +230,7 @@ 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') @@ -395,7 +315,7 @@ class TestMailgateway(TestMailBase): # Data: unlink group frog_group.unlink() - # Do: incoming email from an unknown partner on an Authenticated only alias -> bounce + # 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') @@ -410,25 +330,10 @@ class TestMailgateway(TestMailBase): 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 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, 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 Partners 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 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, other4@gmail.com') + 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 @@ -440,12 +345,12 @@ class TestMailgateway(TestMailBase): 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 an alias with known recipients, alias is owned by user that can create a group + # 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') @@ -462,7 +367,7 @@ class TestMailgateway(TestMailBase): 'message_process: message on created group should have Sylvie as author_id') self.assertIn('Sylvie Lelitre ', 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 + # 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)') @@ -473,9 +378,19 @@ class TestMailgateway(TestMailBase): # Data: unlink group frog_group.unlink() - # Do: incoming email from a not follower Partner on a Followers only alias -> ok + # 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_alias.write(cr, uid, [alias_id], {'alias_contact': 'followers'}) 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) @@ -500,7 +415,7 @@ class TestMailgateway(TestMailBase): # 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='other@gmail.com', + 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 @@ -520,8 +435,7 @@ class TestMailgateway(TestMailBase): # Do: Pigs alias is restricted, should accept Followers self._init_mock_build_email() self.mail_group.message_subscribe(cr, uid, [frog_group.id], [p2id]) - self.mail_group.write(cr, uid, [frog_group.id], {'alias_name': 'frogs', 'alias_contact': 'followers'}) - frog_groups = format_and_process(MAIL_TEMPLATE, email_from='other@gmail.com', + 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 @@ -546,7 +460,7 @@ class TestMailgateway(TestMailBase): # -------------------------------------------------- # 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', + 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) @@ -565,7 +479,7 @@ class TestMailgateway(TestMailBase): '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', + 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 @@ -666,7 +580,7 @@ class TestMailgateway(TestMailBase): 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, '
\nPlease call me as soon as possible this afternoon!\n\n--\nSylvie\n
', + self.assertIn('
\nPlease call me as soon as possible this afternoon!\n\n--\nSylvie\n
', msg.body, 'message_process: plaintext incoming email incorrectly parsed') @mute_logger('openerp.addons.mail.mail_thread', 'openerp.osv.orm') -- cgit v1.2.3