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.

45 lines
1.9 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp.tests import common
  5. class TestAttachExistingAttachment(common.TransactionCase):
  6. def setUp(self):
  7. super(TestAttachExistingAttachment, self).setUp()
  8. self.partner_obj = self.env['res.partner']
  9. self.partner_01 = self.env.ref('base.res_partner_11')
  10. self.partner_02 = self.env.ref('base.res_partner_address_20')
  11. def test_send_email_attachment(self):
  12. ctx = self.env.context.copy()
  13. ctx.update({
  14. 'default_model': 'res.partner',
  15. 'default_res_id': self.partner_01.id,
  16. 'default_composition_mode': 'comment',
  17. })
  18. mail_compose = self.env['mail.compose.message']
  19. values = mail_compose.with_context(ctx)\
  20. .onchange_template_id(False, 'comment', 'res.partner',
  21. self.partner_01.id)['value']
  22. values['partner_ids'] = [(4, self.partner_02.id)]
  23. compose_id = mail_compose.with_context(ctx).create(values)
  24. compose_id.autofollow_recipients = False
  25. compose_id.with_context(ctx).send_mail()
  26. res = self.env["mail.followers"].search(
  27. [('res_model', '=', 'res.partner'),
  28. ('res_id', '=', self.partner_01.id),
  29. ('partner_id', '=', self.partner_02.id)])
  30. # I check if the recipient isn't a follower
  31. self.assertEqual(len(res.ids), 0)
  32. compose_id = mail_compose.with_context(ctx).create(values)
  33. compose_id.autofollow_recipients = True
  34. compose_id.with_context(ctx).send_mail()
  35. res = self.env["mail.followers"].search(
  36. [('res_model', '=', 'res.partner'),
  37. ('res_id', '=', self.partner_01.id),
  38. ('partner_id', '=', self.partner_02.id)])
  39. # I check if the recipient is a follower
  40. self.assertEqual(len(res.ids), 1)