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.

47 lines
1.6 KiB

7 years ago
  1. # © 2016 ABF OSIELL <https://osiell.com>
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
  3. import time
  4. from odoo.tests.common import TransactionCase
  5. class TestAuditlogAutovacuum(TransactionCase):
  6. def setUp(self):
  7. super(TestAuditlogAutovacuum, self).setUp()
  8. self.groups_model_id = self.env.ref('base.model_res_groups').id
  9. self.groups_rule = self.env['auditlog.rule'].create({
  10. 'name': 'testrule for groups',
  11. 'model_id': self.groups_model_id,
  12. 'log_read': True,
  13. 'log_create': True,
  14. 'log_write': True,
  15. 'log_unlink': True,
  16. 'state': 'subscribed',
  17. 'log_type': 'full',
  18. })
  19. def tearDown(self):
  20. self.groups_rule.unlink()
  21. super(TestAuditlogAutovacuum, self).tearDown()
  22. def test_autovacuum(self):
  23. log_model = self.env['auditlog.log']
  24. autovacuum_model = self.env['auditlog.autovacuum']
  25. group = self.env['res.groups'].create({
  26. 'name': 'testgroup1',
  27. })
  28. nb_logs = log_model.search_count([
  29. ('model_id', '=', self.groups_model_id),
  30. ('res_id', '=', group.id),
  31. ])
  32. self.assertGreater(nb_logs, 0)
  33. # Milliseconds are ignored by autovacuum, waiting 1s ensure that
  34. # the logs generated will be processed by the vacuum
  35. time.sleep(1)
  36. autovacuum_model.autovacuum(days=0)
  37. nb_logs = log_model.search_count([
  38. ('model_id', '=', self.groups_model_id),
  39. ('res_id', '=', group.id),
  40. ])
  41. self.assertEqual(nb_logs, 0)