Example #1
0
 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)))
Example #2
0
 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)))
Example #3
0
 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)))
Example #4
0
 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)))
Example #5
0
 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)))
Example #6
0
 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)))
Example #7
0
 def test_set_with_optional_node_tag(self):
     """
     It is possible to set an optional node tag to C{None}, in that
     case it will be removed from the tree.
     """
     schema = NodeSchema("foo")
     schema.add(NodeSchema("bar", [LeafSchema("egg")]), min_occurs=0)
     root = etree.fromstring("<foo><bar><egg>spam</egg></bar></foo>")
     foo = schema.create(root)
     foo.bar = None
     self.assertEqual("<foo/>", etree.tostring(schema.dump(foo)))
Example #8
0
 def test_set_with_non_required_tag(self):
     """
     It is possible to set a non-required tag value to C{None}, in that
     case the element will be removed if present.
     """
     schema = NodeSchema("foo")
     schema.add(LeafSchema("bar"), min_occurs=0)
     root = etree.fromstring("<foo><bar>spam</bar></foo>")
     foo = schema.create(root)
     foo.bar = None
     self.assertEqual("<foo/>", etree.tostring(schema.dump(foo)))
Example #9
0
 def test_set_with_optional_node_tag(self):
     """
     It is possible to set an optional node tag to C{None}, in that
     case it will be removed from the tree.
     """
     schema = NodeSchema("foo")
     schema.add(NodeSchema("bar", [LeafSchema("egg")]), min_occurs=0)
     root = etree.fromstring("<foo><bar><egg>spam</egg></bar></foo>")
     foo = schema.create(root)
     foo.bar = None
     self.assertEqual("<foo/>", etree.tostring(schema.dump(foo)))
Example #10
0
 def test_set_with_non_required_tag(self):
     """
     It is possible to set a non-required tag value to C{None}, in that
     case the element will be removed if present.
     """
     schema = NodeSchema("foo")
     schema.add(LeafSchema("bar"), min_occurs=0)
     root = etree.fromstring("<foo><bar>spam</bar></foo>")
     foo = schema.create(root)
     foo.bar = None
     self.assertEqual("<foo/>", etree.tostring(schema.dump(foo)))
Example #11
0
 def test_get_with_non_required_nested(self):
     """
     It is possible to access a non-required nested node that has no
     associated element in the XML yet, in that case a new element is
     created for it.
     """
     schema = NodeSchema("foo")
     schema.add(NodeSchema("bar", [LeafSchema("egg")]), min_occurs=0)
     root = etree.fromstring("<foo/>")
     foo = schema.create(root)
     foo.bar.egg = "spam"
     self.assertEqual("<foo><bar><egg>spam</egg></bar></foo>",
                      etree.tostring(schema.dump(foo)))
Example #12
0
 def test_get_with_non_required_nested(self):
     """
     It is possible to access a non-required nested node that has no
     associated element in the XML yet, in that case a new element is
     created for it.
     """
     schema = NodeSchema("foo")
     schema.add(NodeSchema("bar", [LeafSchema("egg")]), min_occurs=0)
     root = etree.fromstring("<foo/>")
     foo = schema.create(root)
     foo.bar.egg = "spam"
     self.assertEqual("<foo><bar><egg>spam</egg></bar></foo>",
                      etree.tostring(schema.dump(foo)))
Example #13
0
 def test_set_with_sequence_tag(self):
     """
     It is possible to set a sequence tag to C{None}, in that case
     all its children will be removed
     """
     schema = NodeSchema("foo")
     schema.add(
         SequenceSchema("bar", NodeSchema("item", [LeafSchema("egg")])))
     root = etree.fromstring("<foo>"
                             "<bar><item><egg>spam</egg></item></bar><"
                             "/foo>")
     foo = schema.create(root)
     foo.bar = None
     self.assertEqual("<foo><bar/></foo>", etree.tostring(schema.dump(foo)))
Example #14
0
 def test_set_with_sequence_tag(self):
     """
     It is possible to set a sequence tag to C{None}, in that case
     all its children will be removed
     """
     schema = NodeSchema("foo")
     schema.add(SequenceSchema("bar",
                               NodeSchema("item", [LeafSchema("egg")])))
     root = etree.fromstring("<foo>"
                             "<bar><item><egg>spam</egg></item></bar><"
                             "/foo>")
     foo = schema.create(root)
     foo.bar = None
     self.assertEqual("<foo><bar/></foo>", etree.tostring(schema.dump(foo)))