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.

66 lines
2.6 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp.tests.common import TransactionCase
  5. # One test case per method
  6. class TestMailTracking(TransactionCase):
  7. # Use case : Prepare some data for current test case
  8. def setUp(self):
  9. super(TestMailTracking, self).setUp()
  10. self.sender = self.env['res.partner'].create({
  11. 'name': 'Test sender',
  12. 'email': 'sender@example.com',
  13. 'notify_email': 'always',
  14. })
  15. self.recipient = self.env['res.partner'].create({
  16. 'name': 'Test recipient',
  17. 'email': 'recipient@example.com',
  18. 'notify_email': 'always',
  19. })
  20. def test_message_post(self):
  21. # This message will generate a notification for recipient
  22. message = self.env['mail.message'].create({
  23. 'subject': 'Message test',
  24. 'author_id': self.sender.id,
  25. 'email_from': self.sender.email,
  26. 'type': 'comment',
  27. 'model': 'res.partner',
  28. 'res_id': self.recipient.id,
  29. 'partner_ids': [(4, self.recipient.id)],
  30. 'body': '<p>This is a test message</p>',
  31. })
  32. # Search tracking created
  33. tracking_email = self.env['mail.tracking.email'].search([
  34. ('mail_message_id', '=', message.id),
  35. ('partner_id', '=', self.recipient.id),
  36. ])
  37. # The tracking email must be sent
  38. self.assertTrue(tracking_email)
  39. self.assertEqual(tracking_email.state, 'sent')
  40. # message_dict read by web interface
  41. message_dict = self.env['mail.message'].message_read(message.id)
  42. # First item is message content
  43. self.assertTrue(len(message_dict) > 0)
  44. message_dict = message_dict[0]
  45. self.assertTrue(len(message_dict['partner_ids']) > 0)
  46. # First partner is recipient
  47. partner_id = message_dict['partner_ids'][0][0]
  48. self.assertEqual(partner_id, self.recipient.id)
  49. status = message_dict['partner_trackings'][str(partner_id)]
  50. # Tracking status must be sent and
  51. # mail tracking must be the one search before
  52. self.assertEqual(status[0], 'sent')
  53. self.assertEqual(status[1], tracking_email.id)
  54. # And now open the email
  55. metadata = {
  56. 'ip': '127.0.0.1',
  57. 'user_agent': 'Odoo Test/1.0',
  58. 'os_family': 'linux',
  59. 'ua_family': 'odoo',
  60. }
  61. tracking_email.event_process('open', metadata)
  62. self.assertEqual(tracking_email.state, 'opened')