Example #1
0
 def test_set_with_unknown_tag(self):
     """
     An error is raised when trying to set an attribute not in the schema.
     """
     schema = NodeSchema("foo")
     foo = schema.create()
     error = self.assertRaises(WSDLParseError, setattr, foo, "bar", "egg")
     self.assertEqual("Unknown tag 'bar'", error.message)
Example #2
0
 def test_get_with_nested(self):
     """
     It is possible to access nested nodes.
     """
     schema = NodeSchema("foo", [NodeSchema("bar", [LeafSchema("egg")])])
     root = etree.fromstring("<foo><bar><egg>spam</egg></bar></foo>")
     foo = schema.create(root)
     self.assertEqual("spam", foo.bar.egg)
Example #3
0
 def test_get_with_namespace(self):
     """
     The child leaf elements of a L{NodeItem} can be accessed as attributes.
     """
     schema = NodeSchema("foo", [LeafSchema("bar")])
     root = etree.fromstring("<foo xmlns=\"spam\"><bar>egg</bar></foo>")
     foo = schema.create(root)
     self.assertEqual("egg", foo.bar)
Example #4
0
 def test_set_with_unknown_tag(self):
     """
     An error is raised when trying to set an attribute not in the schema.
     """
     schema = NodeSchema("foo")
     foo = schema.create()
     error = self.assertRaises(WSDLParseError, setattr, foo, "bar", "egg")
     self.assertEqual("Unknown tag 'bar'", error.message)
Example #5
0
 def test_get_with_nested(self):
     """
     It is possible to access nested nodes.
     """
     schema = NodeSchema("foo", [NodeSchema("bar", [LeafSchema("egg")])])
     root = etree.fromstring("<foo><bar><egg>spam</egg></bar></foo>")
     foo = schema.create(root)
     self.assertEqual("spam", foo.bar.egg)
Example #6
0
 def test_get_with_namespace(self):
     """
     The child leaf elements of a L{NodeItem} can be accessed as attributes.
     """
     schema = NodeSchema("foo", [LeafSchema("bar")])
     root = etree.fromstring("<foo xmlns=\"spam\"><bar>egg</bar></foo>")
     foo = schema.create(root)
     self.assertEqual("egg", foo.bar)
Example #7
0
 def test_get_with_many_children(self):
     """
     Multiple children are supported.
     """
     schema = NodeSchema("foo", [LeafSchema("bar"), LeafSchema("egg")])
     root = etree.fromstring("<foo><bar>spam1</bar><egg>spam2</egg></foo>")
     foo = schema.create(root)
     self.assertEqual("spam1", foo.bar)
     self.assertEqual("spam2", foo.egg)
Example #8
0
 def test_get_with_reserved_keyword(self):
     """
     Attributes associated to tags named against required attributes can
     be accessed appending a '_' to the name.
     """
     schema = NodeSchema("foo", [LeafSchema("return")])
     root = etree.fromstring("<foo><return>true</return></foo>")
     foo = schema.create(root)
     self.assertEqual("true", foo.return_)
Example #9
0
 def test_get_with_non_required_tag(self):
     """
     No error is raised if a tag is missing and its min count is zero.
     """
     schema = NodeSchema("foo")
     schema.add(LeafSchema("bar"), min_occurs=0)
     root = etree.fromstring("<foo></foo>")
     foo = schema.create(root)
     self.assertIdentical(None, foo.bar)
Example #10
0
 def test_get_with_reserved_keyword(self):
     """
     Attributes associated to tags named against required attributes can
     be accessed appending a '_' to the name.
     """
     schema = NodeSchema("foo", [LeafSchema("return")])
     root = etree.fromstring("<foo><return>true</return></foo>")
     foo = schema.create(root)
     self.assertEqual("true", foo.return_)
