Beispiel #1
0
 def _teardown_registry(class_or_instance):
     ComponentRegistryCase._teardown_registry(class_or_instance)
     http.controllers_per_module = class_or_instance._controllers_per_module
     db_name = get_db_name()
     _component_databases[db_name] = class_or_instance._original_components
     _rest_services_databases[
         db_name] = class_or_instance._original_services_registry
    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",
        }
Beispiel #3
0
    def setUp(self):
        super(TestEvent, self).setUp()
        ComponentRegistryCase._setup_registry(self)
        self._load_module_components('component_event')

        # get the collecter to notify the event
        # we don't mind about the collection and the model here,
        # the events we test are global
        env = mock.MagicMock()
        self.work = EventWorkContext(model_name='res.users', env=env,
                                     components_registry=self.comp_registry)
        self.collecter = self.comp_registry['base.event.collecter'](self.work)
Beispiel #4
0
 def tearDown(self):
     ComponentRegistryCase._teardown_registry(self)
     super(TestMapper, self).tearDown()
Beispiel #5
0
 def setUp(self):
     super(TestMapper, self).setUp()
     ComponentRegistryCase._setup_registry(self)
     self.comp_registry.load_components('connector')