OCA reporting engine fork for dev and update.
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.

32 lines
1.4 KiB

  1. # © 2016 Therp BV <http://therp.nl>
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. from odoo.exceptions import ValidationError
  4. from odoo.tests.common import HttpCase
  5. class TestReportQwebEncrypt(HttpCase):
  6. def test_report_qweb_no_encrypt(self):
  7. ctx = {"force_report_rendering": True}
  8. report = self.env.ref("web.action_report_internalpreview")
  9. report.encrypt = False
  10. pdf, _ = report.with_context(ctx)._render_qweb_pdf([1])
  11. self.assertFalse(pdf.count(b"/Encrypt"))
  12. def test_report_qweb_auto_encrypt(self):
  13. ctx = {"force_report_rendering": True}
  14. report = self.env.ref("web.action_report_internalpreview")
  15. report.encrypt = "auto"
  16. report.encrypt_password = False
  17. # If no encrypt_password, still not encrypted
  18. pdf, _ = report.with_context(ctx)._render_qweb_pdf([1])
  19. self.assertFalse(pdf.count(b"/Encrypt"))
  20. # If invalid encrypt_password, show error
  21. report.encrypt_password = "invalid python syntax"
  22. with self.assertRaises(ValidationError):
  23. pdf, _ = report.with_context(ctx)._render_qweb_pdf([1])
  24. # Valid python string for password
  25. report.encrypt_password = "'secretcode'"
  26. pdf, _ = report.with_context(ctx)._render_qweb_pdf([1])
  27. self.assertTrue(pdf.count(b"/Encrypt"))
  28. # TODO: test_report_qweb_manual_encrypt, require JS test?