test_env.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo.tests.common import TransactionCase
  4. class TestEnv(TransactionCase):
  5. @classmethod
  6. def setUpClass(cls):
  7. super(TestEnv, cls).setUpClass()
  8. user = cls.env['res.users'].create({
  9. 'name': 'superuser',
  10. 'login': 'superuser',
  11. 'password': 'superuser',
  12. 'groups_id': [(6, 0, cls.env.user.groups_id.ids)],
  13. })
  14. cls.env = cls.env(user=user)
  15. # make sure there is at least another environment in the current transaction
  16. cls.sudo_env = cls.env(su=True)
  17. def test_env_company_part_01(self):
  18. """
  19. The main goal of the test is actually to check the values of the
  20. environment after this test execution (see test_env_company_part_02)
  21. """
  22. company = self.env['res.company'].create({
  23. "name": "Test Company",
  24. })
  25. self.env.user.write({
  26. 'company_id': company.id,
  27. 'company_ids': [(4, company.id), (4, self.env.company.id)],
  28. })
  29. self.assertEqual(self.env.company, self.env.user.company_id)
  30. self.assertTrue(self.env.company.exists())
  31. self.assertEqual(self.sudo_env.company, self.env.user.company_id)
  32. self.assertTrue(self.sudo_env.company.exists())
  33. def test_env_company_part_02(self):
  34. self.assertEqual(self.env.company, self.env.user.company_id)
  35. self.assertTrue(self.env.company.exists())
  36. self.assertEqual(self.sudo_env.company, self.env.user.company_id)
  37. self.assertTrue(self.sudo_env.company.exists())