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.

77 lines
3.0 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
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 test_LogCreation(self):
  24. """First test, caching some data."""
  25. auditlog_log = self.env['auditlog.log']
  26. groups_model_id = self.env.ref('base.model_res_groups').id
  27. self.env['auditlog.rule'].create({
  28. 'name': 'testrule for groups',
  29. 'model_id': groups_model_id,
  30. 'log_create': True,
  31. 'log_write': True,
  32. 'log_unlink': True,
  33. 'state': 'subscribed',
  34. })
  35. group = self.env['res.groups'].create({
  36. 'name': 'testgroup1',
  37. })
  38. self.assertTrue(auditlog_log.search([
  39. ('model_id', '=', groups_model_id),
  40. ('method', '=', 'create'),
  41. ('res_id', '=', group.id),
  42. ]))
  43. group.write({'name': 'Testgroup1'})
  44. self.assertTrue(auditlog_log.search([
  45. ('model_id', '=', groups_model_id),
  46. ('method', '=', 'write'),
  47. ('res_id', '=', group.id),
  48. ]))
  49. group.unlink()
  50. self.assertTrue(auditlog_log.search([
  51. ('model_id', '=', groups_model_id),
  52. ('method', '=', 'unlink'),
  53. ('res_id', '=', group.id),
  54. ]))
  55. def test_LogCreation2(self):
  56. """Second test, using cached data of the first one."""
  57. self.env['res.groups'].create({
  58. 'name': 'testgroup2',
  59. })
  60. def test_LogCreation3(self):
  61. """Third test, two groups, the latter being the parent of the former.
  62. Then we remove it right after (with (2, X) tuple) to test the creation
  63. of a 'write' log with a deleted resource (so with no text
  64. representation).
  65. """
  66. testgroup3 = self.env['res.groups'].create({
  67. 'name': 'testgroup3',
  68. })
  69. testgroup4 = self.env['res.groups'].create({
  70. 'name': 'testgroup4',
  71. 'implied_ids': [(4, testgroup3.id)],
  72. })
  73. testgroup4.write({'implied_ids': [(2, testgroup3.id)]})