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.

121 lines
4.1 KiB

7 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. # Copyright 2015 Therp BV <https://therp.nl>
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
  3. from odoo.tests.common import TransactionCase
  4. class AuditlogCommon(object):
  5. def test_LogCreation(self):
  6. """First test, caching some data."""
  7. self.groups_rule.subscribe()
  8. auditlog_log = self.env['auditlog.log']
  9. group = self.env['res.groups'].create({
  10. 'name': 'testgroup1',
  11. })
  12. self.assertTrue(auditlog_log.search([
  13. ('model_id', '=', self.groups_model_id),
  14. ('method', '=', 'create'),
  15. ('res_id', '=', group.id),
  16. ]).ensure_one())
  17. group.write({'name': 'Testgroup1'})
  18. self.assertTrue(auditlog_log.search([
  19. ('model_id', '=', self.groups_model_id),
  20. ('method', '=', 'write'),
  21. ('res_id', '=', group.id),
  22. ]).ensure_one())
  23. group.unlink()
  24. self.assertTrue(auditlog_log.search([
  25. ('model_id', '=', self.groups_model_id),
  26. ('method', '=', 'unlink'),
  27. ('res_id', '=', group.id),
  28. ]).ensure_one())
  29. def test_LogCreation2(self):
  30. """Second test, using cached data of the first one."""
  31. self.groups_rule.subscribe()
  32. auditlog_log = self.env['auditlog.log']
  33. testgroup2 = self.env['res.groups'].create({
  34. 'name': 'testgroup2',
  35. })
  36. self.assertTrue(auditlog_log.search([
  37. ('model_id', '=', self.groups_model_id),
  38. ('method', '=', 'create'),
  39. ('res_id', '=', testgroup2.id),
  40. ]).ensure_one())
  41. def test_LogCreation3(self):
  42. """Third test, two groups, the latter being the parent of the former.
  43. Then we remove it right after (with (2, X) tuple) to test the creation
  44. of a 'write' log with a deleted resource (so with no text
  45. representation).
  46. """
  47. self.groups_rule.subscribe()
  48. auditlog_log = self.env['auditlog.log']
  49. testgroup3 = testgroup3 = self.env['res.groups'].create({
  50. 'name': 'testgroup3',
  51. })
  52. testgroup4 = self.env['res.groups'].create({
  53. 'name': 'testgroup4',
  54. 'implied_ids': [(4, testgroup3.id)],
  55. })
  56. testgroup4.write({'implied_ids': [(2, testgroup3.id)]})
  57. self.assertTrue(auditlog_log.search([
  58. ('model_id', '=', self.groups_model_id),
  59. ('method', '=', 'create'),
  60. ('res_id', '=', testgroup3.id),
  61. ]).ensure_one())
  62. self.assertTrue(auditlog_log.search([
  63. ('model_id', '=', self.groups_model_id),
  64. ('method', '=', 'create'),
  65. ('res_id', '=', testgroup4.id),
  66. ]).ensure_one())
  67. self.assertTrue(auditlog_log.search([
  68. ('model_id', '=', self.groups_model_id),
  69. ('method', '=', 'write'),
  70. ('res_id', '=', testgroup4.id),
  71. ]).ensure_one())
  72. class TestAuditlogFull(TransactionCase, AuditlogCommon):
  73. def setUp(self):
  74. super(TestAuditlogFull, self).setUp()
  75. self.groups_model_id = self.env.ref('base.model_res_groups').id
  76. self.groups_rule = self.env['auditlog.rule'].create({
  77. 'name': 'testrule for groups',
  78. 'model_id': self.groups_model_id,
  79. 'log_read': True,
  80. 'log_create': True,
  81. 'log_write': True,
  82. 'log_unlink': True,
  83. 'log_type': 'full',
  84. })
  85. def tearDown(self):
  86. self.groups_rule.unlink()
  87. super(TestAuditlogFull, self).tearDown()
  88. class TestAuditlogFast(TransactionCase, AuditlogCommon):
  89. def setUp(self):
  90. super(TestAuditlogFast, self).setUp()
  91. self.groups_model_id = self.env.ref('base.model_res_groups').id
  92. self.groups_rule = self.env['auditlog.rule'].create({
  93. 'name': 'testrule for groups',
  94. 'model_id': self.groups_model_id,
  95. 'log_read': True,
  96. 'log_create': True,
  97. 'log_write': True,
  98. 'log_unlink': True,
  99. 'log_type': 'fast',
  100. })
  101. def tearDown(self):
  102. self.groups_rule.unlink()
  103. super(TestAuditlogFast, self).tearDown()