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.

48 lines
1.6 KiB

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