New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial test #21

Merged
merged 6 commits into from Jun 7, 2018
Jump to file or symbol
Failed to load files and symbols.
+126 −1
Diff settings

Always

Just for now

Viewing a subset of changes. View all

Adds write_xml() test

  • Loading branch information...
duskybomb committed May 28, 2018
commit 2f3ae4446cfb1b2603055e3956fb6936591d46c4
@@ -0,0 +1,53 @@
<rsm:CrossIndustryInvoice xmlns:qdt="urn:un:unece:uncefact:data:standard:QualifiedDataType:100" xmlns:ram="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100" xmlns:rsm="urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100" xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<rsm:ExchangedDocumentContext>
<ram:BusinessProcessSpecifiedDocumentContextParameter>
<ram:ID>A1</ram:ID>
</ram:BusinessProcessSpecifiedDocumentContextParameter>
<ram:GuidelineSpecifiedDocumentContextParameter>
<ram:ID>urn:factur-x.eu:1p0:minimum</ram:ID>
</ram:GuidelineSpecifiedDocumentContextParameter>
</rsm:ExchangedDocumentContext>
<rsm:ExchangedDocument>
<ram:ID>2017-TEST-04</ram:ID>
<ram:TypeCode>380</ram:TypeCode>
<ram:IssueDateTime>
<udt:DateTimeString format="102">20171031</udt:DateTimeString>
</ram:IssueDateTime>
</rsm:ExchangedDocument>
<rsm:SupplyChainTradeTransaction>
<ram:ApplicableHeaderTradeAgreement>
<ram:BuyerReference>CodeSERVICE A</ram:BuyerReference>
<ram:SellerTradeParty>
<ram:Name>FOURNISSEUR F</ram:Name>
<ram:SpecifiedLegalOrganization>
<ram:ID schemeID="0002">99988877900017</ram:ID>
</ram:SpecifiedLegalOrganization>
<ram:PostalTradeAddress>
<ram:CountryID>FR</ram:CountryID>
</ram:PostalTradeAddress>
<ram:SpecifiedTaxRegistration>
<ram:ID schemeID="VA">FR34999888779</ram:ID>
</ram:SpecifiedTaxRegistration>
</ram:SellerTradeParty>
<ram:BuyerTradeParty>
<ram:Name>CLIENT 1</ram:Name>
<ram:SpecifiedLegalOrganization>
<ram:ID schemeID="0002">77788899100018</ram:ID>
</ram:SpecifiedLegalOrganization>
</ram:BuyerTradeParty>
<ram:BuyerOrderReferencedDocument>
<ram:IssuerAssignedID>CDE234</ram:IssuerAssignedID>
</ram:BuyerOrderReferencedDocument>
</ram:ApplicableHeaderTradeAgreement>
<ram:ApplicableHeaderTradeDelivery/>
<ram:ApplicableHeaderTradeSettlement>
<ram:InvoiceCurrencyCode>EUR</ram:InvoiceCurrencyCode>
<ram:SpecifiedTradeSettlementHeaderMonetarySummation>
<ram:TaxBasisTotalAmount currencyID="EUR">15976.87</ram:TaxBasisTotalAmount>
<ram:TaxTotalAmount currencyID="EUR">3195.37</ram:TaxTotalAmount>
<ram:GrandTotalAmount currencyID="EUR">19172.24</ram:GrandTotalAmount>
<ram:DuePayableAmount currencyID="EUR">19172.24</ram:DuePayableAmount>
</ram:SpecifiedTradeSettlementHeaderMonetarySummation>
</ram:ApplicableHeaderTradeSettlement>
</rsm:SupplyChainTradeTransaction>
</rsm:CrossIndustryInvoice>
@@ -1,6 +1,59 @@
import os
import unittest
from facturx.facturx import *
import xml.etree.ElementTree as ET
class XmlTree:

This comment has been minimized.

@m3nu

m3nu Jun 3, 2018

Collaborator
  • You can't plagiarize a whole code block without license and credit.
  • If a helper class is needed, it can't be in the test module.
@m3nu

m3nu Jun 3, 2018

Collaborator
  • You can't plagiarize a whole code block without license and credit.
  • If a helper class is needed, it can't be in the test module.
def __init__(self):
pass
@staticmethod
def convert_string_to_tree( xmlString):
return ET.fromstring(xmlString)
def xml_compare(self, x1, x2):
if x1.tag != x2.tag:
# print('Tags do not match: %s and %s' % (x1.tag, x2.tag))
return False
for name, value in x1.attrib.items():
if x2.attrib.get(name) != value:
# print('Attributes do not match: %s=%r, %s=%r'
# % (name, value, name, x2.attrib.get(name)))
return False
for name in x2.attrib.keys():
if name not in x1.attrib:
# print('x2 has an attribute x1 is missing: %s'
# % name)
return False
if not self.text_compare(x1.text, x2.text):
# print('text: %r != %r' % (x1.text, x2.text))
return False
if not self.text_compare(x1.tail, x2.tail):
# print('tail: %r != %r' % (x1.tail, x2.tail))
return False
cl1 = x1.getchildren()
cl2 = x2.getchildren()
if len(cl1) != len(cl2):
# print('children length differs, %i != %i'
# % (len(cl1), len(cl2)))
return False
i = 0
for c1, c2 in zip(cl1, cl2):
i += 1
if not self.xml_compare(c1, c2):
# print('children %i do not match: %s'
# % (i, c1.tag))
return False
return True
def text_compare(self, t1, t2):
if not t1 and not t2:
return True
if t1 == '*' or t2 == '*':
return True
return (t1 or '').strip() == (t2 or '').strip()
class TestReading(unittest.TestCase):
@@ -54,7 +107,26 @@ def test_write_pdf(self):
def test_write_xml(self):
pass
compare_file_dir = os.path.join(os.path.dirname(__file__), 'compare')
expected_file_path = os.path.join(compare_file_dir, 'no_embedded_data.xml')
test_file_path = os.path.join(compare_file_dir, 'test.xml')
factx = FacturX(self.find_file('no_embedded_data.pdf'))
factx.write_xml(test_file_path)
self.assertTrue(os.path.isfile(test_file_path))
with open(expected_file_path, 'r') as expected_file, open(test_file_path, 'r') as test_file:
expected_file_tree = XmlTree.convert_string_to_tree(expected_file.read())
test_file_tree = XmlTree.convert_string_to_tree(test_file.read())
comparator = XmlTree()
if comparator.xml_compare(expected_file_tree, test_file_tree):
self.assertTrue(True)
else:
self.assertTrue(False, "Files don't match")
os.remove(test_file_path)
def main():
ProTip! Use n and p to navigate between commits in a pull request.