diff --git a/base_rest/models/rest_service_registration.py b/base_rest/models/rest_service_registration.py index 6ccc829ea..3f34971eb 100644 --- a/base_rest/models/rest_service_registration.py +++ b/base_rest/models/rest_service_registration.py @@ -90,29 +90,16 @@ def _build_controller(self, service, controller_def): # generate an addon name used to register our new controller for # the current database - addon_name = "{}_{}_{}".format( + addon_name = base_controller_cls._module + identifier = "{}_{}_{}".format( self.env.cr.dbname, service._collection.replace(".", "_"), service._usage.replace(".", "_"), ) + base_controller_cls._identifier = identifier # put our new controller into the new addon module ctrl_cls.__module__ = "odoo.addons.{}".format(addon_name) - # instruct the registry that our fake addon is part of the loaded - # modules - # TODO: causes - # Traceback (most recent call last): - # File "/home/odoo/odoo/service/server.py", line 1310, in preload_registries - # post_install_suite = loader.make_suite(module_names, 'post_install') - # File "/home/odoo/odoo/tests/loader.py", line 58, in make_suite - # return OdooSuite(sorted(tests, key=lambda t: t.test_sequence)) - # File "/home/odoo/odoo/tests/loader.py", line 54, in - # for m in get_test_modules(module_name) - # File "/home/odoo/odoo/tests/loader.py", line 22, in get_test_modules - # results = _get_tests_modules(importlib.util.find_spec(f'odoo.addons.{module}')) - # File "/home/odoo/odoo/tests/loader.py", line 31, in _get_tests_modules - # spec = importlib.util.find_spec('.tests', mod.name) - # AttributeError: 'NoneType' object has no attribute 'name' self.env.registry._init_modules.add(addon_name) # register our conroller into the list of available controllers diff --git a/base_rest/tests/common.py b/base_rest/tests/common.py index 751d755c5..4d7e9f5fb 100644 --- a/base_rest/tests/common.py +++ b/base_rest/tests/common.py @@ -57,9 +57,6 @@ class RestServiceRegistryCase(ComponentRegistryCase): # pylint: disable=W8106 @staticmethod def _setup_registry(class_or_instance): - class_or_instance._registry_init_modules = set( - class_or_instance.env.registry._init_modules - ) ComponentRegistryCase._setup_registry(class_or_instance) class_or_instance._service_registry = RestServicesRegistry() @@ -143,9 +140,6 @@ def my_controller_route_without_auth_2(self): @staticmethod def _teardown_registry(class_or_instance): - class_or_instance.env.registry._init_modules = ( - class_or_instance._registry_init_modules - ) ComponentRegistryCase._teardown_registry(class_or_instance) http.Controller.children_classes = ( class_or_instance._controller_children_classes @@ -174,16 +168,20 @@ def _build_services(class_or_instance, *classes): ) @staticmethod - def _get_controller_for(service): - addon_name = "{}_{}_{}".format( + def _get_controller_for(service, addon="base_rest"): + identifier = "{}_{}_{}".format( get_db_name(), service._collection.replace(".", "_"), service._usage.replace(".", "_"), ) - controllers = http.Controller.children_classes.get(addon_name, []) + controllers = [ + controller + for controller in http.Controller.children_classes.get(addon, []) + if getattr(controller, "_identifier", None) == identifier + ] if not controllers: return - return controllers[0] + return controllers[-1] @staticmethod def _get_controller_route_methods(controller): diff --git a/base_rest_demo/tests/test_controller.py b/base_rest_demo/tests/test_controller.py index cde51d550..678e52618 100644 --- a/base_rest_demo/tests/test_controller.py +++ b/base_rest_demo/tests/test_controller.py @@ -18,7 +18,6 @@ def test_controller_registry(self): # at the end of the start process, our tow controllers must into the # controller registered controllers = Controller.children_classes.get("base_rest_demo", []) - self.assertEqual(len(controllers), 4) self.assertIn( BaseRestDemoPrivateApiController,