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.

87 lines
3.2 KiB

6 years ago
  1. ###################################################################################
  2. #
  3. # Copyright (C) 2018 MuK IT GmbH
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU Affero General Public License as
  7. # published by the Free Software Foundation, either version 3 of the
  8. # License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU Affero General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Affero General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. #
  18. ###################################################################################
  19. import logging
  20. import datetime
  21. from odoo.tests import common
  22. from odoo.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT
  23. _logger = logging.getLogger(__name__)
  24. class AutoVacuumTestCase(common.TransactionCase):
  25. at_install = False
  26. post_install = True
  27. def _setUpData(self):
  28. model_logs = self.env['ir.logging']
  29. time = datetime.datetime.utcnow() - datetime.timedelta(days=60)
  30. for index in range(0, 3):
  31. model_logs.create({
  32. 'create_date': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
  33. 'create_uid': self.env.user.id,
  34. 'name': "Test %s" % index,
  35. 'type': 'server',
  36. 'dbname': self.env.cr.dbname,
  37. 'level': "INFO",
  38. 'message': "TEST",
  39. 'path': "PATH",
  40. 'func': "TEST",
  41. 'line': 1})
  42. def _setUpRules(self):
  43. model_rule = self.env['muk_autovacuum.rules']
  44. model_model = self.env['ir.model']
  45. model_fields = self.env['ir.model.fields']
  46. model_logs = model_model.search([('model', '=', 'ir.logging')], limit=1)
  47. time_field_domain = [
  48. ('model_id', '=', model_logs.id),
  49. ('ttype', '=', 'datetime'),
  50. ('name', '=', 'create_date')]
  51. time_field_logs = model_fields.search(time_field_domain, limit=1)
  52. model_rule.create({
  53. 'name': "Delete Logs after 1 Minute",
  54. 'state': 'time',
  55. 'model': model_logs.id,
  56. 'time_field': time_field_logs.id,
  57. 'time_type': 'minutes',
  58. 'time': 1})
  59. model_rule.create({
  60. 'name': "Delete Logs Count > 1",
  61. 'state': 'size',
  62. 'model': model_logs.id,
  63. 'size': 1,
  64. 'size_order': "id desc",
  65. 'size_type': 'fixed'})
  66. model_rule.create({
  67. 'name': "Delete Logs with Domain",
  68. 'state': 'domain',
  69. 'model': model_logs.id,
  70. 'domain': "[]"})
  71. def setUp(self):
  72. super(AutoVacuumTestCase, self).setUp()
  73. self._setUpData()
  74. self._setUpRules()
  75. def tearDown(self):
  76. super(AutoVacuumTestCase, self).tearDown()
  77. def test_autovacuum(self):
  78. self.env['ir.cron'].search([('model_id', '=', 'ir.autovacuum')]).ir_actions_server_id.run()