[IMP] mail_followers: get_signature_footer and test
bzr revid: chm@openerp.com-20130129142949-po3hv5utdxsfb99v
This commit is contained in:
@@ -105,20 +105,26 @@ class mail_notification(osv.Model):
|
||||
notify_pids.append(partner.id)
|
||||
return notify_pids
|
||||
|
||||
def get_signature_footer(self, cr, uid, user_id, res_model=None, res_id=None, context=None):
|
||||
def get_signature_footer(self, cr, uid, user_id=None, res_model=None, res_id=None, context=None):
|
||||
footer = ""
|
||||
user = self.pool.get("res.users").browse(cr, uid, [user_id], context=context)[0]
|
||||
if user and user.signature:
|
||||
signature = plaintext2html(user.signature)
|
||||
else:
|
||||
signature = "--<br>%s" % user.name
|
||||
footer = tools.append_content_to_html(footer, signature, plaintext=False, container_tag='p')
|
||||
|
||||
company = None
|
||||
if user.company_id:
|
||||
company = user.company_id.website and "<a style='color:inherit' href='%s'>%s</a>" % (user.company_id.website, user.company_id.name) or user.company_id.name
|
||||
else:
|
||||
company = user.name
|
||||
user = None
|
||||
|
||||
if user_id:
|
||||
users = self.pool.get("res.users").browse(cr, uid, [user_id], context=context)
|
||||
user = users and users[0] or None
|
||||
|
||||
if user:
|
||||
if user.signature:
|
||||
signature = plaintext2html(user.signature)
|
||||
else:
|
||||
signature = "--<br>%s" % user.name
|
||||
footer = tools.append_content_to_html(footer, signature, plaintext=False, container_tag='p')
|
||||
|
||||
if user.company_id:
|
||||
company = user.company_id.website and "<a style='color:inherit' href='%s'>%s</a>" % (user.company_id.website, user.company_id.name) or user.company_id.name
|
||||
else:
|
||||
company = user.name
|
||||
|
||||
model_name = None
|
||||
record_name = None
|
||||
@@ -129,27 +135,27 @@ class mail_notification(osv.Model):
|
||||
if res_id:
|
||||
record_obj = self.pool.get(res_model)
|
||||
record = record_obj.browse(cr, uid, [res_id], context=context)[0]
|
||||
record_name = record.name
|
||||
record_name = record.name_get() and record.name_get()[0] and record.name_get()[0][1] or record.name
|
||||
|
||||
if company:
|
||||
if model_name:
|
||||
if record_name:
|
||||
signature_company = _("This message is written on the document '<b>%(record_name)s</b>' of '<b>%(model_name)s</b>' from '%(company)s'." % {
|
||||
'record_name': record_name,
|
||||
'model_name': model_name,
|
||||
'company': company
|
||||
})
|
||||
else:
|
||||
signature_company = _("This message is written on '<b>%(model_name)s</b>' from '%(company)s'." % {
|
||||
'model_name': model_name,
|
||||
'company': company
|
||||
})
|
||||
else:
|
||||
signature_company = _("This message is written from '%(company)s'." % {
|
||||
if record_name:
|
||||
signature_company = _("This message is written on the document '<b>%(record_name)s</b>' of '<b>%(model_name)s</b>' from %(company)s." % {
|
||||
'record_name': record_name,
|
||||
'model_name': model_name,
|
||||
'company': company
|
||||
})
|
||||
|
||||
footer = tools.append_content_to_html(footer, "<small>%s</small>" % signature_company, plaintext=False, container_tag='div')
|
||||
else:
|
||||
signature_company = _("This message is written from %(company)s." % {
|
||||
'company': company
|
||||
})
|
||||
footer = tools.append_content_to_html(footer, "<small>%s</small>" % signature_company, plaintext=False, container_tag='div')
|
||||
else:
|
||||
if record_name:
|
||||
signature_company = _("This message is written on the document '<b>%(record_name)s</b>' of '<b>%(model_name)s</b>'." % {
|
||||
'record_name': record_name,
|
||||
'model_name': model_name
|
||||
})
|
||||
footer = tools.append_content_to_html(footer, "<small>%s</small>" % signature_company, plaintext=False, container_tag='div')
|
||||
|
||||
return footer
|
||||
|
||||
@@ -172,8 +178,8 @@ class mail_notification(osv.Model):
|
||||
|
||||
# add signature
|
||||
body_html = msg.body
|
||||
user = msg.author_id and msg.author_id.user_ids and msg.author_id.user_ids[0] or None
|
||||
signature_company = self.get_signature_footer(cr, uid, user_id=user.id, res_model=msg.model, res_id=msg.res_id, context=context)
|
||||
user_id = msg.author_id and msg.author_id.user_ids and msg.author_id.user_ids[0] and msg.author_id.user_ids[0].id or None
|
||||
signature_company = self.get_signature_footer(cr, uid, user_id=user_id, res_model=msg.model, res_id=msg.res_id, context=context)
|
||||
body_html = tools.append_content_to_html(body_html, signature_company, plaintext=False, container_tag='div')
|
||||
|
||||
mail_values = {
|
||||
|
||||
@@ -84,23 +84,6 @@ Sylvie
|
||||
|
||||
class test_mail(TestMailBase):
|
||||
|
||||
def _mock_send_get_mail_body(self, *args, **kwargs):
|
||||
# def _send_get_mail_body(self, cr, uid, mail, partner=None, context=None)
|
||||
body = append_content_to_html(args[2].body_html, kwargs.get('partner').name if kwargs.get('partner') else 'No specific partner', plaintext=False)
|
||||
return body
|
||||
|
||||
def setUp(self):
|
||||
super(test_mail, self).setUp()
|
||||
|
||||
# Mock send_get_mail_body to test its functionality without other addons override
|
||||
self._send_get_mail_body = self.registry('mail.mail').send_get_mail_body
|
||||
self.registry('mail.mail').send_get_mail_body = self._mock_send_get_mail_body
|
||||
|
||||
def tearDown(self):
|
||||
# Remove mocks
|
||||
self.registry('mail.mail').send_get_mail_body = self._send_get_mail_body
|
||||
super(test_mail, self).tearDown()
|
||||
|
||||
def test_00_message_process(self):
|
||||
""" Testing incoming emails processing. """
|
||||
cr, uid, user_raoul = self.cr, self.uid, self.user_raoul
|
||||
@@ -341,11 +324,15 @@ class test_mail(TestMailBase):
|
||||
_subject = 'Pigs'
|
||||
_mail_subject = '%s posted on %s' % (user_raoul.name, group_pigs.name)
|
||||
_body1 = '<p>Pigs rules</p>'
|
||||
_mail_body1 = '<p>Pigs rules</p>\n<div><p>Raoul</p></div>\n'
|
||||
_mail_bodyalt1 = 'Pigs rules\nRaoul\n'
|
||||
_mail_body1 = '<p>Pigs rules</p>'
|
||||
_mail_signature1 = '<p>Raoul</p>'
|
||||
_mail_bodyalt1 = 'Pigs rules\n'
|
||||
_mail_signaturealt1 = '\nRaoul\n'
|
||||
_body2 = '<html>Pigs rules</html>'
|
||||
_mail_body2 = '<div><p>Pigs rules</p></div>\n<div><p>Raoul</p></div>'
|
||||
_mail_bodyalt2 = 'Pigs rules\nRaoul'
|
||||
_mail_body2 = '<div><p>Pigs rules</p></div>'
|
||||
_mail_signature2 = '<p>Raoul</p>'
|
||||
_mail_bodyalt2 = 'Pigs rules\n'
|
||||
_mail_signaturealt2 = '\nRaoul\n'
|
||||
_attachments = [('First', 'My first attachment'), ('Second', 'My second attachment')]
|
||||
|
||||
# ----------------------------------------
|
||||
@@ -356,6 +343,9 @@ class test_mail(TestMailBase):
|
||||
self._init_mock_build_email()
|
||||
msg1_id = self.mail_group.message_post(cr, user_raoul.id, self.group_pigs_id, body=_body1, subject=_subject, type='comment', subtype='mt_comment')
|
||||
message1 = self.mail_message.browse(cr, uid, msg1_id)
|
||||
|
||||
print "####", msg1_id, "####", message1.body, "####"
|
||||
|
||||
sent_emails = self._build_email_kwargs_list
|
||||
# Test: mail.mail notifications have been deleted
|
||||
self.assertFalse(self.mail_mail.search(cr, uid, [('mail_message_id', '=', msg1_id)]), 'mail.mail notifications should have been auto-deleted!')
|
||||
@@ -366,12 +356,14 @@ class test_mail(TestMailBase):
|
||||
self.assertEqual(len(sent_emails), 2, 'sent_email number of sent emails incorrect')
|
||||
for sent_email in sent_emails:
|
||||
self.assertEqual(sent_email['subject'], _subject, 'sent_email subject incorrect')
|
||||
self.assertTrue(sent_email['body'] in [_mail_body1 + '\nBert Tartopoils\n', _mail_body1 + '\nAdministrator\n'],
|
||||
'sent_email body incorrect')
|
||||
self.assertIn(_mail_body1, sent_email['body'], 'sent_email body incorrect')
|
||||
self.assertIn(_mail_signature1, sent_email['body'], 'sent_email body incorrect (no signature)')
|
||||
self.assertIn("This message is written on the document", sent_email['body'], 'sent_email body incorrect (no document signature)')
|
||||
# the html2plaintext uses etree or beautiful soup, so the result may be slighly different
|
||||
# depending if you have installed beautiful soup.
|
||||
self.assertTrue(sent_email['body_alternative'] in [_mail_bodyalt1 + '\nBert Tartopoils\n', _mail_bodyalt1 + '\nAdministrator\n'],
|
||||
'sent_email body_alternative is incorrect')
|
||||
self.assertIn(_mail_bodyalt1, sent_email['body_alternative'], 'sent_email body_alternative is incorrect')
|
||||
self.assertIn(_mail_signaturealt1, sent_email['body_alternative'], 'sent_email body_alternative is incorrect (no signature)')
|
||||
self.assertIn("This message is written on the document", sent_email['body'], 'sent_email body incorrect (no document signature)')
|
||||
# Test: mail_message: notified_partner_ids = group followers
|
||||
message_pids = set([partner.id for partner in message1.notified_partner_ids])
|
||||
test_pids = set([self.partner_admin_id, p_b_id, p_c_id])
|
||||
@@ -404,7 +396,12 @@ class test_mail(TestMailBase):
|
||||
for sent_email in sent_emails:
|
||||
self.assertEqual(sent_email['subject'], _mail_subject, 'sent_email subject incorrect')
|
||||
self.assertIn(_mail_body2, sent_email['body'], 'sent_email body incorrect')
|
||||
self.assertIn(_mail_bodyalt2, sent_email['body_alternative'], 'sent_email body_alternative incorrect')
|
||||
self.assertIn(_mail_signature2, sent_email['body'], 'sent_email body incorrect (no signature)')
|
||||
self.assertIn("This message is written on the document", sent_email['body'], 'sent_email body incorrect (no document signature)')
|
||||
# body_alternative
|
||||
self.assertIn(_mail_bodyalt2, sent_email['body_alternative'], 'sent_email body_alternative is incorrect')
|
||||
self.assertIn(_mail_signaturealt2, sent_email['body_alternative'], 'sent_email body_alternative is incorrect (no signature)')
|
||||
self.assertIn("This message is written on the document", sent_email['body'], 'sent_email body incorrect (no document signature)')
|
||||
# Test: mail_message: notified_partner_ids = group followers
|
||||
message_pids = set([partner.id for partner in message2.notified_partner_ids])
|
||||
test_pids = set([self.partner_admin_id, p_b_id, p_c_id, p_d_id])
|
||||
|
||||
Reference in New Issue
Block a user