Skip to content

Commit

Permalink
Merge PR #467 into 15.0
Browse files Browse the repository at this point in the history
Signed-off-by simahawk
  • Loading branch information
OCA-git-bot committed Oct 17, 2023
2 parents 8d02a9c + 88673a9 commit 379f7c7
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 36 deletions.
20 changes: 20 additions & 0 deletions component/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 16 additions & 5 deletions component_event/tests/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
29 changes: 20 additions & 9 deletions connector/tests/test_advisory_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
17 changes: 14 additions & 3 deletions connector/tests/test_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
41 changes: 26 additions & 15 deletions connector/tests/test_locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
19 changes: 15 additions & 4 deletions connector/tests/test_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 379f7c7

Please sign in to comment.