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.

74 lines
2.7 KiB

  1. # -*- coding: utf-8 -*-
  2. #
  3. #
  4. # Authors: Guewen Baconnier
  5. # Copyright 2015 Camptocamp SA
  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 import common
  22. class TestChangesetFieldRule(common.TransactionCase):
  23. def setUp(self):
  24. super(TestChangesetFieldRule, self).setUp()
  25. self.partner_model_id = self.env.ref('base.model_res_partner').id
  26. self.field_name = self.env.ref('base.field_res_partner_name')
  27. self.field_street = self.env.ref('base.field_res_partner_street')
  28. def test_get_rules(self):
  29. ChangesetFieldRule = self.env['changeset.field.rule']
  30. rule1 = ChangesetFieldRule.create({
  31. 'model_id': self.partner_model_id,
  32. 'field_id': self.field_name.id,
  33. 'action': 'validate',
  34. })
  35. rule2 = ChangesetFieldRule.create({
  36. 'model_id': self.partner_model_id,
  37. 'field_id': self.field_street.id,
  38. 'action': 'never',
  39. })
  40. get_rules = ChangesetFieldRule.get_rules('res.partner')
  41. self.assertEqual(get_rules, {'name': rule1, 'street': rule2})
  42. def test_get_rules_cache(self):
  43. ChangesetFieldRule = self.env['changeset.field.rule']
  44. rule = ChangesetFieldRule.create({
  45. 'model_id': self.partner_model_id,
  46. 'field_id': self.field_name.id,
  47. 'action': 'validate',
  48. })
  49. self.assertEqual(
  50. ChangesetFieldRule.get_rules('res.partner')['name'].action,
  51. 'validate',
  52. )
  53. # Write on cursor to bypass the cache invalidation for the
  54. # matter of the test
  55. self.env.cr.execute("UPDATE changeset_field_rule "
  56. "SET action = 'never' "
  57. "WHERE id = %s", (rule.id,))
  58. self.assertEqual(
  59. ChangesetFieldRule.get_rules('res.partner')['name'].action,
  60. 'validate',
  61. )
  62. rule.action = 'auto'
  63. self.assertEqual(
  64. ChangesetFieldRule.get_rules('res.partner')['name'].action,
  65. 'auto',
  66. )
  67. rule.unlink()
  68. self.assertFalse(ChangesetFieldRule.get_rules('res.partner'))