def test_dump(self): """ L{NodeSchema.dump} creates an L{etree.Element} out of a L{NodeItem}. """ schema = NodeSchema("foo", [LeafSchema("bar")]) foo = NodeItem(schema) foo.bar = "spam" self.assertEqual("<foo><bar>spam</bar></foo>", etree.tostring(schema.dump(foo)))
def test_dump_with_multiple_children(self): """ L{NodeSchema.dump} supports multiple children. """ schema = NodeSchema("foo", [LeafSchema("bar"), LeafSchema("egg")]) foo = NodeItem(schema) foo.bar = "spam1" foo.egg = "spam2" self.assertEqual("<foo><bar>spam1</bar><egg>spam2</egg></foo>", etree.tostring(schema.dump(foo)))
def test_dump_with_missing_attribute(self): """ L{NodeSchema.dump} ignores missing attributes if C{min_occurs} is zero. """ schema = NodeSchema("foo") schema.add(LeafSchema("bar"), min_occurs=0) foo = NodeItem(schema) self.assertEqual("<foo/>", etree.tostring(schema.dump(foo)))