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.

56 lines
1.9 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. # Copyright 2018 AGENTERP GMBH
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo.exceptions import ValidationError
  4. from openerp.tests import common
  5. class TestIrMail(common.TransactionCase):
  6. def setUp(self):
  7. super(TestIrMail, self).setUp()
  8. self.mail_server = self.env['ir.mail_server'].create({
  9. 'smtp_port': '25',
  10. 'smtp_host': 'localhost',
  11. 'smtp_encryption': 'none',
  12. 'name': 'test',
  13. 'has_separate_imap_server': True,
  14. 'store_outgoing_mail': True,
  15. })
  16. def test_parse_list_response(self):
  17. imap_mailbox = \
  18. b'(\\HasNoChildren \\UnMarked) "." "INBOX.Deleted Messages"'
  19. flags, delimiter, mailbox_name = \
  20. self.env['ir.mail_server'].parse_list_response(imap_mailbox)
  21. self.assertEqual(flags, '\\HasNoChildren \\UnMarked')
  22. self.assertEqual(delimiter, '.')
  23. self.assertEqual(mailbox_name, 'INBOX.Deleted Messages')
  24. def test_imap_connection(self):
  25. try:
  26. self.mail_server.test_imap_connection()
  27. except ValidationError as e:
  28. pass
  29. def test_send_mail(self):
  30. msg = self.env['ir.mail_server'].build_email(
  31. email_from='test.from@example.com',
  32. reply_to='test.reply@example.com',
  33. email_to=["test.to@example.com"],
  34. subject="Test Subject",
  35. body="test Bosy",
  36. )
  37. self.env['ir.mail_server'].send_email(
  38. msg, mail_server_id=self.mail_server.id)
  39. def test_save_sent_message_to_sentbox(self):
  40. msg = self.env['ir.mail_server'].build_email(
  41. email_from='test.from@example.com',
  42. reply_to='test.reply@example.com',
  43. email_to=["test.to@example.com"],
  44. subject="Test Subject",
  45. body="test Bosy",
  46. )
  47. msg = self.env['ir.mail_server']._save_sent_message_to_sentbox(
  48. msg, self.mail_server.id)