def test_02_uninstall(self):
        """ Check a few things showing the module is uninstalled. """
        with environment() as env:
            module = env['ir.module.module'].search([('name', '=', MODULE)])
            assert len(module) == 1
            module.button_uninstall()
        Registry.new(common.get_db_name(), update_module=True)

        with environment() as env:
            self.assertNotIn('test_uninstall.model', env.registry)
            self.assertFalse(env['ir.model.data'].search([('module', '=',
                                                           MODULE)]))
            self.assertFalse(env['ir.model.fields'].search([('model', '=',
                                                             MODEL)]))
Beispiel #2
0
 def _update_registry(self):
     """ Update the registry after a modification on action rules. """
     if self.env.registry.ready and not self.env.context.get('import_file'):
         # for the sake of simplicity, simply force the registry to reload
         self._cr.commit()
         self.env.reset()
         registry = Registry.new(self._cr.dbname)
         registry.registry_invalidated = True
Beispiel #3
0
def preload_registries(dbnames):
    """ Preload a registries, possibly run a test file."""
    # TODO: move all config checks to args dont check tools.config here
    dbnames = dbnames or []
    rc = 0
    for dbname in dbnames:
        try:
            update_module = config['init'] or config['update']
            registry = Registry.new(dbname, update_module=update_module)

            # run test_file if provided
            if config['test_file']:
                test_file = config['test_file']
                _logger.info('loading test file %s', test_file)
                with eagle.api.Environment.manage():
                    if test_file.endswith('py'):
                        load_test_file_py(registry, test_file)

            # run post-install tests
            if config['test_enable']:
                t0 = time.time()
                t0_sql = eagle.sql_db.sql_counter
                module_names = (registry.updated_modules
                                if update_module else registry._init_modules)
                _logger.info("Starting post tests")
                with eagle.api.Environment.manage():
                    for module_name in module_names:
                        result = run_unit_tests(module_name,
                                                registry.db_name,
                                                position='post_install')
                        registry._assertion_report.record_result(result)
                _logger.info("All post-tested in %.2fs, %s queries",
                             time.time() - t0,
                             eagle.sql_db.sql_counter - t0_sql)

            if registry._assertion_report.failures:
                rc += 1
        except Exception:
            _logger.critical('Failed to initialize database `%s`.',
                             dbname,
                             exc_info=True)
            return -1
    return rc
Beispiel #4
0
    def __new__(cls, cr, uid, context, su=False):
        if uid == SUPERUSER_ID:
            su = True
        assert context is not None
        args = (cr, uid, context, su)

        # if env already exists, return it
        env, envs = None, cls.envs
        for env in envs:
            if env.args == args:
                return env

        # otherwise create environment, and add it in the set
        self = object.__new__(cls)
        args = (cr, uid, frozendict(context), su)
        self.cr, self.uid, self.context, self.su = self.args = args
        self.registry = Registry(cr.dbname)
        self.cache = envs.cache
        self._protected = envs.protected        # proxy to shared data structure
        self.all = envs
        envs.add(self)
        return self
Beispiel #5
0
    def __new__(cls, cr, uid, context):
        assert context is not None
        args = (cr, uid, context)

        # if env already exists, return it
        env, envs = None, cls.envs
        for env in envs:
            if env.args == args:
                return env

        # otherwise create environment, and add it in the set
        self = object.__new__(cls)
        self.cr, self.uid, self.context = self.args = (cr, uid,
                                                       frozendict(context))
        self.registry = Registry(cr.dbname)
        self.cache = envs.cache
        self._cache_key = (cr, uid)
        self._protected = StackMap()  # {field: ids, ...}
        self.dirty = defaultdict(set)  # {record: set(field_name), ...}
        self.all = envs
        envs.add(self)
        return self