# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests import common
from odoo.tools.xml_utils import _check_with_xsd
import base64
from lxml.etree import XMLSchemaError
class TestLXML(common.TransactionCase):
def test_lxml_import_from_filestore(self):
resolver_schema_int = b"""
"""
incomplete_schema_int = b"""
"""
imported_schema = b"""
"""
self.env['ir.attachment'].create([{
'datas': base64.b64encode(resolver_schema_int),
'name': 'resolver_schema_int.xsd'
}, {
'datas': base64.b64encode(incomplete_schema_int),
'name': 'incomplete_schema_int.xsd'
}, {
'datas': base64.b64encode(imported_schema),
'name': 'imported_schema.xsd'
}])
_check_with_xsd("", 'resolver_schema_int.xsd', self.env)
with self.assertRaises(XMLSchemaError):
_check_with_xsd("", 'incomplete_schema_int.xsd', self.env)
with self.assertRaises(FileNotFoundError):
_check_with_xsd("", 'non_existing_schema.xsd', self.env)