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.

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