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.

51 lines
2.4 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # This module copyright (C) 2015 Therp BV (<http://therp.nl>).
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as
  8. # published by the Free Software Foundation, either version 3 of the
  9. # License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. ##############################################################################
  20. from openerp import exceptions
  21. from openerp.tests.common import TransactionCase
  22. class TestBaseSuspendSecurity(TransactionCase):
  23. def test_base_suspend_security(self):
  24. # tests are called before register_hook
  25. self.env['ir.rule']._register_hook()
  26. user_id = self.env.ref('base.user_demo').id
  27. other_company = self.env['res.company'].create({
  28. 'name': 'other company',
  29. # without this, a partner is created and mail's constraint on
  30. # notify_email kicks in
  31. 'partner_id': self.env.ref('base.partner_demo').id,
  32. })
  33. # be sure what we try is forbidden
  34. with self.assertRaises(exceptions.AccessError):
  35. self.env.ref('base.user_root').sudo(user_id).name = 'test'
  36. with self.assertRaises(exceptions.AccessError):
  37. other_company.sudo(user_id).name = 'test'
  38. # this tests ir.model.access
  39. self.env.ref('base.user_root').sudo(user_id).suspend_security().write({
  40. 'name': 'test'})
  41. self.assertEqual(self.env.ref('base.user_root').name, 'test')
  42. self.assertEqual(self.env.ref('base.user_root').write_uid.id, user_id)
  43. # this tests ir.rule
  44. other_company.sudo(user_id).suspend_security().write({'name': 'test'})
  45. self.assertEqual(other_company.name, 'test')
  46. self.assertEqual(other_company.write_uid.id, user_id)
  47. # this tests if _normalize_args conversion works
  48. self.env['res.users'].browse(
  49. self.env['res.users'].suspend_security().env.uid)