Example #11
0
 def test_get_with_non_required_tag(self):
     """
     No error is raised if a tag is missing and its min count is zero.
     """
     schema = NodeSchema("foo")
     schema.add(LeafSchema("bar"), min_occurs=0)
     root = etree.fromstring("<foo></foo>")
     foo = schema.create(root)
     self.assertIdentical(None, foo.bar)
Example #12
0
 def test_get_with_many_children(self):
     """
     Multiple children are supported.
     """
     schema = NodeSchema("foo", [LeafSchema("bar"), LeafSchema("egg")])
     root = etree.fromstring("<foo><bar>spam1</bar><egg>spam2</egg></foo>")
     foo = schema.create(root)
     self.assertEqual("spam1", foo.bar)
     self.assertEqual("spam2", foo.egg)
Example #13
0
 def test_set_with_non_leaf_tag(self):
     """
     An error is raised when trying to set a non-leaf attribute to
     a value other than C{None}.
     """
     schema = NodeSchema("foo", [NodeSchema("bar", [LeafSchema("egg")])])
     root = etree.fromstring("<foo><bar><egg>spam</egg></bar></foo>")
     foo = schema.create(root)
     error = self.assertRaises(WSDLParseError, setattr, foo, "bar", "yo")
     self.assertEqual("Can't set non-leaf tag 'bar'", error.message)
Example #14
0
 def test_get_with_empty_required_tag(self):
     """
     An error is raised if an expected required tag is found but has and
     empty value.
     """
     schema = NodeSchema("foo", [LeafSchema("bar")])
     root = etree.fromstring("<foo><bar/></foo>")
     item = schema.create(root)
     error = self.assertRaises(WSDLParseError, getattr, item, "bar")
     self.assertEqual("Missing tag 'bar'", error.message)
Example #15
0
 def test_set_with_duplicate_tag(self):
     """
     An error is raised when trying to set an attribute associated
     with a tag that appears more than once.
     """
     schema = NodeSchema("foo", [LeafSchema("bar")])
     root = etree.fromstring("<foo><bar>spam1</bar><bar>spam2</bar></foo>")
     foo = schema.create(root)
     error = self.assertRaises(WSDLParseError, setattr, foo, "bar", "egg")
     self.assertEqual("Duplicate tag 'bar'", error.message)
Example #16
0
 def test_get_with_unknown_tag(self):
     """
     An error is raised when trying to access an attribute not in the
     schema.
     """
     schema = NodeSchema("foo", [LeafSchema("bar")])
     root = etree.fromstring("<foo><bar>egg</bar><spam>boom</spam></foo>")
     foo = schema.create(root)
     error = self.assertRaises(WSDLParseError, getattr, foo, "spam")
     self.assertEqual("Unknown tag 'spam'", error.message)
Example #17
0
 def test_set_with_required_tag(self):
     """
     An error is raised when trying to set a required attribute to C{None}.
     """
     schema = NodeSchema("foo", [LeafSchema("bar")])
     root = etree.fromstring("<foo><bar>spam</bar></foo>")
     foo = schema.create(root)
     error = self.assertRaises(WSDLParseError, setattr, foo, "bar", None)
     self.assertEqual("Missing tag 'bar'", error.message)
     self.assertEqual("spam", foo.bar)
Example #18
0
 def test_get_with_empty_required_tag(self):
     """
     An error is raised if an expected required tag is found but has and
     empty value.
     """
     schema = NodeSchema("foo", [LeafSchema("bar")])
     root = etree.fromstring("<foo><bar/></foo>")
     item = schema.create(root)
     error = self.assertRaises(WSDLParseError, getattr, item, "bar")
     self.assertEqual("Missing tag 'bar'", error.message)
Example #19
0
 def test_get_with_missing_required_tag(self):
     """
     An error is raised when trying to access a required attribute and
     the associated tag is missing.
     """
     schema = NodeSchema("foo", [LeafSchema("bar")])
     root = etree.fromstring("<foo></foo>")
     item = schema.create(root)
     error = self.assertRaises(WSDLParseError, getattr, item, "bar")
     self.assertEqual("Missing tag 'bar'", error.message)
