summaryrefslogtreecommitdiff
path: root/odoo/addons/test_testing_utilities
diff options
context:
space:
mode:
authorwilliam <wan@odoo.com>2020-07-06 11:49:20 +0000
committerwilliam <wan@odoo.com>2020-07-10 14:18:12 +0000
commit048c7fef6716e7f459e9f88c10e03a1babf98fae (patch)
tree7625dad4f9e562aa6cb9f92b57e4dc4badd9b98c /odoo/addons/test_testing_utilities
parenta0f45bab76e7c424c56a255867842cc6df41458d (diff)
[IMP] base: _check_with_xsd from ir.attachment
Search the xsd files from in the database. To enable this option, the Environment should be passed to the optional `env` parameter. Both the XSD root and the XSD imported by the root and the recusrively imported files will be searched in the database. X-original-commit: 06a35f2e11230db81b8c21696d228097b31cf649
Diffstat (limited to 'odoo/addons/test_testing_utilities')
-rw-r--r--odoo/addons/test_testing_utilities/tests/__init__.py1
-rw-r--r--odoo/addons/test_testing_utilities/tests/test_lxml.py54
2 files changed, 55 insertions, 0 deletions
diff --git a/odoo/addons/test_testing_utilities/tests/__init__.py b/odoo/addons/test_testing_utilities/tests/__init__.py
index 7be78314304..7193c4e5f94 100644
--- a/odoo/addons/test_testing_utilities/tests/__init__.py
+++ b/odoo/addons/test_testing_utilities/tests/__init__.py
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from . import test_methods
+from . import test_lxml
from . import test_form_impl
diff --git a/odoo/addons/test_testing_utilities/tests/test_lxml.py b/odoo/addons/test_testing_utilities/tests/test_lxml.py
new file mode 100644
index 00000000000..fac6013bd67
--- /dev/null
+++ b/odoo/addons/test_testing_utilities/tests/test_lxml.py
@@ -0,0 +1,54 @@
+# -*- 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"""
+ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:etype="http://codespeak.net/lxml/test/external">
+ <xsd:import namespace="http://codespeak.net/lxml/test/external" schemaLocation="imported_schema.xsd"/>
+ <xsd:element name="a" type="etype:AType"/>
+ </xsd:schema>
+ """
+
+ incomplete_schema_int = b"""
+ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:etype="http://codespeak.net/lxml/test/external">
+ <xsd:import namespace="http://codespeak.net/lxml/test/external" schemaLocation="non_existing_schema.xsd"/>
+ <xsd:element name="a" type="etype:AType"/>
+ </xsd:schema>
+ """
+
+ imported_schema = b"""
+ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://codespeak.net/lxml/test/external">
+ <xsd:complexType name="AType">
+ <xsd:sequence><xsd:element name="b" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/></xsd:sequence>
+ </xsd:complexType>
+ </xsd:schema>
+ """
+
+ 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("<a><b></b></a>", 'resolver_schema_int.xsd', self.env)
+
+ with self.assertRaises(XMLSchemaError):
+ _check_with_xsd("<a><b></b></a>", 'incomplete_schema_int.xsd', self.env)
+
+ with self.assertRaises(FileNotFoundError):
+ _check_with_xsd("<a><b></b></a>", 'non_existing_schema.xsd', self.env)