def test_rendering_simple_type(self): passengers = xsd.ListElement(xsd.String, "passenger", maxOccurs=10, minOccurs=0) passengers_list = ["abc", "123"] xmlelement = etree.Element("flight") passengers.render(xmlelement, "passenger", passengers_list) expected_xml = b"""<flight> <passenger>abc</passenger> <passenger>123</passenger> </flight> """ xml = etree.tostring(xmlelement, pretty_print=True) self.assertEqual(expected_xml, xml)
def test_rendering_simple_type(self): passengers = xsd.ListElement(xsd.String, 'passenger', maxOccurs=10, minOccurs=0) passengers_list = ['abc', '123'] xmlelement = etree.Element('flight') passengers.render(xmlelement, 'passenger', passengers_list) expected_xml = b'''<flight> <passenger>abc</passenger> <passenger>123</passenger> </flight> ''' xml = etree.tostring(xmlelement, pretty_print=True) self.assertEqual(expected_xml, xml)
class ArrayOfErrorDeDocumentoPdf(xsd.ComplexType): INHERITANCE = None INDICATOR = xsd.Sequence ErrorDeDocumentoPdf = xsd.ListElement(__name__ + '.ErrorDeDocumentoPdf', tagname='ErrorDeDocumentoPdf', minOccurs=0, maxOccurs=xsd.UNBOUNDED, nillable=True) @classmethod def create(cls): instance = cls() return instance @property def ErrorDeDocumento(self): return self.ErrorDeDocumentoPdf
class Test(xsd.ComplexType): values = xsd.ListElement(xsd.Int, 'value', nillable=True)
class Test(xsd.ComplexType): values = xsd.ListElement(xsd.String, 'value', nillable=True) notnillable = xsd.ListElement(xsd.String, 'notnillable', minOccurs=0)
def test_append_with_max_occurs_unbounded(self): l = xsd.ListElement(xsd.String, maxOccurs=xsd.UNBOUNDED, tagname='toto').empty_value() l.append('a') l.append('a')
class Test(xsd.ComplexType): values = xsd.ListElement(xsd.Int, 'value')
def test_append_restriction(self): l = xsd.ListElement(xsd.String, maxOccurs=1, tagname='toto').empty_value() l.append('a') e = assert_raises(ValueError, lambda: l.append('a')) assert_equals('You must not add more than 1 items to this list.', str(e))
class Users(xsd.ComplexType): INHERITANCE = None user = xsd.ListElement(User, tagname="users", minOccurs=0)
class StockPrice(xsd.ComplexType): nillable = xsd.Element(xsd.Int, nillable=True) prices = xsd.ListElement(xsd.Decimal(fractionDigits=2), tagname='price', minOccurs=0, maxOccurs=xsd.UNBOUNDED, nillable=True)