Example #20
0
 def test_get_with_unknown_tag(self):
     """
     An error is raised when trying to access an attribute not in the
     schema.
     """
     schema = NodeSchema("foo", [LeafSchema("bar")])
     root = etree.fromstring("<foo><bar>egg</bar><spam>boom</spam></foo>")
     foo = schema.create(root)
     error = self.assertRaises(WSDLParseError, getattr, foo, "spam")
     self.assertEqual("Unknown tag 'spam'", error.message)
Example #21
0
 def test_get_with_missing_required_tag(self):
     """
     An error is raised when trying to access a required attribute and
     the associated tag is missing.
     """
     schema = NodeSchema("foo", [LeafSchema("bar")])
     root = etree.fromstring("<foo></foo>")
     item = schema.create(root)
     error = self.assertRaises(WSDLParseError, getattr, item, "bar")
     self.assertEqual("Missing tag 'bar'", error.message)
Example #22
0
 def test_set_with_non_leaf_tag(self):
     """
     An error is raised when trying to set a non-leaf attribute to
     a value other than C{None}.
     """
     schema = NodeSchema("foo", [NodeSchema("bar", [LeafSchema("egg")])])
     root = etree.fromstring("<foo><bar><egg>spam</egg></bar></foo>")
     foo = schema.create(root)
     error = self.assertRaises(WSDLParseError, setattr, foo, "bar", "yo")
     self.assertEqual("Can't set non-leaf tag 'bar'", error.message)
Example #23
0
 def test_set_with_required_tag(self):
     """
     An error is raised when trying to set a required attribute to C{None}.
     """
     schema = NodeSchema("foo", [LeafSchema("bar")])
     root = etree.fromstring("<foo><bar>spam</bar></foo>")
     foo = schema.create(root)
     error = self.assertRaises(WSDLParseError, setattr, foo, "bar", None)
     self.assertEqual("Missing tag 'bar'", error.message)
     self.assertEqual("spam", foo.bar)
Example #24
0
 def test_set_with_duplicate_tag(self):
     """
     An error is raised when trying to set an attribute associated
     with a tag that appears more than once.
     """
     schema = NodeSchema("foo", [LeafSchema("bar")])
     root = etree.fromstring("<foo><bar>spam1</bar><bar>spam2</bar></foo>")
     foo = schema.create(root)
     error = self.assertRaises(WSDLParseError, setattr, foo, "bar", "egg")
     self.assertEqual("Duplicate tag 'bar'", error.message)
Example #25
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 #26
0
 def test_set_with_required_non_leaf_tag(self):
     """
     An error is raised when trying to set a required non-leaf tag
     to C{None}.
     """
     schema = NodeSchema("foo", [NodeSchema("bar", [LeafSchema("egg")])])
     root = etree.fromstring("<foo><bar><egg>spam</egg></bar></foo>")
     foo = schema.create(root)
     error = self.assertRaises(WSDLParseError, setattr, foo, "bar", None)
     self.assertEqual("Missing tag 'bar'", error.message)
     self.assertTrue(hasattr(foo, "bar"))
Example #27
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 #28
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 #29
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 #30
0
 def test_set_with_required_non_leaf_tag(self):
     """
     An error is raised when trying to set a required non-leaf tag
     to C{None}.
     """
     schema = NodeSchema("foo", [NodeSchema("bar", [LeafSchema("egg")])])
     root = etree.fromstring("<foo><bar><egg>spam</egg></bar></foo>")
     foo = schema.create(root)
     error = self.assertRaises(WSDLParseError, setattr, foo, "bar", None)
     self.assertEqual("Missing tag 'bar'", error.message)
     self.assertTrue(hasattr(foo, "bar"))
Example #31
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 #32
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 #33
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 #34
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)))