Commit 169d1fd6 authored by Jérome Perrin's avatar Jérome Perrin Committed by Kazuhiko Shiozaki

accounting_l10n_fr: set xsi:noNamespaceSchemaLocation for "Test Compta Demat"

The test software from
https://www.economie.gouv.fr/dgfip/outil-test-des-fichiers-des-ecritures-comptables-fec
only validates if the XSD is referenced with xsi:noNamespaceSchemaLocation
parent 683ddedb
<?xml version="1.0" encoding="UTF-8"?>
<comptabilite xmlns:tal="http://xml.zope.org/namespaces/tal">
<comptabilite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="formatA47A-I-VII-1.xsd" xmlns:tal="http://xml.zope.org/namespaces/tal">
<exercice>
<DateCloture tal:content="python: options['at_date'].strftime('%Y-%m-%d')">20141231</DateCloture>
<tal:block tal:repeat="result options/result_list"><tal:block tal:replace="structure python: result.detail.decode('zlib')"/></tal:block>
......
......@@ -90,6 +90,25 @@ class TestAccounting_l10n_fr(AccountingTestCase):
user = uf.getUser(self.username).__of__(uf)
newSecurityManager(None, user)
def validateFECXML(self, tree):
# this "xsi:noNamespaceSchemaLocation" is used by xerces parser from
# https://github.com/DGFiP/Test-Compta-Demat/
noNamespaceSchemaLocation, = tree.xpath(
'./@xsi:noNamespaceSchemaLocation',
namespaces={'xsi': 'http://www.w3.org/2001/XMLSchema-instance'})
import Products.ERP5.tests
with open(os.path.join(
os.path.dirname(Products.ERP5.tests.__file__),
'test_data',
noNamespaceSchemaLocation,
)) as f:
xmlschema_doc = etree.parse(f)
xmlschema = etree.XMLSchema(xmlschema_doc)
self.assertFalse(xmlschema.validate(etree.fromstring('<invalide/>')))
xmlschema.assertValid(tree)
def test_FEC(self):
account_module = self.portal.account_module
self._makeOne(
......@@ -145,14 +164,8 @@ class TestAccounting_l10n_fr(AccountingTestCase):
else:
self.fail("Attachment not found")
# validate against official schema
import Products.ERP5.tests
schema = etree.XMLSchema(etree.XML(open(os.path.join(
os.path.dirname(Products.ERP5.tests.__file__), 'test_data',
'formatA47A-I-VII-1.xsd')).read()))
# this raise if invalid
tree = etree.fromstring(fec_xml, etree.XMLParser(schema=schema))
tree = etree.fromstring(fec_xml)
self.validateFECXML(tree)
debit_list = tree.xpath("//Debit")
self.assertEqual(6, len(debit_list))
......@@ -238,14 +251,8 @@ class TestAccounting_l10n_fr(AccountingTestCase):
else:
self.fail("Attachment not found")
# validate against official schema
import Products.ERP5.tests
schema = etree.XMLSchema(etree.XML(open(os.path.join(
os.path.dirname(Products.ERP5.tests.__file__), 'test_data',
'formatA47A-I-VII-1.xsd')).read()))
# this raise if invalid
tree = etree.fromstring(fec_xml, etree.XMLParser(schema=schema))
tree = etree.fromstring(fec_xml)
self.validateFECXML(tree)
return tree
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment