def test_element_children_with_parents_restrictions(self): choice = Choice(elements=[Element(name="elem1")]) complex_type = ComplexType( sequence=Sequence(choices=[choice], min_occurs=0, max_occurs=3)) parent_restrictions = Restrictions.from_element(complex_type) children = SchemaMapper.element_children(complex_type, parent_restrictions) child, restrictions = next(children) expected = Restrictions(min_occurs=0, max_occurs=3, sequential=True, choice=str(id(choice))) self.assertEqual(expected, restrictions)
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 = SchemaMapper.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))