diff --git a/component/tests/common.py b/component/tests/common.py index e2a8076c9..205dc4479 100644 --- a/component/tests/common.py +++ b/component/tests/common.py @@ -68,6 +68,16 @@ class TransactionComponentCase(common.TransactionCase, ComponentMixin): @classmethod def setUpClass(cls): super().setUpClass() + cls.env = cls.env( + context=dict( + cls.env.context, + mail_create_nolog=True, + mail_create_nosubscribe=True, + mail_notrack=True, + no_reset_password=True, + tracking_disable=True, + ) + ) cls.setUpComponent() # pylint: disable=W8106 @@ -212,6 +222,16 @@ def setUpClass(cls): # resolve an inheritance issue (common.TransactionCase does not use # super) common.TransactionCase.setUpClass() + cls.env = cls.env( + context=dict( + cls.env.context, + mail_create_nolog=True, + mail_create_nosubscribe=True, + mail_notrack=True, + no_reset_password=True, + tracking_disable=True, + ) + ) cls.collection = cls.env["collection.base"] @classmethod diff --git a/component_event/tests/test_event.py b/component_event/tests/test_event.py index 6b2e68e34..ccd314971 100644 --- a/component_event/tests/test_event.py +++ b/component_event/tests/test_event.py @@ -24,11 +24,22 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.test_sequence = 0 - def setUp(self): - super().setUp() - self.env = mock.MagicMock(name="env") - self.record = mock.MagicMock(name="record") - self.components_registry = mock.MagicMock(name="ComponentRegistry") + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = mock.MagicMock(name="env") + cls.env = cls.env( + context=dict( + cls.env.context, + mail_create_nolog=True, + mail_create_nosubscribe=True, + mail_notrack=True, + no_reset_password=True, + tracking_disable=True, + ) + ) + cls.record = mock.MagicMock(name="record") + cls.components_registry = mock.MagicMock(name="ComponentRegistry") def test_env(self): """WorkContext with env""" diff --git a/connector/tests/test_advisory_lock.py b/connector/tests/test_advisory_lock.py index a30982abc..73375d44a 100644 --- a/connector/tests/test_advisory_lock.py +++ b/connector/tests/test_advisory_lock.py @@ -14,18 +14,29 @@ class TestAdvisoryLock(TransactionComponentCase): - def setUp(self): - super().setUp() - self.registry2 = Registry(common.get_db_name()) - self.cr2 = self.registry2.cursor() - self.env2 = api.Environment(self.cr2, self.env.uid, {}) + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env( + context=dict( + cls.env.context, + mail_create_nolog=True, + mail_create_nosubscribe=True, + mail_notrack=True, + no_reset_password=True, + tracking_disable=True, + ) + ) + cls.registry2 = Registry(common.get_db_name()) + cls.cr2 = cls.registry2.cursor() + cls.env2 = api.Environment(cls.cr2, cls.env.uid, {}) - @self.addCleanup + @cls.addClassCleanup def reset_cr2(): # rollback and close the cursor, and reset the environments - self.env2.reset() - self.cr2.rollback() - self.cr2.close() + cls.env2.reset() + cls.cr2.rollback() + cls.cr2.close() def test_concurrent_lock(self): """2 concurrent transactions cannot acquire the same lock""" diff --git a/connector/tests/test_listener.py b/connector/tests/test_listener.py index 27221a9cf..14683ece0 100644 --- a/connector/tests/test_listener.py +++ b/connector/tests/test_listener.py @@ -15,9 +15,20 @@ class TestEventListener(TransactionComponentRegistryCase): """Test Connecter Listener""" - def setUp(self): - super().setUp() - self._setup_registry(self) + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env( + context=dict( + cls.env.context, + mail_create_nolog=True, + mail_create_nosubscribe=True, + mail_notrack=True, + no_reset_password=True, + tracking_disable=True, + ) + ) + cls._setup_registry(cls) def test_skip_if_no_connector_export(self): class MyEventListener(Component): diff --git a/connector/tests/test_locker.py b/connector/tests/test_locker.py index 93ac1974d..65a0cda6a 100644 --- a/connector/tests/test_locker.py +++ b/connector/tests/test_locker.py @@ -13,23 +13,34 @@ class TestLocker(TransactionComponentRegistryCase): - def setUp(self): - super().setUp() - self.backend = mock.MagicMock(name="backend") - self.backend.env = self.env - - self.registry2 = Registry(common.get_db_name()) - self.cr2 = self.registry2.cursor() - self.env2 = api.Environment(self.cr2, self.env.uid, {}) - self.backend2 = mock.MagicMock(name="backend2") - self.backend2.env = self.env2 - - @self.addCleanup + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env( + context=dict( + cls.env.context, + mail_create_nolog=True, + mail_create_nosubscribe=True, + mail_notrack=True, + no_reset_password=True, + tracking_disable=True, + ) + ) + cls.backend = mock.MagicMock(name="backend") + cls.backend.env = cls.env + + cls.registry2 = Registry(common.get_db_name()) + cls.cr2 = cls.registry2.cursor() + cls.env2 = api.Environment(cls.cr2, cls.env.uid, {}) + cls.backend2 = mock.MagicMock(name="backend2") + cls.backend2.env = cls.env2 + + @cls.addClassCleanup def reset_cr2(): # rollback and close the cursor, and reset the environments - self.env2.reset() - self.cr2.rollback() - self.cr2.close() + cls.env2.reset() + cls.cr2.rollback() + cls.cr2.close() def test_lock(self): """Lock a record""" diff --git a/connector/tests/test_mapper.py b/connector/tests/test_mapper.py index cb0955c1c..c0323949e 100644 --- a/connector/tests/test_mapper.py +++ b/connector/tests/test_mapper.py @@ -20,10 +20,21 @@ class TestMapper(TransactionComponentRegistryCase): - def setUp(self): - super().setUp() - self._setup_registry(self) - self.comp_registry.load_components("connector") + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env( + context=dict( + cls.env.context, + mail_create_nolog=True, + mail_create_nosubscribe=True, + mail_notrack=True, + no_reset_password=True, + tracking_disable=True, + ) + ) + cls._setup_registry(cls) + cls.comp_registry.load_components("connector") def test_mapping_decorator(self): class KifKrokerMapper(Component):