示例#1
0
 def test_get_with_non_existing_index(self):
     """An error is raised when trying to access a non existing item."""
     schema = SequenceSchema("foo", NodeSchema("item", [LeafSchema("bar")]))
     root = etree.fromstring("<foo><item><bar>egg</bar></item></foo>")
     foo = schema.create(root)
     error = self.assertRaises(WSDLParseError, foo.__getitem__, 1)
     self.assertEqual("Non existing item in tag 'foo'", error.message)
示例#2
0
文件: test_wsdl.py 项目: GP89/txaws
 def test_get_with_non_existing_index(self):
     """An error is raised when trying to access a non existing item."""
     schema = SequenceSchema("foo", NodeSchema("item", [LeafSchema("bar")]))
     root = etree.fromstring("<foo><item><bar>egg</bar></item></foo>")
     foo = schema.create(root)
     error = self.assertRaises(WSDLParseError, foo.__getitem__, 1)
     self.assertEqual("Non existing item in tag 'foo'", error.message)
示例#3
0
文件: test_wsdl.py 项目: GP89/txaws
 def test_get(self):
     """
     The child elements of a L{SequenceItem} can be accessed as attributes.
     """
     schema = SequenceSchema("foo", NodeSchema("item", [LeafSchema("bar")]))
     root = etree.fromstring("<foo><item><bar>egg</bar></item></foo>")
     foo = schema.create(root)
     self.assertEqual("egg", foo[0].bar)
示例#4
0
 def test_get(self):
     """
     The child elements of a L{SequenceItem} can be accessed as attributes.
     """
     schema = SequenceSchema("foo", NodeSchema("item", [LeafSchema("bar")]))
     root = etree.fromstring("<foo><item><bar>egg</bar></item></foo>")
     foo = schema.create(root)
     self.assertEqual("egg", foo[0].bar)
示例#5
0
 def test_get_items(self):
     """L{SequenceItem} supports elements with many child items."""
     schema = SequenceSchema("foo", NodeSchema("item", [LeafSchema("bar")]))
     root = etree.fromstring("<foo>"
                             "<item><bar>egg0</bar></item>"
                             "<item><bar>egg1</bar></item>"
                             "</foo>")
     foo = schema.create(root)
     self.assertEqual("egg0", foo[0].bar)
     self.assertEqual("egg1", foo[1].bar)
示例#6
0
文件: test_wsdl.py 项目: GP89/txaws
 def test_get_items(self):
     """L{SequenceItem} supports elements with many child items."""
     schema = SequenceSchema("foo", NodeSchema("item", [LeafSchema("bar")]))
     root = etree.fromstring("<foo>"
                             "<item><bar>egg0</bar></item>"
                             "<item><bar>egg1</bar></item>"
                             "</foo>")
     foo = schema.create(root)
     self.assertEqual("egg0", foo[0].bar)
     self.assertEqual("egg1", foo[1].bar)
示例#7
0
文件: test_wsdl.py 项目: GP89/txaws
 def test_iter(self):
     """L{SequenceItem} objects are iterable."""
     schema = SequenceSchema("foo", NodeSchema("item", [LeafSchema("bar")]))
     root = etree.fromstring("<foo>"
                             "<item><bar>egg0</bar></item>"
                             "<item><bar>egg1</bar></item>"
                             "</foo>")
     foo = schema.create(root)
     [item0, item1] = list(foo)
     self.assertEqual("egg0", item0.bar)
     self.assertEqual("egg1", item1.bar)
示例#8
0
文件: test_wsdl.py 项目: GP89/txaws
 def test_remove_with_non_existing_item(self):
     """
     L{SequenceItem.remove} raises an exception when trying to remove a
     non existing item
     """
     schema = SequenceSchema("foo", NodeSchema("item", [LeafSchema("bar")]))
     root = etree.fromstring("<foo><item><bar>egg</bar></item></foo>")
     foo = schema.create(root)
     item = foo.remove(foo[0])
     error = self.assertRaises(WSDLParseError, foo.remove, item)
     self.assertEqual("Non existing item in tag 'foo'", error.message)
示例#9
0
 def test_remove_with_non_existing_item(self):
     """
     L{SequenceItem.remove} raises an exception when trying to remove a
     non existing item
     """
     schema = SequenceSchema("foo", NodeSchema("item", [LeafSchema("bar")]))
     root = etree.fromstring("<foo><item><bar>egg</bar></item></foo>")
     foo = schema.create(root)
     item = foo.remove(foo[0])
     error = self.assertRaises(WSDLParseError, foo.remove, item)
     self.assertEqual("Non existing item in tag 'foo'", error.message)
