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


Python Router.get_onionoo_details方法代码示例

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


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

示例1: OnionOOTests

# 需要导入模块: from txtorcon.router import Router [as 别名]
# 或者: from txtorcon.router.Router import get_onionoo_details [as 别名]
class OnionOOTests(unittest.TestCase):

    def setUp(self):
        self.router = Router(FakeController())
        self.router.update(
            "foo",
            "AHhuQ8zFQJdT8l42Axxc6m6kNwI",
            "MAANkj30tnFvmoh7FsjVFr+cmcs",
            "2011-12-16 15:11:34",
            "1.2.3.4",
            "24051", "24052"
        )

    @defer.inlineCallbacks
    def test_onionoo_get_fails(self):
        agent = Mock()
        resp = Mock()
        resp.code = 500
        agent.request = Mock(return_value=defer.succeed(resp))

        with self.assertRaises(Exception) as ctx:
            yield self.router.get_onionoo_details(agent)
        self.assertTrue(
            "Failed to lookup" in str(ctx.exception)
        )

    @defer.inlineCallbacks
    def test_onionoo_success(self):
        agent = Mock()
        resp = Mock()
        resp.code = 200

        def feed_response(protocol):
            config = {
                "relays": [
                    {
                        "fingerprint": "00786E43CCC5409753F25E36031C5CEA6EA43702",
                    },
                ]
            }
            protocol.dataReceived(json.dumps(config).encode())
            protocol.connectionLost(Failure(ResponseDone()))
        resp.deliverBody = Mock(side_effect=feed_response)
        agent.request = Mock(return_value=defer.succeed(resp))

        data = yield self.router.get_onionoo_details(agent)

        self.assertTrue('fingerprint' in data)
        self.assertTrue(data['fingerprint'] == "00786E43CCC5409753F25E36031C5CEA6EA43702")

    @defer.inlineCallbacks
    def test_onionoo_too_many_answers(self):
        agent = Mock()
        resp = Mock()
        resp.code = 200

        def feed_response(protocol):
            config = {
                "relays": [
                    {
                        "fingerprint": "00786E43CCC5409753F25E36031C5CEA6EA43702",
                    },
                    {
                        "fingerprint": "boom",
                    }
                ]
            }
            protocol.dataReceived(json.dumps(config).encode())
            protocol.connectionLost(Failure(ResponseDone()))
        resp.deliverBody = Mock(side_effect=feed_response)
        agent.request = Mock(return_value=defer.succeed(resp))

        with self.assertRaises(Exception) as ctx:
            yield self.router.get_onionoo_details(agent)

        self.assertTrue(
            "multiple relays for" in str(ctx.exception)
        )

    @defer.inlineCallbacks
    def test_onionoo_wrong_fingerprint(self):
        agent = Mock()
        resp = Mock()
        resp.code = 200

        def feed_response(protocol):
            config = {
                "relays": [
                    {
                        "fingerprint": "boom",
                    },
                ]
            }
            protocol.dataReceived(json.dumps(config).encode())
            protocol.connectionLost(Failure(ResponseDone()))
        resp.deliverBody = Mock(side_effect=feed_response)
        agent.request = Mock(return_value=defer.succeed(resp))

        with self.assertRaises(Exception) as ctx:
            yield self.router.get_onionoo_details(agent)
#.........这里部分代码省略.........
开发者ID:felipedau,项目名称:txtorcon,代码行数:103,代码来源:test_router.py


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