当前位置: 首页>>代码示例>>Python>>正文


Python API._get_session_id方法代码示例

本文整理汇总了Python中api.API._get_session_id方法的典型用法代码示例。如果您正苦于以下问题:Python API._get_session_id方法的具体用法?Python API._get_session_id怎么用?Python API._get_session_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在api.API的用法示例。


在下文中一共展示了API._get_session_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestSilverpopApi

# 需要导入模块: from api import API [as 别名]
# 或者: from api.API import _get_session_id [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)
开发者ID:nicholasamorim,项目名称:silverpy,代码行数:104,代码来源:test_api.py


注:本文中的api.API._get_session_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。