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.

39 lines
1.5 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. from odoo.modules.module import get_module_resource
  6. class TestMailNotification(common.TransactionCase):
  7. def setUp(self):
  8. super(TestMailNotification, self).setUp()
  9. self.fetchmail_model = self.env['fetchmail.server']
  10. self.partner_model = self.env['res.partner']
  11. self.thread_model = self.env['mail.thread']
  12. def test_notify_bounce_partners(self):
  13. admin_id = self.partner_model.search(
  14. [('name', '=', 'Administrator')])[0].id
  15. server = self.fetchmail_model.create({
  16. 'name': 'disabled',
  17. 'server': 'disabled',
  18. 'user': 'disabled',
  19. 'password': 'disabled',
  20. 'bounce_notify_partner_ids': [(6, 0, [admin_id])]
  21. })
  22. path = get_module_resource(
  23. 'mail_notify_bounce',
  24. 'tests', 'data', 'bounce_message'
  25. )
  26. with open(path) as bounce_message:
  27. self.thread_model.with_context(
  28. fetchmail_server_id=server.id
  29. ).message_process(
  30. model='res.partner', message=bounce_message.read())
  31. sent_mail = self.env['mail.mail'].search(
  32. [], order="create_date desc")[0]
  33. self.assertEqual(sent_mail.recipient_ids.name, 'Administrator')
  34. self.assertEqual(
  35. sent_mail.subject, 'Delivery Status Notification (Failure)')