Commit 55ff0956 authored by Jérome Perrin's avatar Jérome Perrin

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 7c24c322
<?xml version="1.0" encoding="UTF-8"?> <?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> <exercice>
<DateCloture tal:content="python: options['at_date'].strftime('%Y-%m-%d')">20141231</DateCloture> <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> <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): ...@@ -90,6 +90,25 @@ class TestAccounting_l10n_fr(AccountingTestCase):
user = uf.getUser(self.username).__of__(uf) user = uf.getUser(self.username).__of__(uf)
newSecurityManager(None, user) 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): def test_FEC(self):
account_module = self.portal.account_module account_module = self.portal.account_module
self._makeOne( self._makeOne(
...@@ -145,14 +164,8 @@ class TestAccounting_l10n_fr(AccountingTestCase): ...@@ -145,14 +164,8 @@ class TestAccounting_l10n_fr(AccountingTestCase):
else: else:
self.fail("Attachment not found") self.fail("Attachment not found")
# validate against official schema tree = etree.fromstring(fec_xml)
import Products.ERP5.tests self.validateFECXML(tree)
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))
debit_list = tree.xpath("//Debit") debit_list = tree.xpath("//Debit")
self.assertEqual(6, len(debit_list)) self.assertEqual(6, len(debit_list))
...@@ -238,14 +251,8 @@ class TestAccounting_l10n_fr(AccountingTestCase): ...@@ -238,14 +251,8 @@ class TestAccounting_l10n_fr(AccountingTestCase):
else: else:
self.fail("Attachment not found") self.fail("Attachment not found")
# validate against official schema tree = etree.fromstring(fec_xml)
import Products.ERP5.tests self.validateFECXML(tree)
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))
return 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