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.

50 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. user_id = self.env.ref('base.user_demo').id
  26. other_company = self.env['res.company'].create({
  27. 'name': 'other company',
  28. # without this, a partner is created and mail's constraint on
  29. # notify_email kicks in
  30. 'partner_id': self.env.ref('base.partner_demo').id,
  31. })
  32. # be sure what we try is forbidden
  33. with self.assertRaises(exceptions.AccessError):
  34. self.env.ref('base.user_root').sudo(user_id).name = 'test'
  35. with self.assertRaises(exceptions.AccessError):
  36. other_company.sudo(user_id).name = 'test'
  37. # this tests ir.model.access
  38. self.env.ref('base.user_root').sudo(user_id).suspend_security().write({
  39. 'name': 'test'})
  40. self.assertEqual(self.env.ref('base.user_root').name, 'test')
  41. self.assertEqual(self.env.ref('base.user_root').write_uid.id, user_id)
  42. # this tests ir.rule
  43. other_company.sudo(user_id).suspend_security().write({'name': 'test'})
  44. self.assertEqual(other_company.name, 'test')
  45. self.assertEqual(other_company.write_uid.id, user_id)
  46. # this tests if _normalize_args conversion works
  47. self.env['res.users'].browse(
  48. self.env['res.users'].suspend_security().env.uid)