Skip to content

Commit

Permalink
Merge PR #468 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by dreispt
  • Loading branch information
OCA-git-bot committed Apr 27, 2024
2 parents 9fd43cb + 9835126 commit d9ced3c
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 37 deletions.
16 changes: 15 additions & 1 deletion component/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from odoo import api
from odoo.tests import common

from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT
from odoo.addons.component.core import ComponentRegistry, MetaComponent, _get_addon_name


Expand Down Expand Up @@ -67,6 +68,7 @@ class TransactionComponentCase(common.TransactionCase, ComponentMixin):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
cls.setUpComponent()

# pylint: disable=W8106
Expand Down Expand Up @@ -208,5 +210,17 @@ def tearDownClass(cls):
# pylint: disable=W8106
@classmethod
def setUpClass(cls):
super().setUpClass()
# 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"]
13 changes: 8 additions & 5 deletions component_event/tests/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from odoo.tests.common import MetaCase, tagged

from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT
from odoo.addons.component.core import Component
from odoo.addons.component.tests.common import (
ComponentRegistryCase,
Expand All @@ -23,11 +24,13 @@ 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, **DISABLED_MAIL_CONTEXT))
cls.record = mock.MagicMock(name="record")
cls.components_registry = mock.MagicMock(name="ComponentRegistry")

def test_env(self):
"""WorkContext with env"""
Expand Down
21 changes: 12 additions & 9 deletions connector/tests/test_advisory_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,28 @@
from odoo.modules.registry import Registry
from odoo.tests import common

from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT
from odoo.addons.component.core import WorkContext
from odoo.addons.component.tests.common import TransactionComponentCase
from odoo.addons.connector.database import pg_try_advisory_lock
from odoo.addons.queue_job.exception import RetryableJobError


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, **DISABLED_MAIL_CONTEXT))
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"""
Expand Down
9 changes: 6 additions & 3 deletions connector/tests/test_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from odoo.tools import frozendict

from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT
from odoo.addons.component.core import Component
from odoo.addons.component.tests.common import TransactionComponentRegistryCase
from odoo.addons.component_event.components.event import skip_if
Expand All @@ -15,9 +16,11 @@
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, **DISABLED_MAIL_CONTEXT))
cls._setup_registry(cls)

def test_skip_if_no_connector_export(self):
class MyEventListener(Component):
Expand Down
33 changes: 18 additions & 15 deletions connector/tests/test_locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,32 @@
from odoo.modules.registry import Registry
from odoo.tests import common

from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT
from odoo.addons.component.core import WorkContext
from odoo.addons.component.tests.common import TransactionComponentRegistryCase
from odoo.addons.queue_job.exception import RetryableJobError


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, **DISABLED_MAIL_CONTEXT))
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"""
Expand Down
11 changes: 7 additions & 4 deletions connector/tests/test_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from unittest import mock

from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT
from odoo.addons.component.core import Component, WorkContext
from odoo.addons.component.tests.common import TransactionComponentRegistryCase
from odoo.addons.connector.components.mapper import (
Expand All @@ -20,10 +21,12 @@


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, **DISABLED_MAIL_CONTEXT))
cls._setup_registry(cls)
cls.comp_registry.load_components("connector")

def test_mapping_decorator(self):
class KifKrokerMapper(Component):
Expand Down

0 comments on commit d9ced3c

Please sign in to comment.