[CLEAN] mail: tests: cleaned test_mail_gateway file about indentation

bzr revid: tde@openerp.com-20130807142928-ocgzim1hdi95uyby
This commit is contained in:
Thibault Delavallée 2013-08-07 16:29:28 +02:00
parent 2eece10cd4
commit c998b86a46
2 changed files with 113 additions and 113 deletions

View File

@ -22,11 +22,11 @@
from . import test_mail_message, test_mail_features, test_mail_gateway, test_message_read, test_invite from . import test_mail_message, test_mail_features, test_mail_gateway, test_message_read, test_invite
checks = [ checks = [
# test_mail_message, test_mail_message,
# test_mail_features, test_mail_features,
test_mail_gateway, test_mail_gateway,
# test_message_read, test_message_read,
# test_invite, test_invite,
] ]
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -20,7 +20,7 @@
############################################################################## ##############################################################################
from openerp.addons.mail.tests.test_mail_base import TestMailBase from openerp.addons.mail.tests.test_mail_base import TestMailBase
from openerp.tools import mute_logger, email_split from openerp.tools import mute_logger
MAIL_TEMPLATE = """Return-Path: <whatever-2a840@postmaster.twitter.com> MAIL_TEMPLATE = """Return-Path: <whatever-2a840@postmaster.twitter.com>
To: {to} To: {to}
@ -101,9 +101,9 @@ class TestMailgateway(TestMailBase):
# Do: find partner with email -> first partner should be found # Do: find partner with email -> first partner should be found
partner_info = self.mail_thread.message_partner_info_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>', self.assertEqual(partner_info['full_name'], 'Maybe Raoul <test@test.fr>',
'mail_thread: message_partner_info_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, self.assertEqual(partner_info['partner_id'], p_a_id,
'mail_thread: message_partner_info_from_emails wrong partner found') 'mail_thread: message_partner_info_from_emails wrong partner found')
# Data: add some data about partners # Data: add some data about partners
# 2 - User BRaoul # 2 - User BRaoul
@ -112,7 +112,7 @@ class TestMailgateway(TestMailBase):
# Do: find partner with email -> first user should be found # Do: find partner with email -> first user should be found
partner_info = self.mail_thread.message_partner_info_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, self.assertEqual(partner_info['partner_id'], p_b_id,
'mail_thread: message_partner_info_from_emails wrong partner found') 'mail_thread: message_partner_info_from_emails wrong partner found')
# -------------------------------------------------- # --------------------------------------------------
# CASE1: with object # CASE1: with object
@ -122,7 +122,7 @@ class TestMailgateway(TestMailBase):
self.mail_group.message_subscribe(cr, uid, [group_pigs.id], [p_b_id]) self.mail_group.message_subscribe(cr, uid, [group_pigs.id], [p_b_id])
partner_info = self.mail_group.message_partner_info_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, self.assertEqual(partner_info['partner_id'], p_b_id,
'mail_thread: message_partner_info_from_emails wrong partner found') 'mail_thread: message_partner_info_from_emails wrong partner found')
def test_05_mail_message_mail_mail(self): def test_05_mail_message_mail_mail(self):
""" Tests designed for testing email values based on mail.message, aliases, ... """ """ Tests designed for testing email values based on mail.message, aliases, ... """
@ -146,46 +146,46 @@ class TestMailgateway(TestMailBase):
msg = self.mail_message.browse(cr, user_raoul_id, msg_id) msg = self.mail_message.browse(cr, user_raoul_id, msg_id)
# Test: message content # Test: message content
self.assertIn('reply_to', msg.message_id, self.assertIn('reply_to', msg.message_id,
'mail_message: message_id should be specific to a mail_message with a given reply_to') 'mail_message: message_id should be specific to a mail_message with a given reply_to')
self.assertEqual(msg.reply_to, reply_to1, self.assertEqual(msg.reply_to, reply_to1,
'mail_message: incorrect reply_to: should come from values') 'mail_message: incorrect reply_to: should come from values')
self.assertEqual(msg.email_from, email_from1, self.assertEqual(msg.email_from, email_from1,
'mail_message: incorrect email_from: should come from values') 'mail_message: incorrect email_from: should come from values')
# Do: create a mail_mail with the previous mail_message # Do: create a mail_mail with the previous mail_message
mail_id = self.mail_mail.create(cr, user_raoul_id, {'mail_message_id': msg_id, 'state': 'cancel'}) 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) mail = self.mail_mail.browse(cr, user_raoul_id, mail_id)
# Test: mail_mail content # Test: mail_mail content
self.assertEqual(mail.reply_to, reply_to1, self.assertEqual(mail.reply_to, reply_to1,
'mail_mail: incorrect reply_to: should come from mail.message') 'mail_mail: incorrect reply_to: should come from mail.message')
self.assertEqual(mail.email_from, email_from1, self.assertEqual(mail.email_from, email_from1,
'mail_mail: incorrect email_from: should come from mail.message') 'mail_mail: incorrect email_from: should come from mail.message')
# Do: create a mail_mail with the previous mail_message + specified reply_to # 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_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) mail = self.mail_mail.browse(cr, user_raoul_id, mail_id)
# Test: mail_mail content # Test: mail_mail content
self.assertEqual(mail.reply_to, reply_to2, self.assertEqual(mail.reply_to, reply_to2,
'mail_mail: incorrect reply_to: should come from values') 'mail_mail: incorrect reply_to: should come from values')
self.assertEqual(mail.email_from, email_from1, self.assertEqual(mail.email_from, email_from1,
'mail_mail: incorrect email_from: should come from mail.message') 'mail_mail: incorrect email_from: should come from mail.message')
# Do: mail_message attached to a document # 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_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) msg = self.mail_message.browse(cr, user_raoul_id, msg_id)
# Test: message content # Test: message content
self.assertIn('mail.group', msg.message_id, 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, 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, self.assertFalse(msg.reply_to,
'mail_message: incorrect reply_to: should not be generated if not specified') 'mail_message: incorrect reply_to: should not be generated if not specified')
self.assertEqual(msg.email_from, raoul_from, self.assertEqual(msg.email_from, raoul_from,
'mail_message: incorrect email_from: should be Raoul') 'mail_message: incorrect email_from: should be Raoul')
# Do: create a mail_mail based on the previous mail_message # 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_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) mail = self.mail_mail.browse(cr, user_raoul_id, mail_id)
# Test: mail_mail content # Test: mail_mail content
self.assertEqual(mail.reply_to, raoul_reply, self.assertEqual(mail.reply_to, raoul_reply,
'mail_mail: incorrect reply_to: should be Raoul') 'mail_mail: incorrect reply_to: should be Raoul')
# Data: set catchall domain # Data: set catchall domain
self.registry('ir.config_parameter').set_param(cr, uid, 'mail.catchall.domain', alias_domain) self.registry('ir.config_parameter').set_param(cr, uid, 'mail.catchall.domain', alias_domain)
@ -199,7 +199,7 @@ class TestMailgateway(TestMailBase):
mail = self.mail_mail.browse(cr, user_raoul_id, mail_id) mail = self.mail_mail.browse(cr, user_raoul_id, mail_id)
# Test: mail_mail content # Test: mail_mail content
self.assertEqual(mail.reply_to, raoul_reply_alias, self.assertEqual(mail.reply_to, raoul_reply_alias,
'mail_mail: incorrect reply_to: should be Pigs alias') 'mail_mail: incorrect reply_to: should be Pigs alias')
# Update message: test alias on email_from # Update message: test alias on email_from
msg_id = self.mail_message.create(cr, user_raoul_id, {}) msg_id = self.mail_message.create(cr, user_raoul_id, {})
@ -209,7 +209,7 @@ class TestMailgateway(TestMailBase):
mail = self.mail_mail.browse(cr, user_raoul_id, mail_id) mail = self.mail_mail.browse(cr, user_raoul_id, mail_id)
# Test: mail_mail content # Test: mail_mail content
self.assertEqual(mail.reply_to, raoul_from_alias, self.assertEqual(mail.reply_to, raoul_from_alias,
'mail_mail: incorrect reply_to: should be message email_from using Raoul alias') 'mail_mail: incorrect reply_to: should be message email_from using Raoul alias')
# Update message # Update message
self.mail_message.write(cr, user_raoul_id, [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})
@ -219,7 +219,7 @@ class TestMailgateway(TestMailBase):
mail = self.mail_mail.browse(cr, user_raoul_id, mail_id) mail = self.mail_mail.browse(cr, user_raoul_id, mail_id)
# Test: mail_mail content # Test: mail_mail content
self.assertEqual(mail.reply_to, msg.email_from, self.assertEqual(mail.reply_to, msg.email_from,
'mail_mail: incorrect reply_to: should be message email_from') 'mail_mail: incorrect reply_to: should be message email_from')
# Data: set catchall alias # Data: set catchall alias
self.registry('ir.config_parameter').set_param(self.cr, self.uid, 'mail.catchall.alias', 'gateway') self.registry('ir.config_parameter').set_param(self.cr, self.uid, 'mail.catchall.alias', 'gateway')
@ -232,21 +232,21 @@ class TestMailgateway(TestMailBase):
mail = self.mail_mail.browse(cr, uid, mail_id) mail = self.mail_mail.browse(cr, uid, mail_id)
# Test: mail_mail Content-Type # Test: mail_mail Content-Type
self.assertEqual(mail.reply_to, 'gateway@schlouby.fr', 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 # Do: create a mail_mail
mail_id = self.mail_mail.create(cr, uid, {'state': 'cancel'}) mail_id = self.mail_mail.create(cr, uid, {'state': 'cancel'})
mail = self.mail_mail.browse(cr, uid, mail_id) mail = self.mail_mail.browse(cr, uid, mail_id)
# Test: mail_mail content # Test: mail_mail content
self.assertEqual(mail.reply_to, 'gateway@schlouby.fr', 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 # Do: create a mail_mail
mail_id = self.mail_mail.create(cr, uid, {'state': 'cancel', 'reply_to': 'someone@example.com'}) mail_id = self.mail_mail.create(cr, uid, {'state': 'cancel', 'reply_to': 'someone@example.com'})
mail = self.mail_mail.browse(cr, uid, mail_id) mail = self.mail_mail.browse(cr, uid, mail_id)
# Test: mail_mail content # Test: mail_mail content
self.assertEqual(mail.reply_to, 'someone@example.com', 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') @mute_logger('openerp.addons.mail.mail_thread', 'openerp.osv.orm')
def test_10_message_process(self): def test_10_message_process(self):
@ -254,9 +254,9 @@ class TestMailgateway(TestMailBase):
cr, uid, user_raoul = self.cr, self.uid, self.user_raoul 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', def format_and_process(template, to='groups@example.com, other@gmail.com', subject='Frogs',
extra='', email_from='Sylvie Lelitre <test.sylvie.lelitre@agrolait.com>', extra='', email_from='Sylvie Lelitre <test.sylvie.lelitre@agrolait.com>',
msg_id='<1198923581.41972151344608186760.JavaMail@agrolait.com>', msg_id='<1198923581.41972151344608186760.JavaMail@agrolait.com>',
model=None): model=None):
self.assertEqual(self.mail_group.search(cr, uid, [('name', '=', subject)]), []) 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) 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) self.mail_thread.message_process(cr, uid, model, mail)
@ -289,29 +289,29 @@ class TestMailgateway(TestMailBase):
frog_group = self.mail_group.browse(cr, uid, frog_groups[0]) frog_group = self.mail_group.browse(cr, uid, frog_groups[0])
res = self.mail_group.perm_read(cr, uid, [frog_group.id], details=False) res = self.mail_group.perm_read(cr, uid, [frog_group.id], details=False)
self.assertEqual(res[0].get('create_uid'), uid, 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 # Test: one message that is the incoming email
self.assertEqual(len(frog_group.message_ids), 1, 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] msg = frog_group.message_ids[0]
self.assertEqual('Frogs', msg.subject, 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, 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, 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, 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 # Test: message: unknown email address -> message has email_from, not author_id
self.assertFalse(msg.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, 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 # Test: followers: nobody
self.assertEqual(len(frog_group.message_follower_ids), 0, 'message_process: newly create group should not have any follower') self.assertEqual(len(frog_group.message_follower_ids), 0, 'message_process: newly create group should not have any follower')
# Test: sent emails: no-one # Test: sent emails: no-one
self.assertEqual(len(sent_emails), 0, 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 # Data: unlink group
frog_group.unlink() frog_group.unlink()
@ -324,11 +324,11 @@ class TestMailgateway(TestMailBase):
# Test: email bounced # Test: email bounced
sent_emails = self._build_email_kwargs_list sent_emails = self._build_email_kwargs_list
self.assertEqual(len(sent_emails), 1, self.assertEqual(len(sent_emails), 1,
'message_process: incoming email on Partners 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'), self.assertIn('Frogs', sent_emails[0].get('subject'),
'message_process: bounce email on Partners 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'), 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') '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 # Do: incoming email from an unknown partner on a Followers only alias -> bounce
self._init_mock_build_email() self._init_mock_build_email()
@ -339,11 +339,11 @@ class TestMailgateway(TestMailBase):
# Test: email bounced # Test: email bounced
sent_emails = self._build_email_kwargs_list sent_emails = self._build_email_kwargs_list
self.assertEqual(len(sent_emails), 1, self.assertEqual(len(sent_emails), 1,
'message_process: incoming email on Followers alias should send a bounce email') 'message_process: incoming email on Followers alias should send a bounce email')
self.assertIn('Frogs', sent_emails[0].get('subject'), self.assertIn('Frogs', sent_emails[0].get('subject'),
'message_process: bounce email on Followers alias should contain the original 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'), 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') '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) # 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'}) self.mail_alias.write(cr, uid, [alias_id], {'alias_user_id': self.user_raoul_id, 'alias_contact': 'partners'})
@ -357,24 +357,24 @@ class TestMailgateway(TestMailBase):
frog_group = self.mail_group.browse(cr, uid, frog_groups[0]) frog_group = self.mail_group.browse(cr, uid, frog_groups[0])
res = self.mail_group.perm_read(cr, uid, [frog_group.id], details=False) res = self.mail_group.perm_read(cr, uid, [frog_group.id], details=False)
self.assertEqual(res[0].get('create_uid'), self.user_raoul_id, 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 # Test: one message that is the incoming email
self.assertEqual(len(frog_group.message_ids), 1, 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] msg = frog_group.message_ids[0]
# Test: message: author found # Test: message: author found
self.assertEqual(p1id, msg.author_id.id, 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, self.assertIn('Sylvie Lelitre <test.sylvie.lelitre@agrolait.com>', msg.email_from,
'message_process: message on created group should have have an 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]) frog_follower_ids = set([p.id for p in frog_group.message_follower_ids])
self.assertEqual(frog_follower_ids, set([p1id]), 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 # Test: sent emails: no-one, no bounce effet
sent_emails = self._build_email_kwargs_list sent_emails = self._build_email_kwargs_list
self.assertEqual(len(sent_emails), 0, self.assertEqual(len(sent_emails), 0,
'message_process: should not bounce incoming emails') 'message_process: should not bounce incoming emails')
# Data: unlink group # Data: unlink group
frog_group.unlink() frog_group.unlink()
@ -387,7 +387,7 @@ class TestMailgateway(TestMailBase):
# Test: email bounced # Test: email bounced
sent_emails = self._build_email_kwargs_list sent_emails = self._build_email_kwargs_list
self.assertEqual(len(sent_emails), 1, self.assertEqual(len(sent_emails), 1,
'message_process: incoming email on Partners alias should send a bounce email') '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 # Do: incoming email from a parent document follower on a Followers only alias -> ok
self._init_mock_build_email() self._init_mock_build_email()
@ -398,15 +398,15 @@ class TestMailgateway(TestMailBase):
frog_group = self.mail_group.browse(cr, uid, frog_groups[0]) frog_group = self.mail_group.browse(cr, uid, frog_groups[0])
# Test: one message that is the incoming email # Test: one message that is the incoming email
self.assertEqual(len(frog_group.message_ids), 1, 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 # Test: author (and not recipient) added as follower
frog_follower_ids = set([p.id for p in frog_group.message_follower_ids]) frog_follower_ids = set([p.id for p in frog_group.message_follower_ids])
self.assertEqual(frog_follower_ids, set([p1id]), 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 # Test: sent emails: no-one, no bounce effet
sent_emails = self._build_email_kwargs_list sent_emails = self._build_email_kwargs_list
self.assertEqual(len(sent_emails), 0, self.assertEqual(len(sent_emails), 0,
'message_process: should not bounce incoming emails') 'message_process: should not bounce incoming emails')
# -------------------------------------------------- # --------------------------------------------------
# Test2: update-like alias # Test2: update-like alias
@ -416,43 +416,43 @@ class TestMailgateway(TestMailBase):
self._init_mock_build_email() 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}) 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', frog_groups = format_and_process(MAIL_TEMPLATE, email_from='other4@gmail.com',
msg_id='<1198923581.41972151344608186760.JavaMail.diff1@agrolait.com>', msg_id='<1198923581.41972151344608186760.JavaMail.diff1@agrolait.com>',
to='frogs@example.com>', subject='Re: news') to='frogs@example.com>', subject='Re: news')
# Test: no group 'Re: news' created, still only 1 Frogs group # Test: no group 'Re: news' created, still only 1 Frogs group
self.assertEqual(len(frog_groups), 0, 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')]) frog_groups = self.mail_group.search(cr, uid, [('name', '=', 'Frogs')])
self.assertEqual(len(frog_groups), 1, 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]) frog_group = self.mail_group.browse(cr, uid, frog_groups[0])
# Test: email bounced # Test: email bounced
sent_emails = self._build_email_kwargs_list sent_emails = self._build_email_kwargs_list
self.assertEqual(len(sent_emails), 1, self.assertEqual(len(sent_emails), 1,
'message_process: incoming email on Followers alias should send a bounce email') 'message_process: incoming email on Followers alias should send a bounce email')
self.assertIn('Re: news', sent_emails[0].get('subject'), self.assertIn('Re: news', sent_emails[0].get('subject'),
'message_process: bounce email on Followers alias should contain the original subject') 'message_process: bounce email on Followers alias should contain the original subject')
# Do: Pigs alias is restricted, should accept Followers # Do: Pigs alias is restricted, should accept Followers
self._init_mock_build_email() self._init_mock_build_email()
self.mail_group.message_subscribe(cr, uid, [frog_group.id], [p2id]) self.mail_group.message_subscribe(cr, uid, [frog_group.id], [p2id])
frog_groups = format_and_process(MAIL_TEMPLATE, email_from='other4@gmail.com', frog_groups = format_and_process(MAIL_TEMPLATE, email_from='other4@gmail.com',
msg_id='<1198923581.41972151344608186799.JavaMail.diff1@agrolait.com>', msg_id='<1198923581.41972151344608186799.JavaMail.diff1@agrolait.com>',
to='frogs@example.com>', subject='Re: cats') to='frogs@example.com>', subject='Re: cats')
# Test: no group 'Re: news' created, still only 1 Frogs group # Test: no group 'Re: news' created, still only 1 Frogs group
self.assertEqual(len(frog_groups), 0, 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')]) frog_groups = self.mail_group.search(cr, uid, [('name', '=', 'Frogs')])
self.assertEqual(len(frog_groups), 1, 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]) frog_group = self.mail_group.browse(cr, uid, frog_groups[0])
# Test: one new message # 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), 2, 'message_process: group should contain 2 messages after reply')
# Test: sent emails: 1 (Sylvie copy of the incoming email, but no bounce) # Test: sent emails: 1 (Sylvie copy of the incoming email, but no bounce)
sent_emails = self._build_email_kwargs_list sent_emails = self._build_email_kwargs_list
self.assertEqual(len(sent_emails), 1, self.assertEqual(len(sent_emails), 1,
'message_process: one email should have been generated') 'message_process: one email should have been generated')
self.assertIn('test.sylvie.lelitre@agrolait.com', sent_emails[0].get('email_to')[0], self.assertIn('test.sylvie.lelitre@agrolait.com', sent_emails[0].get('email_to')[0],
'message_process: email should be sent to Sylvie') 'message_process: email should be sent to Sylvie')
self.mail_group.message_unsubscribe(cr, uid, [frog_group.id], [p2id]) self.mail_group.message_unsubscribe(cr, uid, [frog_group.id], [p2id])
# -------------------------------------------------- # --------------------------------------------------
@ -461,40 +461,40 @@ class TestMailgateway(TestMailBase):
# Do: even with a wrong destination, a reply should end up in the correct thread # 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', frog_groups = format_and_process(MAIL_TEMPLATE, email_from='other4@gmail.com',
msg_id='<1198923581.41972151344608186760.JavaMail.diff1@agrolait.com>', msg_id='<1198923581.41972151344608186760.JavaMail.diff1@agrolait.com>',
to='erroneous@example.com>', subject='Re: news', to='erroneous@example.com>', subject='Re: news',
extra='In-Reply-To: <12321321-openerp-%d-mail.group@example.com>\n' % frog_group.id) 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 # Test: no group 'Re: news' created, still only 1 Frogs group
self.assertEqual(len(frog_groups), 0, 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')]) frog_groups = self.mail_group.search(cr, uid, [('name', '=', 'Frogs')])
self.assertEqual(len(frog_groups), 1, 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]) frog_group = self.mail_group.browse(cr, uid, frog_groups[0])
# Test: one new message # Test: one new message
self.assertEqual(len(frog_group.message_ids), 3, '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 # Test: author (and not recipient) added as follower
frog_follower_ids = set([p.id for p in frog_group.message_follower_ids]) frog_follower_ids = set([p.id for p in frog_group.message_follower_ids])
self.assertEqual(frog_follower_ids, set([p1id, p2id]), 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 # Do: due to some issue, same email goes back into the mailgateway
frog_groups = format_and_process(MAIL_TEMPLATE, email_from='other4@gmail.com', frog_groups = format_and_process(MAIL_TEMPLATE, email_from='other4@gmail.com',
msg_id='<1198923581.41972151344608186760.JavaMail.diff1@agrolait.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) 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 # Test: no group 'Re: news' created, still only 1 Frogs group
self.assertEqual(len(frog_groups), 0, 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')]) frog_groups = self.mail_group.search(cr, uid, [('name', '=', 'Frogs')])
self.assertEqual(len(frog_groups), 1, 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]) frog_group = self.mail_group.browse(cr, uid, frog_groups[0])
# Test: no new message # Test: no new message
self.assertEqual(len(frog_group.message_ids), 3, '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 # Test: message_id is still unique
msg_ids = self.mail_message.search(cr, uid, [('message_id', 'ilike', '<1198923581.41972151344608186760.JavaMail.diff1@agrolait.com>')]) msg_ids = self.mail_message.search(cr, uid, [('message_id', 'ilike', '<1198923581.41972151344608186760.JavaMail.diff1@agrolait.com>')])
self.assertEqual(len(msg_ids), 1, 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')
# -------------------------------------------------- # --------------------------------------------------
# Test4: email_from and partner finding # Test4: email_from and partner finding
@ -505,28 +505,28 @@ class TestMailgateway(TestMailBase):
# Do: post a new message, with a known partner -> duplicate emails -> partner # 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>', format_and_process(MAIL_TEMPLATE, email_from='Lombrik Lubrik <test_raoul@email.com>',
to='erroneous@example.com>', subject='Re: news (2)', to='erroneous@example.com>', subject='Re: news (2)',
msg_id='<1198923581.41972151344608186760.JavaMail.new1@agrolait.com>', msg_id='<1198923581.41972151344608186760.JavaMail.new1@agrolait.com>',
extra='In-Reply-To: <12321321-openerp-%d-mail.group@example.com>\n' % frog_group.id) 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_groups = self.mail_group.search(cr, uid, [('name', '=', 'Frogs')])
frog_group = self.mail_group.browse(cr, uid, frog_groups[0]) frog_group = self.mail_group.browse(cr, uid, frog_groups[0])
# Test: author is A-Raoul (only existing) # Test: author is A-Raoul (only existing)
self.assertEqual(frog_group.message_ids[0].author_id.id, extra_partner_id, 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 # Do: post a new message, with a known partner -> duplicate emails -> user
frog_group.message_unsubscribe([extra_partner_id]) frog_group.message_unsubscribe([extra_partner_id])
raoul_email = self.user_raoul.email raoul_email = self.user_raoul.email
self.res_users.write(cr, uid, self.user_raoul_id, {'email': 'test_raoul@email.com'}) 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>', format_and_process(MAIL_TEMPLATE, email_from='Lombrik Lubrik <test_raoul@email.com>',
to='erroneous@example.com>', subject='Re: news (3)', to='erroneous@example.com>', subject='Re: news (3)',
msg_id='<1198923581.41972151344608186760.JavaMail.new2@agrolait.com>', msg_id='<1198923581.41972151344608186760.JavaMail.new2@agrolait.com>',
extra='In-Reply-To: <12321321-openerp-%d-mail.group@example.com>\n' % frog_group.id) 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_groups = self.mail_group.search(cr, uid, [('name', '=', 'Frogs')])
frog_group = self.mail_group.browse(cr, uid, frog_groups[0]) frog_group = self.mail_group.browse(cr, uid, frog_groups[0])
# Test: author is Raoul (user), not A-Raoul # Test: author is Raoul (user), not A-Raoul
self.assertEqual(frog_group.message_ids[0].author_id.id, self.partner_raoul_id, 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 # Do: post a new message, with a known partner -> duplicate emails -> partner because is follower
frog_group.message_unsubscribe([self.partner_raoul_id]) frog_group.message_unsubscribe([self.partner_raoul_id])
@ -534,14 +534,14 @@ class TestMailgateway(TestMailBase):
raoul_email = self.user_raoul.email raoul_email = self.user_raoul.email
self.res_users.write(cr, uid, self.user_raoul_id, {'email': 'test_raoul@email.com'}) 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>', format_and_process(MAIL_TEMPLATE, email_from='Lombrik Lubrik <test_raoul@email.com>',
to='erroneous@example.com>', subject='Re: news (3)', to='erroneous@example.com>', subject='Re: news (3)',
msg_id='<1198923581.41972151344608186760.JavaMail.new3@agrolait.com>', msg_id='<1198923581.41972151344608186760.JavaMail.new3@agrolait.com>',
extra='In-Reply-To: <12321321-openerp-%d-mail.group@example.com>\n' % frog_group.id) 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_groups = self.mail_group.search(cr, uid, [('name', '=', 'Frogs')])
frog_group = self.mail_group.browse(cr, uid, frog_groups[0]) frog_group = self.mail_group.browse(cr, uid, frog_groups[0])
# Test: author is Raoul (user), not A-Raoul # Test: author is Raoul (user), not A-Raoul
self.assertEqual(frog_group.message_ids[0].author_id.id, extra_partner_id, 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}) self.res_users.write(cr, uid, self.user_raoul_id, {'email': raoul_email})
@ -551,37 +551,37 @@ class TestMailgateway(TestMailBase):
# Do: incoming email with model that does not accepts incoming emails must raise # Do: incoming email with model that does not accepts incoming emails must raise
self.assertRaises(AssertionError, self.assertRaises(AssertionError,
format_and_process, format_and_process,
MAIL_TEMPLATE, MAIL_TEMPLATE,
to='noone@example.com', subject='spam', extra='', model='res.country', to='noone@example.com', subject='spam', extra='', model='res.country',
msg_id='<1198923581.41972151344608186760.JavaMail.new4@agrolait.com>') msg_id='<1198923581.41972151344608186760.JavaMail.new4@agrolait.com>')
# Do: incoming email without model and without alias must raise # Do: incoming email without model and without alias must raise
self.assertRaises(AssertionError, self.assertRaises(AssertionError,
format_and_process, format_and_process,
MAIL_TEMPLATE, MAIL_TEMPLATE,
to='noone@example.com', subject='spam', extra='', to='noone@example.com', subject='spam', extra='',
msg_id='<1198923581.41972151344608186760.JavaMail.new5@agrolait.com>') msg_id='<1198923581.41972151344608186760.JavaMail.new5@agrolait.com>')
# Do: incoming email with model that accepting incoming emails as fallback # Do: incoming email with model that accepting incoming emails as fallback
frog_groups = format_and_process(MAIL_TEMPLATE, frog_groups = format_and_process(MAIL_TEMPLATE,
to='noone@example.com', to='noone@example.com',
subject='Spammy', extra='', model='mail.group', subject='Spammy', extra='', model='mail.group',
msg_id='<1198923581.41972151344608186760.JavaMail.new6@agrolait.com>') msg_id='<1198923581.41972151344608186760.JavaMail.new6@agrolait.com>')
self.assertEqual(len(frog_groups), 1, 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 # Do: incoming email in plaintext should be stored as html
frog_groups = format_and_process(MAIL_TEMPLATE_PLAINTEXT, frog_groups = format_and_process(MAIL_TEMPLATE_PLAINTEXT,
to='groups@example.com', subject='Frogs Return', extra='', to='groups@example.com', subject='Frogs Return', extra='',
msg_id='<deadcafe.1337@smtp.agrolait.com>') msg_id='<deadcafe.1337@smtp.agrolait.com>')
# Test: one group created with one message # Test: one group created with one message
self.assertEqual(len(frog_groups), 1, 'message_process: a new mail.group should have been created') 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]) frog_group = self.mail_group.browse(cr, uid, frog_groups[0])
msg = frog_group.message_ids[0] msg = frog_group.message_ids[0]
# Test: plain text content should be wrapped and stored as html # Test: plain text content should be wrapped and stored as html
self.assertIn('<pre>\nPlease call me as soon as possible this afternoon!\n\n--\nSylvie\n</pre>', msg.body, 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') 'message_process: plaintext incoming email incorrectly parsed')
@mute_logger('openerp.addons.mail.mail_thread', 'openerp.osv.orm') @mute_logger('openerp.addons.mail.mail_thread', 'openerp.osv.orm')
def test_20_thread_parent_resolution(self): def test_20_thread_parent_resolution(self):
@ -602,26 +602,26 @@ class TestMailgateway(TestMailBase):
# Reply to msg1, make sure the reply is properly attached using the various reply identification mechanisms # Reply to msg1, make sure the reply is properly attached using the various reply identification mechanisms
# 0. Direct alias match # 0. Direct alias match
reply_msg1 = format(MAIL_TEMPLATE, to='Pretty Pigs <group+pigs@example.com>', reply_msg1 = format(MAIL_TEMPLATE, to='Pretty Pigs <group+pigs@example.com>',
extra='In-Reply-To: %s' % msg1.message_id, extra='In-Reply-To: %s' % msg1.message_id,
msg_id='<1198923581.41972151344608186760.JavaMail.2@agrolait.com>') msg_id='<1198923581.41972151344608186760.JavaMail.2@agrolait.com>')
self.mail_group.message_process(cr, uid, None, reply_msg1) self.mail_group.message_process(cr, uid, None, reply_msg1)
# 1. In-Reply-To header # 1. In-Reply-To header
reply_msg2 = format(MAIL_TEMPLATE, to='erroneous@example.com', reply_msg2 = format(MAIL_TEMPLATE, to='erroneous@example.com',
extra='In-Reply-To: %s' % msg1.message_id, extra='In-Reply-To: %s' % msg1.message_id,
msg_id='<1198923581.41972151344608186760.JavaMail.3@agrolait.com>') msg_id='<1198923581.41972151344608186760.JavaMail.3@agrolait.com>')
self.mail_group.message_process(cr, uid, None, reply_msg2) self.mail_group.message_process(cr, uid, None, reply_msg2)
# 2. References header # 2. References header
reply_msg3 = format(MAIL_TEMPLATE, to='erroneous@example.com', 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, extra='References: <2233@a.com>\r\n\t<3edss_dsa@b.com> %s' % msg1.message_id,
msg_id='<1198923581.41972151344608186760.JavaMail.4@agrolait.com>') msg_id='<1198923581.41972151344608186760.JavaMail.4@agrolait.com>')
self.mail_group.message_process(cr, uid, None, reply_msg3) 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) # 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', reply_msg4 = format(MAIL_TEMPLATE, to='erroneous@example.com',
extra='', subject='Re: [%s] 1' % self.group_pigs_id, extra='', subject='Re: [%s] 1' % self.group_pigs_id,
msg_id='<1198923581.41972151344608186760.JavaMail.5@agrolait.com>') msg_id='<1198923581.41972151344608186760.JavaMail.5@agrolait.com>')
self.mail_group.message_process(cr, uid, 'mail.group', reply_msg4) self.mail_group.message_process(cr, uid, 'mail.group', reply_msg4)
group_pigs.refresh() group_pigs.refresh()