Skip to content

Commit

Permalink
component: allow propagation of custom registry
Browse files Browse the repository at this point in the history
  • Loading branch information
simahawk authored and asierneiradev committed Nov 25, 2022
1 parent 4a826d5 commit a1c6ff7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions component/models/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,9 @@ def work_on(self, model_name, **kwargs):
"""
self.ensure_one()
# Allow propagation of custom component registry via context
# TODO: maybe to be moved to `WorkContext.__init__`
components_registry = self.env.context.get("components_registry")
if components_registry:
kwargs["components_registry"] = components_registry
yield WorkContext(model_name=model_name, collection=self, **kwargs)
7 changes: 7 additions & 0 deletions component/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ def setUpComponent(cls):
# build the components of the current tested addon
current_addon = _get_addon_name(cls.__module__)
env["component.builder"].load_components(current_addon)
# share component registry everywhere
cls.env.context = dict(
cls.env.context, components_registry=cls._components_registry
)

# pylint: disable=W8106
def setUp(self):
Expand Down Expand Up @@ -201,6 +205,9 @@ def setUp(self):
# of the components. Here, we'll add components later in
# the components registry, but we don't mind for the tests.
self.comp_registry.ready = True
self.env.context = dict(
self.env.context, components_registry=self.comp_registry
)

def tearDown(self):
super().tearDown()
Expand Down

0 comments on commit a1c6ff7

Please sign in to comment.