示例#10
0
 def test_iter(self):
     """L{SequenceItem} objects are iterable."""
     schema = SequenceSchema("foo", NodeSchema("item", [LeafSchema("bar")]))
     root = etree.fromstring("<foo>"
                             "<item><bar>egg0</bar></item>"
                             "<item><bar>egg1</bar></item>"
                             "</foo>")
     foo = schema.create(root)
     [item0, item1] = list(foo)
     self.assertEqual("egg0", item0.bar)
     self.assertEqual("egg1", item1.bar)
示例#11
0
文件: test_wsdl.py 项目: xzy3/txaws
 def test_append_with_too_many_items(self):
     """
     An error is raised when trying to append items above the max.
     """
     schema = SequenceSchema("foo")
     schema.set(NodeSchema("item", [LeafSchema("bar")]), min_occurs=0,
                max_occurs=1)
     root = etree.fromstring("<foo><item><bar>egg</bar></item></foo>")
     foo = schema.create(root)
     error = self.assertRaises(WSDLParseError, foo.append)
     self.assertEqual("Too many items in tag 'foo'", error.args[0])
     self.assertEqual(1, len(list(foo)))
示例#12
0
文件: test_wsdl.py 项目: GP89/txaws
 def test_append_with_too_many_items(self):
     """
     An error is raised when trying to append items above the max.
     """
     schema = SequenceSchema("foo")
     schema.set(NodeSchema("item", [LeafSchema("bar")]), min_occurs=0,
                max_occurs=1)
     root = etree.fromstring("<foo><item><bar>egg</bar></item></foo>")
     foo = schema.create(root)
     error = self.assertRaises(WSDLParseError, foo.append)
     self.assertEqual("Too many items in tag 'foo'", error.message)
     self.assertEqual(1, len(list(foo)))
示例#13
0
文件: test_wsdl.py 项目: GP89/txaws
 def test_delitem_with_not_enough_items(self):
     """
     L{SequenceItem.__delitem__} raises an error if trying to remove an item
     would make the sequence shorter than the required minimum.
     """
     schema = SequenceSchema("foo")
     schema.set(NodeSchema("item", [LeafSchema("bar")]), min_occurs=1,
                max_occurs=10)
     root = etree.fromstring("<foo><item><bar>egg</bar></item></foo>")
     foo = schema.create(root)
     error = self.assertRaises(WSDLParseError, foo.__delitem__, 0)
     self.assertEqual("Not enough items in tag 'foo'", error.message)
     self.assertEqual(1, len(list(foo)))
示例#14
0
文件: test_wsdl.py 项目: xzy3/txaws
 def test_delitem_with_not_enough_items(self):
     """
     L{SequenceItem.__delitem__} raises an error if trying to remove an item
     would make the sequence shorter than the required minimum.
     """
     schema = SequenceSchema("foo")
     schema.set(NodeSchema("item", [LeafSchema("bar")]), min_occurs=1,
                max_occurs=10)
     root = etree.fromstring("<foo><item><bar>egg</bar></item></foo>")
     foo = schema.create(root)
     error = self.assertRaises(WSDLParseError, foo.__delitem__, 0)
     self.assertEqual("Not enough items in tag 'foo'", error.args[0])
     self.assertEqual(1, len(list(foo)))
示例#15
0
文件: test_wsdl.py 项目: GP89/txaws
 def test_remove(self):
     """
     L{SequenceItem.remove} removes the given item from the sequence.
     """
     schema = SequenceSchema("foo", NodeSchema("item", [LeafSchema("bar")]))
     root = etree.fromstring("<foo>"
                             "<item><bar>egg0</bar></item>"
                             "<item><bar>egg1</bar></item>"
                             "</foo>")
     foo = schema.create(root)
     foo.remove(foo[0])
     self.assertEqual("egg1", foo[0].bar)
     self.assertEqual("<foo><item><bar>egg1</bar></item></foo>",
                      etree.tostring(schema.dump(foo)))
