Ejemplo n.º 1
0
    def _load_data(cr, module_name, idref, mode, kind):
        """

        kind: data, demo, test, init_xml, update_xml, demo_xml.

        noupdate is False, unless it is demo data or it is csv data in
        init mode.

        """
        for filename in package.data[kind]:
            log = logging.getLogger('init')
            log.info("module %s: loading %s", module_name, filename)
            _, ext = os.path.splitext(filename)
            pathname = os.path.join(module_name, filename)
            fp = tools.file_open(pathname)
            noupdate = False
            if kind in ('demo', 'demo_xml'):
                noupdate = True
            try:
                if ext == '.csv':
                    if kind in ('init', 'init_xml'):
                        noupdate = True
                    tools.convert_csv_import(cr, module_name, pathname, fp.read(), idref, mode, noupdate)
                elif ext == '.sql':
                    process_sql_file(cr, fp)
                elif ext == '.yml':
                    tools.convert_yaml_import(cr, module_name, fp, idref, mode, noupdate)
                else:
                    tools.convert_xml_import(cr, module_name, fp, idref, mode, noupdate, report)
            finally:
                fp.close()
Ejemplo n.º 2
0
    def _load_data(cr, module_name, idref, mode, kind):
        """

        kind: data, demo, test, init_xml, update_xml, demo_xml.

        noupdate is False, unless it is demo data or it is csv data in
        init mode.

        """
        for filename in package.data[kind]:
            _logger.info("module %s: loading %s", module_name, filename)
            _, ext = os.path.splitext(filename)
            pathname = os.path.join(module_name, filename)
            fp = tools.file_open(pathname)
            noupdate = False
            if kind in ('demo', 'demo_xml'):
                noupdate = True
            try:
                ext = ext.lower()
                if ext == '.csv':
                    if kind in ('init', 'init_xml'):
                        noupdate = True
                    tools.convert_csv_import(cr, module_name, pathname, fp.read(), idref, mode, noupdate)
                elif ext == '.sql':
                    process_sql_file(cr, fp)
                elif ext == '.yml':
                    tools.convert_yaml_import(cr, module_name, fp, kind, idref, mode, noupdate, report)
                elif ext == '.xml':
                    tools.convert_xml_import(cr, module_name, fp, idref, mode, noupdate, report)
                elif ext == '.js':
                    pass # .js files are valid but ignored here.
                else:
                    _logger.warning("Can't load unknown file type %s.", filename)
            finally:
                fp.close()
Ejemplo n.º 3
0
    def _load_data(cr, module_name, idref, mode, kind):
        """

        kind: data, demo, test, init_xml, update_xml, demo_xml.

        noupdate is False, unless it is demo data or it is csv data in
        init mode.

        """
        for filename in package.data[kind]:
            _logger.info("module %s: loading %s", module_name, filename)
            _, ext = os.path.splitext(filename)
            pathname = os.path.join(module_name, filename)
            fp = tools.file_open(pathname)
            noupdate = False
            if kind in ('demo', 'demo_xml'):
                noupdate = True
            try:
                ext = ext.lower()
                if ext == '.csv':
                    if kind in ('init', 'init_xml'):
                        noupdate = True
                    tools.convert_csv_import(cr, module_name, pathname, fp.read(), idref, mode, noupdate)
                elif ext == '.sql':
                    process_sql_file(cr, fp)
                elif ext == '.yml':
                    tools.convert_yaml_import(cr, module_name, fp, kind, idref, mode, noupdate, report)
                elif ext == '.xml':
                    tools.convert_xml_import(cr, module_name, fp, idref, mode, noupdate, report)
                elif ext == '.js':
                    pass # .js files are valid but ignored here.
                else:
                    _logger.warning("Can't load unknown file type %s.", filename)
            finally:
                fp.close()
