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.

62 lines
2.2 KiB

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