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
2.5 KiB

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