本文整理汇总了Python中api.API._insert_text_node方法的典型用法代码示例。如果您正苦于以下问题:Python API._insert_text_node方法的具体用法?Python API._insert_text_node怎么用?Python API._insert_text_node使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api.API
的用法示例。
在下文中一共展示了API._insert_text_node方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestSilverpopApi
# 需要导入模块: from api import API [as 别名]
# 或者: from api.API import _insert_text_node [as 别名]
#.........这里部分代码省略.........
self.assertIsInstance(envelope, tuple)
self.assertEqual(len(envelope), 2)
self.assertEqual(envelope[0].tag, 'Envelope')
self.assertEqual(envelope[1].tag, 'Test')
self.assertEqual(etree.tostring(envelope[0]), expected)
self.assertIsInstance(envelope[0], etree._Element)
with self.assertRaises(TypeError):
self.api._envelope(123)
def test_is_successful_with_successful_response(self):
tree = etree.parse('tests/test_response.xml')
response = etree.tostring(tree)
info_tuple = self.api._is_successful(response)
self.assertIsInstance(info_tuple, tuple)
self.assertEqual(len(info_tuple), 2)
self.assertIsInstance(info_tuple[0], bool)
self.assertTrue(info_tuple[0])
self.assertIsNone(info_tuple[1])
def test_is_successful_with_error_response(self):
tree = etree.parse('tests/test_error_response.xml')
response = etree.tostring(tree)
info_tuple = self.api._is_successful(response)
self.assertIsInstance(info_tuple, tuple)
self.assertEqual(len(info_tuple), 2)
self.assertIsInstance(info_tuple[0], bool)
self.assertFalse(info_tuple[0])
self.assertIsInstance(info_tuple[1], tuple)
error = info_tuple[1]
expected_error_msg = (
"Unable to remove the recipient. "
"The list is private and you are not the owner.")
self.assertEqual(error[0], '140')
self.assertEqual(error[1], expected_error_msg)
def test_is_successful_with_malformed_error_response(self):
tree = etree.parse('tests/test_error_malformed_response.xml')
response = etree.tostring(tree)
with self.assertRaises(ValueError):
self.api._is_successful(response)
def test_parse_from_string(self):
tree = etree.parse('tests/test_error_response.xml')
response = etree.tostring(tree)
tree_ret = self.api._parse_from_string(response)
self.assertIsInstance(tree_ret, etree._Element)
def test_create_child_element(self):
root, action_node = self.api._envelope('Test')
dict_columns = {
'name': 'Droichead Orga',
'email': '[email protected]'
}
self.api._create_child_element(action_node, 'COLUMN', dict_columns)
children = action_node.getchildren()
names = list(dict_columns.iterkeys())
values = list(dict_columns.itervalues())
for child in children:
self.assertEqual(child.tag, 'COLUMN')
for ch in child:
if ch.tag == 'NAME':
self.assertIn(ch.text, names)
elif ch.tag == 'VALUE':
self.assertIn(ch.text, values)
def test_insert_text_node(self):
root, action_node = self.api._envelope('Test')
node = self.api._insert_text_node('subTest', 'insideText', action_node)
self.assertEqual(node.tag, 'subTest')
self.assertEqual(node.text, 'insideText')
def test_get_session_id(self):
tree = etree.parse('tests/test_login_response.xml')
response = etree.tostring(tree)
session = self.api._get_session_id(response)
self.assertIsNotNone(session)
self.assertEqual(len(session), 32)