-
-
Notifications
You must be signed in to change notification settings - Fork 441
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
component: add is_component_registry_ready
Handy function to allow depending modules to check for registry readyness w/o exposing internals.
- Loading branch information
Showing
3 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
from . import test_component | ||
from . import test_lookup | ||
from . import test_work_on | ||
from . import test_utils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |