Ejemplo n.º 1
0
 def test_element_children(self):
     sequence_one = Sequence(elements=[Element(), Element()])
     sequence_two = Sequence(max_occurs=2, elements=[Element(), Element()])
     restriction = Restriction(
         enumerations=[Enumeration(value=x) for x in "abc"], sequence=sequence_two,
     )
     complex_type = ComplexType(
         attributes=[Attribute(), Attribute()],
         sequence=sequence_one,
         simple_content=SimpleContent(restriction=Restriction()),
         complex_content=ComplexContent(restriction=restriction,),
     )
     restrictions = Restrictions.from_element(complex_type)
     children = self.builder.element_children(complex_type, restrictions)
     expected = [
         (sequence_two.elements[0], Restrictions.from_element(sequence_two)),
         (sequence_two.elements[1], Restrictions.from_element(sequence_two)),
         (restriction.enumerations[0], Restrictions.from_element(restriction)),
         (restriction.enumerations[1], Restrictions.from_element(restriction)),
         (restriction.enumerations[2], Restrictions.from_element(restriction)),
         (sequence_one.elements[0], Restrictions.from_element(sequence_one)),
         (sequence_one.elements[1], Restrictions.from_element(sequence_one)),
         (complex_type.attributes[0], Restrictions.from_element(complex_type)),
         (complex_type.attributes[1], Restrictions.from_element(complex_type)),
     ]
     self.assertIsInstance(children, GeneratorType)
     self.assertEqual(expected, list(children))
Ejemplo n.º 2
0
    def test_children_extensions(self):
        complex_type = ComplexType(
            attributes=[Attribute(index=i) for i in range(2)],
            simple_content=SimpleContent(restriction=Restriction(base="bk:b", index=4)),
            complex_content=ComplexContent(extension=Extension(base="bk:ext", index=7)),
        )

        item = ClassFactory.create()
        children = self.builder.children_extensions(complex_type, item)
        expected = list(
            map(
                ExtensionFactory.create,
                [
                    AttrTypeFactory.create(name="bk:b", index=4),
                    AttrTypeFactory.create(name="bk:ext", index=7),
                ],
            )
        )

        self.assertIsInstance(children, GeneratorType)
        self.assertEqual(expected, list(children))
Ejemplo n.º 3
0
    def test_children_extensions(self):
        complex_type = ComplexType(
            attributes=[Attribute() for _ in range(2)],
            simple_content=SimpleContent(restriction=Restriction(base="bk:b")),
            complex_content=ComplexContent(extension=Extension(base="bk:c")),
        )
        complex_type.simple_content.restriction.index = 4
        complex_type.complex_content.extension.index = 7

        item = ClassFactory.create(ns_map={"bk": "book"})
        children = SchemaMapper.children_extensions(complex_type, item)
        expected = list(
            map(
                ExtensionFactory.create,
                [
                    AttrTypeFactory.create(qname=build_qname("book", "b")),
                    AttrTypeFactory.create(qname=build_qname("book", "c")),
                ],
            ))

        self.assertIsInstance(children, GeneratorType)
        self.assertEqual(expected, list(children))
Ejemplo n.º 4
0
 def test_property_extension(self):
     obj = SimpleContent()
     self.assertEqual([], list(obj.extensions))