Skip to content

Commit

Permalink
component: add is_component_registry_ready
Browse files Browse the repository at this point in the history
Handy function to allow depending modules to check for registry readyness
w/o exposing internals.
  • Loading branch information
simahawk committed Sep 2, 2024
1 parent a93344b commit e9fb8dd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions component/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
from . import test_component
from . import test_lookup
from . import test_work_on
from . import test_utils
20 changes: 20 additions & 0 deletions component/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2023 Camptocamp SA
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)

from unittest import mock

from odoo.addons.component.utils import is_component_registry_ready

from .common import TransactionComponentRegistryCase


class TestUtils(TransactionComponentRegistryCase):
def test_registry_ready(self):
path = "odoo.addons.component.utils.get_component_registry"
with mock.patch(path) as mocked:
mocked.return_value = None
self.assertFalse(is_component_registry_ready(self.env.cr.dbname))
self._setup_registry(self)
mocked.return_value = self.comp_registry
self.assertTrue(is_component_registry_ready(self.env.cr.dbname))
self._teardown_registry(self)
14 changes: 14 additions & 0 deletions component/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2023 Camptocamp SA
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)

from .core import _component_databases


def get_component_registry(dbname):
return _component_databases.get(dbname)


def is_component_registry_ready(dbname):
"""Return True if the registry is ready to be used."""
comp_registry = get_component_registry(dbname)
return comp_registry.ready if comp_registry else False

0 comments on commit e9fb8dd

Please sign in to comment.