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.

57 lines
2.1 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 Simone Orsi <simone.orsi@camptocamp.com>
  3. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
  4. from odoo.tests.common import SavepointCase
  5. import mock
  6. from ..controllers.digest_layout_preview import DigestPreview
  7. REQUEST_PATH = 'odoo.addons.mail_digest.controllers.digest_layout_preview'
  8. class PreviewCase(SavepointCase):
  9. """Easy tests for preview controller to make codecov happy."""
  10. @classmethod
  11. def setUpClass(cls):
  12. super(PreviewCase, cls).setUpClass()
  13. cls.ctrl = DigestPreview()
  14. @mock.patch(REQUEST_PATH + '.request')
  15. def test_fake_digest(self, patched_req):
  16. patched_req.env = self.env
  17. digest = self.ctrl._fake_digest()
  18. self.assertEqual(
  19. digest.partner_id, self.env.user.partner_id,
  20. )
  21. self.assertEqual(
  22. digest.digest_template_id, digest._default_digest_template_id(),
  23. )
  24. self.assertTrue(digest.message_ids)
  25. self.assertTrue(digest.sanitize_msg_body)
  26. @mock.patch(REQUEST_PATH + '.request')
  27. def test_fake_messages(self, patched_req):
  28. patched_req.env = self.env
  29. all_types = self.env['mail.message.subtype'].search([])
  30. messages = self.ctrl._fake_messages()
  31. self.assertEqual(
  32. len(messages), len(all_types) * 2
  33. )
  34. @mock.patch(REQUEST_PATH + '.request')
  35. def test_fake_content(self, patched_req):
  36. patched_req.env = self.env
  37. subj, body = self.ctrl._fake_content(None, 1, 2)
  38. body = 'Random text here lorem ipsum 1 / 2'
  39. self.assertEqual(subj, 'Lorem ipsum 1 / 2')
  40. self.assertEqual(body, 'Random text here lorem ipsum 1 / 2')
  41. subj, body = self.ctrl._fake_content(None, 2, 2)
  42. self.assertEqual(subj, 'Lorem ipsum 2 / 2')
  43. self.assertTrue(body.startswith('<p style="font-size: 13px;'))
  44. @mock.patch(REQUEST_PATH + '.request')
  45. def test_fake_tracking_vals(self, patched_req):
  46. patched_req.env = self.env
  47. vals = self.ctrl._fake_tracking_vals()
  48. self.assertEqual(len(vals), 2)