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.

116 lines
4.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
  1. # -*- coding: utf-8 -*-
  2. # © 2015 Therp BV <http://therp.nl>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from openerp.tests.common import TransactionCase
  5. class TestAuditlog(object):
  6. def test_LogCreation(self):
  7. """First test, caching some data."""
  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. auditlog_log = self.env['auditlog.log']
  32. testgroup2 = self.env['res.groups'].create({
  33. 'name': 'testgroup2',
  34. })
  35. self.assertTrue(auditlog_log.search([
  36. ('model_id', '=', self.groups_model_id),
  37. ('method', '=', 'create'),
  38. ('res_id', '=', testgroup2.id),
  39. ]).ensure_one())
  40. def test_LogCreation3(self):
  41. """Third test, two groups, the latter being the parent of the former.
  42. Then we remove it right after (with (2, X) tuple) to test the creation
  43. of a 'write' log with a deleted resource (so with no text
  44. representation).
  45. """
  46. auditlog_log = self.env['auditlog.log']
  47. testgroup3 = testgroup3 = self.env['res.groups'].create({
  48. 'name': 'testgroup3',
  49. })
  50. testgroup4 = self.env['res.groups'].create({
  51. 'name': 'testgroup4',
  52. 'implied_ids': [(4, testgroup3.id)],
  53. })
  54. testgroup4.write({'implied_ids': [(2, testgroup3.id)]})
  55. self.assertTrue(auditlog_log.search([
  56. ('model_id', '=', self.groups_model_id),
  57. ('method', '=', 'create'),
  58. ('res_id', '=', testgroup3.id),
  59. ]).ensure_one())
  60. self.assertTrue(auditlog_log.search([
  61. ('model_id', '=', self.groups_model_id),
  62. ('method', '=', 'create'),
  63. ('res_id', '=', testgroup4.id),
  64. ]).ensure_one())
  65. self.assertTrue(auditlog_log.search([
  66. ('model_id', '=', self.groups_model_id),
  67. ('method', '=', 'write'),
  68. ('res_id', '=', testgroup4.id),
  69. ]).ensure_one())
  70. class TestAuditlogFull(TransactionCase, TestAuditlog):
  71. def setUp(self):
  72. super(TestAuditlogFull, self).setUp()
  73. self.groups_model_id = self.env.ref('base.model_res_groups').id
  74. self.groups_rule = self.env['auditlog.rule'].create({
  75. 'name': 'testrule for groups',
  76. 'model_id': self.groups_model_id,
  77. 'log_read': True,
  78. 'log_create': True,
  79. 'log_write': True,
  80. 'log_unlink': True,
  81. 'state': 'subscribed',
  82. 'log_type': 'full',
  83. })
  84. def tearDown(self):
  85. self.groups_rule.unlink()
  86. super(TestAuditlogFull, self).tearDown()
  87. class TestAuditlogFast(TransactionCase, TestAuditlog):
  88. def setUp(self):
  89. super(TestAuditlogFast, self).setUp()
  90. self.groups_model_id = self.env.ref('base.model_res_groups').id
  91. self.groups_rule = self.env['auditlog.rule'].create({
  92. 'name': 'testrule for groups',
  93. 'model_id': self.groups_model_id,
  94. 'log_read': True,
  95. 'log_create': True,
  96. 'log_write': True,
  97. 'log_unlink': True,
  98. 'state': 'subscribed',
  99. 'log_type': 'fast',
  100. })
  101. def tearDown(self):
  102. self.groups_rule.unlink()
  103. super(TestAuditlogFast, self).tearDown()