Ejemplo n.º 4
0
 def test_reload_test(self):
     if tools.config.options['test_enable']:
         cr = self.cr
         module_info = modules.load_information_from_description_file(
             "l10n_pe_retest")
         for dat in module_info.get('depends', []):
             cr.commit()
             try:
                 mod_info = modules.load_information_from_description_file(
                     dat)
                 for test_module in mod_info.get('test', []):
                     if test_module in self.test_deprecate:
                         continue
                     pathname = os.path.join(dat, test_module)
                     fp = tools.file_open(pathname)
                     _logger.info(
                         "Try againt Test: {} of Module: {}".format(
                             test_module, dat))
                     try:
                         tools.convert_yaml_import(cr,
                                                   dat,
                                                   fp,
                                                   kind="test",
                                                   idref={},
                                                   mode="init")
                     except BaseException:
                         _logger.exception(
                             'module %s: an exception occurred in a test',
                             dat)
             finally:
                 if tools.config.options['test_commit']:
                     cr.commit()
                 else:
                     cr.rollback()
 def _import_file(self, cr, mode, f_obj):
     root, ext = os.path.splitext(f_obj.name)
     if ext == '.sql':
         self._sql_import(cr, f_obj)
     elif mode != 'pre-load' and ext == '.yml':
         tools.convert_yaml_import(cr, 'base', f_obj, 'upgrade')
     else:
         _logger.error('%s extension is not supported in upgrade %sing', ext, mode)
         pass
Ejemplo n.º 6
0
 def _import_file(self, cr, mode, f_obj):
     root, ext = os.path.splitext(f_obj.name)
     if ext == '.sql':
         self._sql_import(cr, f_obj)
     elif mode != 'pre-load' and ext == '.yml':
         tools.convert_yaml_import(cr, 'base', f_obj)
     else:
         _logger.error('%s extension is not supported in upgrade %sing', ext, mode)
         pass
Ejemplo n.º 7
0
    def test_purchase(self, cr, uid, ids, context=None):
        if context == None:
            context = {}
        assertion_obj = assertion_report.assertion_report()
        this = self.browse(cr, uid, ids)[0]
        fp_data = tools.file_open(os.path.join(
            'purchase_test_data_imp', 'test/purchase_order_test_data.xml'))
        fp_test = tools.file_open(os.path.join(
            'purchase_test_data_imp', 'test/purchase_order_product_can_be_purchased.yml'))
        try:
            cr.execute("SAVEPOINT test_yaml_purchase_savepoint")
            context.update({'uid': uid})
            tools.convert_xml_import(cr, 'purchase_test_data_imp', fp_data, {
            }, 'init', False, assertion_obj)
            tools.convert_yaml_import(cr, 'purchase_test_data_imp', fp_test, 'test', {
            }, 'init', False, assertion_obj, context=context)
        finally:
            if this.test_commit:
                cr.execute("RELEASE SAVEPOINT test_yaml_purchase_savepoint")
            else:
                cr.execute("ROLLBACK TO test_yaml_purchase_savepoint")

        fp_data.close()
        fp_test.close()

        tmp_path = tempfile.gettempdir()
        file_purchase_order_wrong = base64.encodestring(
            open(os.path.join(tmp_path, 'purchase_order_product_log.csv'), 'rb+').read())
        file_purchase_order_log = base64.encodestring(
            open(os.path.join(tmp_path, 'purchase_order_general_log.csv'), 'rb+').read())

        self.write(cr, uid, ids, {
            'yaml_file': file_purchase_order_wrong,
            'yaml_file_log': file_purchase_order_log,
            'filename_product': 'purchase_order_product_log.csv',
            'filename_log_general': 'purchase_order_general_log.csv',
        }, context=context)

        __, xml_id = self.pool.get('ir.model.data').get_object_reference(
            cr, uid, 'purchase_test_data_imp', 'view_wizard_purchase_test_data_result')

        return {
            'res_model': 'test.yaml.data.purchase',
            'view_type': 'form',
            'view_mode': 'form',
            'view_id': xml_id,
            'res_id': this.id,
            'context': context,
            'type': 'ir.actions.act_window',
            'target': 'new',
        }