示例#16
0
 def test_remove(self):
     """
     L{SequenceItem.remove} removes the given item from the sequence.
     """
     schema = SequenceSchema("foo", NodeSchema("item", [LeafSchema("bar")]))
     root = etree.fromstring("<foo>"
                             "<item><bar>egg0</bar></item>"
                             "<item><bar>egg1</bar></item>"
                             "</foo>")
     foo = schema.create(root)
     foo.remove(foo[0])
     self.assertEqual("egg1", foo[0].bar)
     self.assertEqual("<foo><item><bar>egg1</bar></item></foo>",
                      etree.tostring(schema.dump(foo)))
示例#17
0
文件: test_wsdl.py 项目: xzy3/txaws
 def test_get_with_index_higher_than_max(self):
     """
     An error is raised when trying to access an item above the allowed
     max value.
     """
     schema = SequenceSchema("foo")
     schema.set(NodeSchema("item", [LeafSchema("bar")]), min_occurs=0,
                max_occurs=1)
     root = etree.fromstring("<foo>"
                             "<item><bar>egg0</bar></item>"
                             "<item><bar>egg1</bar></item>"
                             "</foo>")
     foo = schema.create(root)
     error = self.assertRaises(WSDLParseError, foo.__getitem__, 1)
     self.assertEqual("Out of range item in tag 'foo'", error.args[0])
示例#18
0
文件: test_wsdl.py 项目: GP89/txaws
 def test_get_with_index_higher_than_max(self):
     """
     An error is raised when trying to access an item above the allowed
     max value.
     """
     schema = SequenceSchema("foo")
     schema.set(NodeSchema("item", [LeafSchema("bar")]), min_occurs=0,
                max_occurs=1)
     root = etree.fromstring("<foo>"
                             "<item><bar>egg0</bar></item>"
                             "<item><bar>egg1</bar></item>"
                             "</foo>")
     foo = schema.create(root)
     error = self.assertRaises(WSDLParseError, foo.__getitem__, 1)
     self.assertEqual("Out of range item in tag 'foo'", error.message)
示例#19
0
 def test_delitem(self):
     """
     L{SequenceItem.__delitem__} removes from the sequence the item with the
     given index.
     """
     schema = SequenceSchema("foo", NodeSchema("item", [LeafSchema("bar")]))
     root = etree.fromstring("<foo>"
                             "<item><bar>egg0</bar></item>"
                             "<item><bar>egg1</bar></item>"
                             "</foo>")
     foo = schema.create(root)
     del foo[0]
     self.assertEqual("egg1", foo[0].bar)
     self.assertEqual("<foo><item><bar>egg1</bar></item></foo>",
                      etree.tostring(schema.dump(foo)))
示例#20
0
 def test_append(self):
     """
     L{SequenceItem.append} adds a new item to the sequence, appending it
     at the end.
     """
     schema = SequenceSchema("foo", NodeSchema("item", [LeafSchema("bar")]))
     root = etree.fromstring("<foo><item><bar>egg0</bar></item></foo>")
     foo = schema.create(root)
     foo.append().bar = "egg1"
     self.assertEqual("egg1", foo[1].bar)
     self.assertEqual(
         "<foo>"
         "<item><bar>egg0</bar></item>"
         "<item><bar>egg1</bar></item>"
         "</foo>", etree.tostring(schema.dump(foo)))
示例#21
0
文件: test_wsdl.py 项目: GP89/txaws
 def test_append(self):
     """
     L{SequenceItem.append} adds a new item to the sequence, appending it
     at the end.
     """
     schema = SequenceSchema("foo", NodeSchema("item", [LeafSchema("bar")]))
     root = etree.fromstring("<foo><item><bar>egg0</bar></item></foo>")
     foo = schema.create(root)
     foo.append().bar = "egg1"
     self.assertEqual("egg1", foo[1].bar)
     self.assertEqual("<foo>"
                      "<item><bar>egg0</bar></item>"
                      "<item><bar>egg1</bar></item>"
                      "</foo>",
                      etree.tostring(schema.dump(foo)))
示例#22
0
文件: test_wsdl.py 项目: GP89/txaws
 def test_delitem(self):
     """
     L{SequenceItem.__delitem__} removes from the sequence the item with the
     given index.
     """
     schema = SequenceSchema("foo", NodeSchema("item", [LeafSchema("bar")]))
     root = etree.fromstring("<foo>"
                             "<item><bar>egg0</bar></item>"
                             "<item><bar>egg1</bar></item>"
                             "</foo>")
     foo = schema.create(root)
     del foo[0]
     self.assertEqual("egg1", foo[0].bar)
     self.assertEqual("<foo><item><bar>egg1</bar></item></foo>",
                      etree.tostring(schema.dump(foo)))