You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.2 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2015 Antiun Ingenieria S.L. - Antonio Espinosa
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp.tests.common import TransactionCase
  5. from openerp import fields
  6. from email.utils import formataddr
  7. # One test case per method
  8. class TestResPartner(TransactionCase):
  9. def test_mail_mail_create(self):
  10. partner_a = self.env.ref('base.res_partner_address_16')
  11. partner_b = self.env.ref('base.res_partner_3')
  12. partner_c = self.env.ref('base.res_partner_2')
  13. mass_mailing = self.env['mail.mass_mailing'].create({
  14. 'email_from': 'email_from@example.com',
  15. 'name': 'Subject test',
  16. 'mailing_domain': "[['id', 'in', [%d, %d, %d]]]" % (
  17. partner_a.id,
  18. partner_b.id,
  19. partner_c.id
  20. ),
  21. 'mailing_model': 'res.partner',
  22. 'body_html': '<p>Hello world!</p>',
  23. 'reply_to_mode': 'email',
  24. })
  25. mail = self.env['mail.mail'].create({
  26. 'author_id': self.env.ref('base.res_partner_4').id,
  27. 'notification': False,
  28. 'mailing_id': mass_mailing.id,
  29. 'date': fields.Datetime.now(),
  30. 'subject': 'Subject test',
  31. 'email_from': 'email_from@example.com',
  32. 'email_to': partner_a.email,
  33. 'recipient_ids': [
  34. (4, partner_b.id),
  35. (4, partner_c.id),
  36. ],
  37. 'statistics_ids': [(0, 0, {
  38. 'mass_mailing_id': mass_mailing.id,
  39. 'model': 'res.partner',
  40. 'res_id': partner_a.id,
  41. })],
  42. 'model': 'res.partner',
  43. 'res_id': partner_a.id,
  44. })
  45. orig_list = [
  46. partner_a.email,
  47. formataddr((partner_b.name, partner_b.email)),
  48. formataddr((partner_c.name, partner_c.email)),
  49. ]
  50. self.assertEqual(len(mail.statistics_ids), 1)
  51. self.assertEqual(mail.statistics_ids[0].subject, 'Subject test')
  52. self.assertEqual(mail.statistics_ids[0].email_from,
  53. 'email_from@example.com')
  54. for address in mail.statistics_ids[0].email_to.split(';'):
  55. self.assertIn(address, orig_list)