Ejemplo n.º 8
0
 def _import_file(self, cr, mode, f_obj, module):
     root, ext = os.path.splitext(f_obj.name)
     if ext == '.sql':
         self._sql_import(cr, f_obj)
     elif mode != 'pre-load' and ext == '.yml':
         with api.Environment.manage():
             tools.convert_yaml_import(cr, module, f_obj, 'upgrade')
     elif mode != 'pre-load' and ext == '.csv':
         tools.convert_csv_import(cr, module, f_obj.name, f_obj.read(),
                                  'upgrade')
     elif mode != 'pre-load' and ext == '.xml':
         tools.convert_xml_import(cr, module, f_obj, 'upgrade')
     else:
         _logger.error('%s extension is not supported in upgrade %sing',
                       ext, mode)
         pass
Ejemplo n.º 9
0
    def _load_data(cr, module_name, idref, mode, kind):
        """

        kind: data, demo, test, init_xml, update_xml, demo_xml.

        noupdate is False, unless it is demo data or it is csv data in
        init mode.

        """

        skip_list = []
        ignore_xml_on_installed = package.data.get('ignore_xml_on_installed')
        if ignore_xml_on_installed:
            check_modules = ignore_xml_on_installed.keys()
            if check_modules:
                cr.execute(''' SELECT name FROM ir_module_module
                 WHERE name = ANY(ARRAY%s)
                 AND state in ('installed','to_upgrade')''' % check_modules)
                for installed_module, in cr.fetchall():
                    skip_list.extend(ignore_xml_on_installed[installed_module])

        for filename in package.data[kind]:
            _logger.info("module %s: loading %s", module_name, filename)
            _, ext = os.path.splitext(filename)
            pathname = os.path.join(module_name, filename)
            if filename in skip_list:
                continue
            fp = tools.file_open(pathname)
            noupdate = False
            if kind in ('demo', 'demo_xml'):
                noupdate = True
            try:
                if ext == '.csv':
                    if kind in ('init', 'init_xml'):
                        noupdate = True
                    tools.convert_csv_import(cr, module_name, pathname,
                                             fp.read(), idref, mode, noupdate)
                elif ext == '.sql':
                    process_sql_file(cr, fp)
                elif ext == '.yml':
                    tools.convert_yaml_import(cr, module_name, fp, idref, mode,
                                              noupdate)
                else:
                    tools.convert_xml_import(cr, module_name, fp, idref, mode,
                                             noupdate, report)
            finally:
                fp.close()
Ejemplo n.º 10
0
    def _load_data(cr, module_name, idref, mode, kind):
        """

        kind: data, demo, test, init_xml, update_xml, demo_xml.

        noupdate is False, unless it is demo data or it is csv data in
        init mode.

        """

        skip_list = []
        ignore_xml_on_installed = package.data.get('ignore_xml_on_installed')
        if ignore_xml_on_installed:
            check_modules = ignore_xml_on_installed.keys()
            if check_modules:
                cr.execute(''' SELECT name FROM ir_module_module
                 WHERE name = ANY(ARRAY%s)
                 AND state in ('installed','to_upgrade')''' % check_modules)
                for installed_module, in cr.fetchall():
                    skip_list.extend(ignore_xml_on_installed[installed_module])

        for filename in package.data[kind]:
            _logger.info("module %s: loading %s", module_name, filename)
            _, ext = os.path.splitext(filename)
            pathname = os.path.join(module_name, filename)
            if filename in skip_list:
                continue
            fp = tools.file_open(pathname)
            noupdate = False
            if kind in ('demo', 'demo_xml'):
                noupdate = True
            try:
                if ext == '.csv':
                    if kind in ('init', 'init_xml'):
                        noupdate = True
                    tools.convert_csv_import(cr, module_name, pathname, fp.read(), idref, mode, noupdate)
                elif ext == '.sql':
                    process_sql_file(cr, fp)
                elif ext == '.yml':
                    tools.convert_yaml_import(cr, module_name, fp, idref, mode, noupdate)
                else:
                    tools.convert_xml_import(cr, module_name, fp, idref, mode, noupdate, report)
            finally:
                fp.close()
