From a1c6ff7d47a160cff611634406a9b6e206dd47bb Mon Sep 17 00:00:00 2001 From: Simone Orsi Date: Wed, 4 Nov 2020 15:39:37 +0100 Subject: [PATCH] component: allow propagation of custom registry --- component/models/collection.py | 5 +++++ component/tests/common.py | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/component/models/collection.py b/component/models/collection.py index a1e93a09d..e9816354e 100644 --- a/component/models/collection.py +++ b/component/models/collection.py @@ -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) diff --git a/component/tests/common.py b/component/tests/common.py index b205f0c94..575cd33e3 100644 --- a/component/tests/common.py +++ b/component/tests/common.py @@ -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): @@ -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()