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.

44 lines
1.6 KiB

  1. # coding: utf-8
  2. # Copyright (C) 2018 - Today: GRAP (http://www.grap.coop)
  3. # @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. from openerp.tests.common import TransactionCase
  6. class TestModule(TransactionCase):
  7. """Tests for 'Cron - Inactivity Period' Module"""
  8. def setUp(self):
  9. super(TestModule, self).setUp()
  10. self.config_obj = self.env['res.config']
  11. self.cron_obj = self.env['ir.cron']
  12. self.inactivity_period = self.env['ir.cron.inactivity.period']
  13. self.cron_job = self.env.ref('base.cronjob_osv_memory_autovacuum')
  14. # Test Section
  15. def test_01_no_inactivity_period(self):
  16. count = self._create_transient_model()
  17. self.assertEqual(
  18. count, 0,
  19. "Calling a cron without inactivity period should run the cron")
  20. def test_02_no_activity_period(self):
  21. self.inactivity_period.create({
  22. 'cron_id': self.cron_job.id,
  23. 'type': 'hour',
  24. 'inactivity_hour_begin': 0.0,
  25. 'inactivity_hour_end': 23.59,
  26. })
  27. count = self._create_transient_model()
  28. self.assertEqual(
  29. count, 1,
  30. "Calling a cron with inactivity period should not run the cron")
  31. def _create_transient_model(self):
  32. self.config_obj.search([]).unlink()
  33. self.config_obj.create({})
  34. self.env.cr.execute("update res_config set write_date = '1970-01-01'")
  35. self.cron_obj._callback(
  36. 'osv_memory.autovacuum', 'power_on', (), self.cron_job.id)
  37. return len(self.config_obj.search([]))