Ejemplo n.º 11
0
def _run_test(cr, module, filename):
    _, ext = os.path.splitext(filename)
    pathname = os.path.join(module, filename)
    with tools.file_open(pathname) as fp:
        if ext == '.sql':
            if hasattr(tools, 'convert_sql_import'):
                tools.convert_sql_import(cr, fp)
            else:
                queries = fp.read().split(';')
                for query in queries:
                    new_query = ' '.join(query.split())
                    if new_query:
                        cr.execute(new_query)
        elif ext == '.csv':
            tools.convert_csv_import(cr, module, pathname, fp.read(), idref=None, mode='update', noupdate=False)
        elif ext == '.yml':
            if LooseVersion(release.major_version) >= LooseVersion('7.0'):
                tools.convert_yaml_import(cr, module, fp, kind='test', idref=None, mode='update', noupdate=False)
            else:
                tools.convert_yaml_import(cr, module, fp, idref=None, mode='update', noupdate=False)
        elif ext == '.xml':
            tools.convert_xml_import(cr, module, fp, idref=None, mode='update', noupdate=False)
Ejemplo n.º 12
0
 def _load_data(self,
                module_name,
                kind='demo',
                mode='update',
                noupdate=False):
     cr = self._cr
     info = load_information_from_description_file(module_name)
     for filename in info.get(kind, []):
         _logger.info('loading %s/%s...' % (module_name, filename))
         _, ext = os.path.splitext(filename)
         pathname = os.path.join(module_name, filename)
         with tools.file_open(pathname) as fp:
             if ext == '.sql':
                 tools.convert_sql_import(cr, fp)
             elif ext == '.csv':
                 tools.convert_csv_import(cr,
                                          module_name,
                                          pathname,
                                          fp.read(),
                                          idref=None,
                                          mode=mode,
                                          noupdate=noupdate)
             elif ext == '.yml':
                 tools.convert_yaml_import(cr,
                                           module_name,
                                           fp,
                                           kind=kind,
                                           idref=None,
                                           mode=mode,
                                           noupdate=noupdate)
             elif ext == '.xml':
                 tools.convert_xml_import(cr,
                                          module_name,
                                          fp,
                                          idref=None,
                                          mode=mode,
                                          noupdate=noupdate)
     return True
Ejemplo n.º 13
0
    def load_data(self, cr, uid, load=[]):
        """
        Load data defined on test case `data` attribute
        """
        module = self.get_current_instance_module()

        for file in load:

            if not isinstance(file, dict):
                data = {'module': module, 'file': file}
            else:
                data = file

            if not [name for name in ['module', 'file'] if name in data]:
                raise Exception('Test case data entry is not valid: %s', data)

            if data.get('uid', False):
                data.update({'uid': self.full_ref(data['uid'])})
            else:
                data.update({'uid': SUPERUSER_ID})
            self.log.debug("module %s: loading %s (User ID: %s)",
                           data['module'], data['file'], data['uid'])

            _, ext = os.path.splitext(data['file'])
            pathname = os.path.join(data['module'], data['file'])
            fp = tools.file_open(pathname)

            noupdate = False

            # fake these incomprehensible params...
            idref = {}
            mode = 'update'
            kind = 'data'
            report = None

            # copy from server/openerp/modules/loading.py:66...
            def process_sql_file(cr, fp):
                queries = fp.read().split(';')
                for query in queries:
                    new_query = ' '.join(query.split())
                    if new_query:
                        cr.execute(new_query)

            try:
                ext = ext.lower()
                if ext == '.csv':
                    # TODO: Migrate the feature below to v8
                    # allow to specify a user when importing data. By default,
                    # use the superuser.
                    tools.convert_csv_import(cr, module, pathname, fp.read(),
                                             idref, mode, noupdate)
                elif ext == '.sql':
                    process_sql_file(cr, fp)
                elif ext == '.yml':
                    tools.convert_yaml_import(cr, module, fp, kind, idref,
                                              mode, noupdate, report)
                elif ext == '.xml':
                    tools.convert_xml_import(cr, module, fp, idref, mode,
                                             noupdate, report)
                else:
                    self.log.warning("Can't load unknown file type %s.",
                                     data['file'])
            finally:
                fp.close()