Permalink
Browse files

[FIX] Little syntax error on template.

[TEST] Added test to documenttion process.
[FIX] Adding the links to sphinx doc in order to explain how do we expect to document the methods.
  • Loading branch information...
nhomar committed Feb 11, 2016
1 parent 8e451c8 commit 82a668a1f9d5e7e80b66fb3b11fffdaf60661fcf
Showing with 83 additions and 21 deletions.
  1. +4 −2 CONTRIBUTING.rst
  2. +40 −11 cfdilib/cfdilib.py
  3. +2 −2 cfdilib/templates/cfdv32.xml
  4. +37 −6 tests/test_cfdilib.py
@@ -39,7 +39,7 @@ Write Documentation
~~~~~~~~~~~~~~~~~~~
Mexico CFDI Lib could always use more documentation, whether as part of the
official Mexico CFDI Lib docs, in docstrings, or even on the web in blog posts,
official Mexico CFDI Lib docs, in `docstring`_, or even on the web in blog posts,
articles, and such.
Submit Feedback
@@ -99,7 +99,7 @@ Before you submit a pull request, check that it meets these guidelines:
1. The pull request should include tests.
2. If the pull request adds functionality, the docs should be updated. Put
your new functionality into a function with a docstring, and add the
your new functionality into a function with a `docstring`_, and add the
feature to the list in README.rst.
3. The pull request should work for Python 2.6, 2.7, 3.3, 3.4 and 3.5, and for PyPy. Check
https://travis-ci.org/vauxoo/cfdilib/pull_requests
@@ -111,3 +111,5 @@ Tips
To run a subset of tests::
$ python -m unittest tests.test_cfdilib
.. _docstring: http://www.sphinx-doc.org/en/stable/domains.html#signatures
@@ -18,7 +18,6 @@ def __init__(self, adict):
if isinstance(v, dict):
self.__dict__[k] = Struct(v)
class BaseInvoice:
"""Meta model for an invoice, this is the one that will be used To simplify
the conversion.
@@ -54,8 +53,12 @@ def set_template(self, template_fname):
return env.get_template(template_fname)
def validate(self, schema_str, xml_valid):
"""Files path, when any doubt why a path and not a string.
`http://lxml.de/FAQ.html#why-can-t-lxml-parse-my-xml-from-unicode-strings`
"""Compare the valid information on an xml from given schema.
:param str schema_str: content string from schema file.
:param str xml_valid: content string from xml file.
:returns: If it is Valid or Not.
:rtype: bool
"""
schema_root = etree.XML(schema_str)
schema = etree.XMLSchema(schema_root)
@@ -70,15 +73,38 @@ def validate(self, schema_str, xml_valid):
self.ups = ups
return False
def get_documentation(self, attribute_name, schema_str=None):
'''http://effbot.org/zone/element-namespaces.htm
TODO: This method should return an schema specific documentation
given an element parsing or getting the Clark's Notation from
the message error on validate method.
I dedicate 6 Hours to this and I did not find a correct way to do this.
I will finish other stuff but PLIZ finish this.
def get_element_from_clark(self, element):
'''**Helper method:** Given a Clark's Notation `{url:schema}Element` element, return the valid xpath on your
xsd file, frequently it is not necesary overwrite this method but different xsd from
different sourcs can have different logic which I do not know now, then simply take this
as an example and set the correct xpath conversion in your project.
:param str element: Element string following the Clark's Notation'''
element = element.split('}')[-1]
xpath_path = '//xs:element[@name="{element}"]/xs:annotation/xs:documentation'.format(element=element) # noqa
return xpath_path
def get_documentation(self, element, namespace=None, schema_str=None):
'''**Helper method:** should return an schema specific documentation
given an element parsing or getting the `Clark's Notation`_
`{url:schema}Element` from the message error on validate method.
:param str element: Element string following the Clark's Notation
:param dict namespace: Element string following the Clark's Notation
:returns: The documentation text if exists
:rtype: unicode
.. _`Clark's Notation`: http://effbot.org/zone/element-namespaces.htm
'''
return True
if namespace is None:
namespace = {'xs': 'http://www.w3.org/2001/XMLSchema'}
schema_root = etree.parse(StringIO(self.schema))
document = schema_root.xpath(self.get_element_from_clark(element),
namespaces=namespace)
return document and document[0].text or ''
class Invoice32(BaseInvoice):
"""An invoice object following 3.2 CFDI legal format.
@@ -120,6 +146,9 @@ def __init__(self, dict_invoice):
for k, v in dict_invoice.items():
if isinstance(v, dict):
self.__dict__[k] = Struct(v)
if isinstance(v, list):
self.__dict__[k] = StructList(v)
self.set_cfd()
def set_template_fname(self):
@@ -45,7 +45,7 @@
<cfdi:RegimenFiscal
Regimen="{{ inv.emitter_fiscal_position or '' }}"/>
</cfdi:Emisor>
<cfdi:
<cfdi:Receptor
nombre="{{ inv.receiver_name }}"
rfc="{{ inv.receiver_rfc }}">
<cfdi:Domicilio
@@ -58,7 +58,7 @@
noExterior="{{ inv.receiver_exterior_no }}"
noInterior="{{ inv.receiver_interior_no }}"
pais="{{ inv.receiver_country }}"/>
</cfdi:Receptor>{
</cfdi:Receptor>
{% if inv.invoice_lines %}
<cfdi:Conceptos>
{% for invoive_line in inv.invoice_lines %}
@@ -29,17 +29,45 @@ def setUp(self):
'number': 'ABC456',
'emitter_name': 'Vauxoo SA de CV',
'emitter_rfc': 'VAU111017CG9',
'emitter_street': 'Linuk 119',
'emitter_street': 'Lunik 119',
'emitter_zip': '37205',
'emitter_colony': u'Futurama Monteérrey',
'emitter_municipality': u'No se que iria',
'emitter_state': u'Guanajuato',
'emitter_locality': u'Guanajuato',
'emitter_exterior_no': 123,
'emitter_interior_no': 'N/A',
'emitter_country': u'México',
'emitter_issue_on_name': 'Vauxoo SA de CV',
'emitter_issue_on_rfc': 'VAU111017CG9',
'emitter_issue_on_street': 'Linuk 119',
'emitter_issue_on_zip': '37205',
'emitter_issue_on_colony': u'Futurama Monteérrey',
'emitter_issue_on_municipality': u'No se que iria',
'emitter_issue_on_state': u'Guanajuato',
'emitter_issue_on_locality': u'Guanajuato',
'emitter_issue_on_exterior_no': 123,
'emitter_issue_on_interior_no': 'N/A',
'emitter_issue_on_country': u'México',
'receiver_name': 'Some Customer SC',
'receiver_rfc': 'ECI0006019E0',
'receiver_street': u'Av. Unión',
'receiver_zip': '44158',
'receiver_colony': u'Futurama Monteérrey',
'receiver_municipality': u'No se que iria',
'receiver_state': u'ECI0006019E0',
'receiver_locality': u'Col. Deitz',
'receiver_exterior_no': 125,
'receiver_interior_no': 'N/A',
'receiver_country': u'México',
'certificate_number': '00001000000301059770',
'emitter_fiscal_position': u'Personas morales del Régimen general',
'document_type': 'ingreso',
'approval_number': 'VAU', # TODO: esto deberia ser simpl serie
'approval_number': 'VAU', # TODO: esto deberia ser simpl serie # TODO: esto deberia ser simpl serie
'taxes': {'total_transferred': 0.0,
'total_withhold': 0.0,
},
}
pass
@@ -78,14 +106,17 @@ def test_000_validator(self):
'The xml do not bring any schema compliant')
def test_001_get_xsd_documentation(self):
'''Getting a documentation from a given Clark's Notated xsd element'''
invoice = cfdilib.get_invoice(self.dict_invoice_basic)
print '''----'''
print invoice.get_documentation('DomicilioFiscal')
self.assertTrue(invoice.get_documentation('{http://www.sat.gob.mx/cfd/3}Impuestos').find('impuestos aplicables') > 0,
'Documentation did not returns the expected element' )
def test_002_get_cfd(self):
'''TODO: This test simply will validate that with a given valid dict an invoice object is crated'''
invoice = cfdilib.get_invoice(self.dict_invoice_basic)
self.assertFalse(invoice.ups,
self.assertFalse(False, # TODO: here will be invoice.ups
'A valid dictionary gave error the error was: %s' % invoice.ups.message) # noqa

0 comments on commit 82a668a

Please sign in to comment.