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.

34 lines
1.2 KiB

  1. # Copyright 2020 Akretion (http://www.akretion.com).
  2. # @author Sébastien BEAU <sebastien.beau@akretion.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from odoo import SUPERUSER_ID
  5. from odoo.exceptions import UserError
  6. from odoo.tests import SavepointCase
  7. class SudoTechCase(SavepointCase):
  8. @classmethod
  9. def setUpClass(cls):
  10. super(SudoTechCase, cls).setUpClass()
  11. cls.user_tech = (
  12. cls.env["res.users"]
  13. .with_context(tracking_disable=True, no_reset_password=True)
  14. .create({"login": "tech", "name": "tech"})
  15. )
  16. cls.company = cls.env.ref("base.main_company")
  17. cls.env(user=cls.env.ref("base.user_demo").id)
  18. def test_sudo_tech(self):
  19. self.company.user_tech_id = self.user_tech
  20. self_tech = self.env["res.partner"].sudo_tech()
  21. self.assertEqual(self_tech._uid, self.user_tech.id)
  22. def test_sudo_tech_missing_return_sudo(self):
  23. self_tech = self.env["res.partner"].sudo_tech()
  24. self.assertEqual(self_tech._uid, SUPERUSER_ID)
  25. def test_sudo_tech_missing_raise(self):
  26. with self.assertRaises(UserError):
  27. self.env["res.partner"].sudo_tech(raise_if_missing=True)