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.

59 lines
2.5 KiB

  1. # Copyright 2017 Tecnativa - Jairo Llopis <jairo.llopis@tecnativa.com>
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo.addons.mail.tests.test_mail_gateway import MAIL_TEMPLATE
  4. from odoo.tests.common import SavepointCase
  5. from odoo.tools import mute_logger
  6. class FetchmailCase(SavepointCase):
  7. @classmethod
  8. def setUpClass(cls):
  9. super(FetchmailCase, cls).setUpClass()
  10. cls.server = cls.env.ref("fetchmail_thread_default.demo_server")
  11. cls.sink = cls.env.ref("fetchmail_thread_default.demo_sink")
  12. cls.MailThread = cls.env["mail.thread"]
  13. def test_available_models(self):
  14. """Non-``mail.thread`` models don't appear."""
  15. for record in self.server._get_thread_models():
  16. self.assertNotEqual(record[0], "mail.message")
  17. def test_emptying_default_thread(self):
  18. """Choosing an ``object_id`` empties ``default_thread_id``."""
  19. self.server.write({'object_id': 1})
  20. self.server.onchange_server_type()
  21. self.assertFalse(self.server.default_thread_id)
  22. def test_emptying_object(self):
  23. """Choosing a ``default_thread_id`` empties ``object_id``."""
  24. self.server.object_id = self.env["ir.model"].search([], limit=1)
  25. self.server._onchange_remove_object_id()
  26. self.assertFalse(self.server.object_id)
  27. @mute_logger('odoo.addons.mail.models.mail_thread', 'odoo.models')
  28. def test_unbound_incoming_email(self):
  29. """An unbound incoming email gets posted to the sink."""
  30. # Imitate what self.server.feth_mail() would do
  31. result = (
  32. self.MailThread.with_context(fetchmail_server_id=self.server.id)
  33. .message_process(
  34. self.server.object_id.model,
  35. MAIL_TEMPLATE.format(
  36. email_from="spambot@example.com",
  37. to="you@example.com",
  38. cc="nobody@example.com",
  39. subject="I'm a robot, hello",
  40. extra="",
  41. msg_id="<fitter.happier.more.productive@example.com>",
  42. ),
  43. save_original=self.server.original,
  44. strip_attachments=not self.server.attach,
  45. )
  46. )
  47. self.assertEqual(self.server.default_thread_id, self.sink)
  48. self.assertEqual(result, self.sink.id)
  49. # Nobody subscribed
  50. self.assertFalse(self.sink.message_partner_ids)
  51. # Message entered channel
  52. self.assertEqual(self.sink.message_ids.subject, "I'm a robot, hello")