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.

61 lines
1.9 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2018 Lorenzo Battistini - Agile Business Group
  3. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
  4. import odoo.tests.common as common
  5. class TestMailNotification(common.TransactionCase):
  6. def setUp(self):
  7. super(TestMailNotification, self).setUp()
  8. self.partner_obj = self.env['res.partner']
  9. self.env.user.company_id.force_mail_queue = True
  10. def test_get_signature_footer(self):
  11. vals = {
  12. 'name': 'p1@example.com',
  13. 'email': 'p1@example.com',
  14. }
  15. partner1 = self.partner_obj.create(vals)
  16. body = 'this is the body'
  17. subject = 'this is the subject'
  18. res = partner1.message_post(
  19. subject=subject,
  20. body=body,
  21. content_subtype="plaintext",
  22. partner_ids=[partner1.id],
  23. )
  24. mail = self.env['mail.mail'].search([
  25. ('mail_message_id', '=', res.id)
  26. ])
  27. # default behaviour: outgoing mail queued
  28. self.assertTrue(mail)
  29. self.assertEqual(mail.state, 'outgoing')
  30. res = partner1.with_context(mail_notify_force_send=True).message_post(
  31. subject=subject,
  32. body=body,
  33. content_subtype="plaintext",
  34. partner_ids=[partner1.id],
  35. )
  36. mail = self.env['mail.mail'].search([
  37. ('mail_message_id', '=', res.id)
  38. ])
  39. # force send immediately: outgoing email is sent and deleted
  40. self.assertFalse(mail)
  41. res = partner1.with_context(mail_notify_force_send=False).message_post(
  42. subject=subject,
  43. body=body,
  44. content_subtype="plaintext",
  45. partner_ids=[partner1.id],
  46. )
  47. mail = self.env['mail.mail'].search([
  48. ('mail_message_id', '=', res.id)
  49. ])
  50. # do not send immediately
  51. self.assertTrue(mail)
  52. self.assertEqual(mail.state, 'outgoing')