diff --git a/connector_search_engine/tests/common.py b/connector_search_engine/tests/common.py index 65a9a79..74d07be 100644 --- a/connector_search_engine/tests/common.py +++ b/connector_search_engine/tests/common.py @@ -4,7 +4,7 @@ # Sébastien BEAU # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import mock -from odoo import api, models +from odoo import models from odoo.addons.component.tests.common import SavepointComponentCase @@ -25,18 +25,18 @@ class TestSeBackendCase(SavepointComponentCase): Tests With a fake Se Backend """ - def _init_test_model(self, model_cls): + @classmethod + def _init_test_model(cls, model_cls): """ Function to init/create a new Odoo Model during unit test. Based on base_kanban_stage/test/test_base_kanban_abstract.py :param model_cls: Odoo Model class :return: instance of model (empty) """ - registry = self.env.registry - registry.enter_test_mode() - cr = self.env.cr + registry = cls.env.registry + cr = cls.env.cr model_cls._build_model(registry, cr) - model = self.env[model_cls._name].with_context(todo=[]) + model = cls.env[model_cls._name].with_context(todo=[]) model._prepare_setup() model._setup_base(partial=False) model._setup_fields(partial=False) @@ -44,23 +44,28 @@ def _init_test_model(self, model_cls): model._auto_init() model.init() model._auto_end() - return self.env[model_cls._name] + return cls.env[model_cls._name] + + @classmethod + def setUpClass(cls): + super(TestSeBackendCase, cls).setUpClass() + cls.env.cr.commit = mock.MagicMock() + cls._init_test_model(TestSeBackend) def setUp(self): super(TestSeBackendCase, self).setUp() - # To load a new Model, we have to use a new cursor and env. - # Because there is a commit on the model._auto_init() - # Based on base_kanban_stage/test/test_base_kanban_abstract.py - # self.registry.enter_test_mode() - # self.old_cursor = self.cr - # self.cr = self.registry.cursor() - self.cr.commit = mock.MagicMock() - self.env = api.Environment(self.cr, self.uid, {}) - self._init_test_model(TestSeBackend) self.se_backend = self.env['test.se.backend'].create({ 'specific_model': 'test.se.backend', }) - def tearDown(self): - self.registry.leave_test_mode() - super(TestSeBackendCase, self).tearDown() + @classmethod + def tearDownClass(cls): + # The cursor have been not commited as it have been mocked + # so there is not table 'test_se_backend' in the DB + # but the registry have been polluted by the class test.se.backend + # To avoid having error message (missing table 'test.se.backend' when + # running the test on several module + # We flag this class as an abstract class + # so odoo will do not care that the table do not exist + cls.env.registry['test.se.backend']._abstract = True + super(TestSeBackendCase, cls).tearDownClass()