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.

56 lines
2.4 KiB

  1. # Copyright 2019 Ecosoft Co., Ltd (http://ecosoft.co.th/)
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
  3. from odoo.tests import common
  4. from odoo.tests.common import Form
  5. from odoo.exceptions import UserError
  6. class TestJobChannel(common.TransactionCase):
  7. def setUp(self):
  8. super(TestJobChannel, self).setUp()
  9. self.print_doc = self.env.ref('report_async.'
  10. 'report_async_print_document')
  11. self.test_rec = self.env.ref('base.module_mail')
  12. self.test_rpt = self.env.ref('base.ir_module_reference_print')
  13. def _print_wizard(self, res):
  14. obj = self.env[res['res_model']]
  15. ctx = {'active_model': self.print_doc._name,
  16. 'active_id': self.print_doc.id, }
  17. ctx.update(res['context'])
  18. with Form(obj.with_context(ctx)) as form:
  19. form.reference = '%s,%s' % (self.test_rec._name, self.test_rec.id)
  20. form.action_report_id = self.test_rpt
  21. print_wizard = form.save()
  22. return print_wizard
  23. def test_1_run_now(self):
  24. """Run now will return report action as normal"""
  25. res = self.print_doc.run_now()
  26. report_action = self._print_wizard(res).print_report()
  27. self.assertEquals(report_action['type'], 'ir.actions.report')
  28. def test_2_run_async(self):
  29. """Run background will return nothing, job started"""
  30. with self.assertRaises(UserError):
  31. self.print_doc.run_async()
  32. self.print_doc.write({'allow_async': True,
  33. 'email_notify': True})
  34. res = self.print_doc.run_async()
  35. print_wizard = self._print_wizard(res)
  36. report_action = print_wizard.print_report()
  37. self.assertEquals(report_action, {}) # Do not run report yet
  38. self.assertEquals(self.print_doc.job_status, 'pending') # Job started
  39. # Test produce file (as queue will not run in test mode)
  40. docids = [print_wizard.reference.id]
  41. data = None
  42. report_id = self.test_rpt.id
  43. user_id = self.env.user.id
  44. self.print_doc.run_report(docids, data, report_id, user_id)
  45. # Check name of the newly producted file
  46. # Note: on env with test-enable, always fall back to render_qweb_html
  47. self.assertIn(self.test_rpt.name, self.print_doc.file_ids[0].name)
  48. # View fileds/jobs
  49. self.print_doc.view_files()
  50. self.print_doc.view_jobs()