Exemple #1
0
 def _build_services(self, *classes):
     self._build_components(*classes)
     with new_rollbacked_env() as env:
         RestServiceRegistration = env["rest.service.registration"]
         current_addon = _get_addon_name(self.__module__)
         RestServiceRegistration.load_services(current_addon, self._service_registry)
         RestServiceRegistration._build_controllers_routes(self._service_registry)
Exemple #2
0
    def _test_exception(self, test_type, wrapping_exc, exc_name, severity):
        log_model = self.env["rest.log"].sudo()
        initial_entries = log_model.search([])
        entry_url_from_exc = None
        with self._get_mocked_request():
            try:
                self.service.dispatch("fail", test_type)
            except Exception as err:
                # Not using `assertRaises` to inspect the exception directly
                self.assertTrue(isinstance(err, wrapping_exc))
                self.assertEqual(
                    self.service._get_exception_message(err), "Failed as you wanted!"
                )
                entry_url_from_exc = err.rest_json_info["log_entry_url"]

        with new_rollbacked_env() as env:
            log_model = env["rest.log"].sudo()
            entry = log_model.search([]) - initial_entries
            expected = {
                "collection": self.service._collection,
                "state": "failed",
                "result": "null",
                "exception_name": exc_name,
                "exception_message": "Failed as you wanted!",
                "severity": severity,
            }
            self.assertRecordValues(entry, [expected])
            self.assertEqual(entry_url_from_exc, self.service._get_log_entry_url(entry))
    def _setup_registry(class_or_instance):
        ComponentRegistryCase._setup_registry(class_or_instance)

        class_or_instance._service_registry = RestServicesRegistry()
        # take a copy of registered controllers
        controllers = http.controllers_per_module
        http.controllers_per_module = controllers

        class_or_instance._controllers_per_module = copy.deepcopy(
            http.controllers_per_module)
        class_or_instance._original_addon_rest_controllers_per_module = copy.deepcopy(
            _rest_controllers_per_module[_get_addon_name(
                class_or_instance.__module__)])
        db_name = get_db_name()

        # makes the test component registry available for the db name
        _component_databases[db_name] = class_or_instance.comp_registry

        # makes the test service registry available for the db name
        class_or_instance._original_services_registry = _rest_services_databases.get(
            db_name, {})
        _rest_services_databases[db_name] = class_or_instance._service_registry

        # build the services and controller of every installed addons
        # but the current addon (when running with pytest/nosetest, we
        # simulate the --test-enable behavior by excluding the current addon
        # which is in 'to install' / 'to upgrade' with --test-enable).
        current_addon = _get_addon_name(class_or_instance.__module__)

        with new_rollbacked_env() as env:
            RestServiceRegistration = env["rest.service.registration"]
            RestServiceRegistration.build_registry(
                class_or_instance._service_registry,
                states=("installed", ),
                exclude_addons=[current_addon],
            )
            RestServiceRegistration._build_controllers_routes(
                class_or_instance._service_registry)

        # register our components
        class_or_instance.comp_registry.load_components("base_rest")

        # Define a base test controller here to avoid to have this controller
        # registered outside tests
        class_or_instance._collection_name = "base.rest.test"

        BaseTestController = class_or_instance._get_test_controller(
            class_or_instance)

        class_or_instance._BaseTestController = BaseTestController
        class_or_instance._controller_route_method_names = {
            "my_controller_route_without",
            "my_controller_route_with",
            "my_controller_route_without_auth_2",
        }
Exemple #4
0
 def setUpRegistry(cls):
     with new_rollbacked_env() as env:
         service_registration = env['rest.service.registration']
         # build the registry of every installed addons
         services_registry = service_registration._init_global_registry()
         cls._services_registry = services_registry
         # ensure that we load only the services of the 'installed'
         # modules, not 'to install', which means we load only the
         # dependencies of the tested addons, not the siblings or
         # children addons
         service_registration.build_registry(services_registry,
                                             states=('installed', ))
         # build the services of the current tested addon
         current_addon = _get_addon_name(cls.__module__)
         env['rest.service.registration'].load_services(
             current_addon, services_registry)