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.

107 lines
4.2 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # This module copyright (C) 2015 Therp BV (<http://therp.nl>).
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from openerp.tests.common import TransactionCase
  22. class TestAuditlog(TransactionCase):
  23. def setUp(self):
  24. super(TestAuditlog, self).setUp()
  25. self.groups_model_id = self.env.ref('base.model_res_groups').id
  26. self.groups_rule = self.env['auditlog.rule'].create({
  27. 'name': 'testrule for groups',
  28. 'model_id': self.groups_model_id,
  29. 'log_read': True,
  30. 'log_create': True,
  31. 'log_write': True,
  32. 'log_unlink': True,
  33. 'state': 'subscribed',
  34. })
  35. def tearDown(self):
  36. self.groups_rule.unlink()
  37. super(TestAuditlog, self).tearDown()
  38. def test_LogCreation(self):
  39. """First test, caching some data."""
  40. auditlog_log = self.env['auditlog.log']
  41. group = self.env['res.groups'].create({
  42. 'name': 'testgroup1',
  43. })
  44. self.assertTrue(auditlog_log.search([
  45. ('model_id', '=', self.groups_model_id),
  46. ('method', '=', 'create'),
  47. ('res_id', '=', group.id),
  48. ]).ensure_one())
  49. group.write({'name': 'Testgroup1'})
  50. self.assertTrue(auditlog_log.search([
  51. ('model_id', '=', self.groups_model_id),
  52. ('method', '=', 'write'),
  53. ('res_id', '=', group.id),
  54. ]).ensure_one())
  55. group.unlink()
  56. self.assertTrue(auditlog_log.search([
  57. ('model_id', '=', self.groups_model_id),
  58. ('method', '=', 'unlink'),
  59. ('res_id', '=', group.id),
  60. ]).ensure_one())
  61. def test_LogCreation2(self):
  62. """Second test, using cached data of the first one."""
  63. auditlog_log = self.env['auditlog.log']
  64. testgroup2 = self.env['res.groups'].create({
  65. 'name': 'testgroup2',
  66. })
  67. self.assertTrue(auditlog_log.search([
  68. ('model_id', '=', self.groups_model_id),
  69. ('method', '=', 'create'),
  70. ('res_id', '=', testgroup2.id),
  71. ]).ensure_one())
  72. def test_LogCreation3(self):
  73. """Third test, two groups, the latter being the parent of the former.
  74. Then we remove it right after (with (2, X) tuple) to test the creation
  75. of a 'write' log with a deleted resource (so with no text
  76. representation).
  77. """
  78. auditlog_log = self.env['auditlog.log']
  79. testgroup3 = testgroup3 = self.env['res.groups'].create({
  80. 'name': 'testgroup3',
  81. })
  82. testgroup4 = self.env['res.groups'].create({
  83. 'name': 'testgroup4',
  84. 'implied_ids': [(4, testgroup3.id)],
  85. })
  86. testgroup4.write({'implied_ids': [(2, testgroup3.id)]})
  87. self.assertTrue(auditlog_log.search([
  88. ('model_id', '=', self.groups_model_id),
  89. ('method', '=', 'create'),
  90. ('res_id', '=', testgroup3.id),
  91. ]).ensure_one())
  92. self.assertTrue(auditlog_log.search([
  93. ('model_id', '=', self.groups_model_id),
  94. ('method', '=', 'create'),
  95. ('res_id', '=', testgroup4.id),
  96. ]).ensure_one())
  97. self.assertTrue(auditlog_log.search([
  98. ('model_id', '=', self.groups_model_id),
  99. ('method', '=', 'write'),
  100. ('res_id', '=', testgroup4.id),
  101. ]).ensure_one())