Ejemplo n.º 1
0
Archivo: test_html.py Proyecto: 0k/odoo
    def test_image(self):
        column = self.get_column('binary')
        converter = self.registry('ir.qweb.field.image')

        with open(os.path.join(directory, 'test_vectors', 'image'), 'rb') as f:
            content = f.read()

        encoded_content = content.encode('base64')
        value = e(converter.value_to_html(
            self.cr, self.uid, encoded_content, column))
        self.assertEqual(
            value, '<img src="data:image/jpeg;base64,%s">' % (
                encoded_content
            ))

        with open(os.path.join(directory, 'test_vectors', 'pdf'), 'rb') as f:
            content = f.read()

        with self.assertRaises(ValueError):
            e(converter.value_to_html(
                self.cr, self.uid, 'binary', content.encode('base64'), column))

        with open(os.path.join(directory, 'test_vectors', 'pptx'), 'rb') as f:
            content = f.read()

        with self.assertRaises(ValueError):
            e(converter.value_to_html(
                self.cr, self.uid, 'binary', content.encode('base64'), column))
Ejemplo n.º 2
0
    def test_image(self):
        field = self.get_field('binary')
        converter = self.registry('ir.qweb.field.image')

        with open(os.path.join(directory, 'test_vectors', 'image'), 'rb') as f:
            content = f.read()

        encoded_content = content.encode('base64')
        value = e(
            converter.value_to_html(self.cr, self.uid, encoded_content, field))
        self.assertEqual(
            value, '<img src="data:image/jpeg;base64,%s">' % (encoded_content))

        with open(os.path.join(directory, 'test_vectors', 'pdf'), 'rb') as f:
            content = f.read()

        with self.assertRaises(ValueError):
            e(
                converter.value_to_html(self.cr, self.uid, 'binary',
                                        content.encode('base64'), field))

        with open(os.path.join(directory, 'test_vectors', 'pptx'), 'rb') as f:
            content = f.read()

        with self.assertRaises(ValueError):
            e(
                converter.value_to_html(self.cr, self.uid, 'binary',
                                        content.encode('base64'), field))
Ejemplo n.º 3
0
        def converter(record):
            column = self.get_column('many2one')
            model = self.registry('ir.qweb.field.many2one')

            return e(
                model.record_to_html(self.cr, self.uid, 'many2one', record,
                                     column))
Ejemplo n.º 4
0
    def test_selection(self):
        converter = self.get_converter('selection')
        value = converter(4)
        self.assertEqual(value, e(u"réponse <D>"))

        converter = self.get_converter('selection_str')
        value = converter('C')
        self.assertEqual(value, u"Qu'est-ce qu'il fout ce maudit pancake, tabernacle ?")
Ejemplo n.º 5
0
    def test_selection(self):
        converter = self.get_converter('selection')
        value = converter(4)
        self.assertEqual(value, e(u"réponse <D>"))

        converter = self.get_converter('selection_str')
        value = converter('C')
        self.assertEqual(
            value, u"Qu'est-ce qu'il fout ce maudit pancake, tabernacle ?")
Ejemplo n.º 6
0
    def test_selection(self):
        [record] = self.Model.browse(
            self.cr, self.uid, [self.Model.create(self.cr, self.uid, {"selection": 4, "selection_str": "C"})]
        )

        converter = self.registry("ir.qweb.field.selection")

        field_name = "selection"
        value = converter.record_to_html(self.cr, self.uid, record, field_name, {})
        self.assertEqual(value, e(u"réponse <D>"))

        field_name = "selection_str"
        value = converter.record_to_html(self.cr, self.uid, record, field_name, {})
        self.assertEqual(value, u"Qu'est-ce qu'il fout ce maudit pancake, tabernacle ?")
Ejemplo n.º 7
0
Archivo: test_html.py Proyecto: 0k/odoo
    def get_converter(self, name, type=None):
        column = self.get_column(name)

        for postfix in type, column._type, '':
            fs = ['ir', 'qweb', 'field']
            if postfix is None: continue
            if postfix: fs.append(postfix)

            try:
                model = self.registry('.'.join(fs))
                break
            except KeyError: pass

        return lambda value, options=None, context=None: e(model.value_to_html(
            self.cr, self.uid, value, column, options=options, context=context))
Ejemplo n.º 8
0
    def get_converter(self, name, type=None):
        field = self.get_field(name)

        for postfix in type, field.type, '':
            fs = ['ir', 'qweb', 'field']
            if postfix is None: continue
            if postfix: fs.append(postfix)

            try:
                model = self.registry('.'.join(fs))
                break
            except KeyError: pass

        return lambda value, options=None, context=None: e(model.value_to_html(
            self.cr, self.uid, value, field, options=options, context=context))
Ejemplo n.º 9
0
    def test_selection(self):
        [record] = self.Model.browse(self.cr, self.uid, [
            self.Model.create(self.cr, self.uid, {
                'selection': 4,
                'selection_str': 'C',
            })
        ])

        converter = self.registry('ir.qweb.field.selection')

        field_name = 'selection'
        value = converter.record_to_html(self.cr, self.uid, record, field_name,
                                         {})
        self.assertEqual(value, e(u"réponse <D>"))

        field_name = 'selection_str'
        value = converter.record_to_html(self.cr, self.uid, record, field_name,
                                         {})
        self.assertEqual(
            value, u"Qu'est-ce qu'il fout ce maudit pancake, tabernacle ?")
Ejemplo n.º 10
0
Archivo: test_html.py Proyecto: 0k/odoo
        def converter(record):
            column = self.get_column('many2one')
            model = self.registry('ir.qweb.field.many2one')

            return e(model.record_to_html(
                self.cr, self.uid, 'many2one', record, column))
Ejemplo n.º 11
0
 def converter(record):
     model = self.registry('ir.qweb.field.many2one')
     return e(
         model.record_to_html(self.cr, self.uid, 'many2one', record))
Ejemplo n.º 12
0
 def converter(record):
     model = self.registry('ir.qweb.field.many2one')
     return e(model.record_to_html(self.cr, self.uid, 'many2one', record))