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


Python AsyncHTTPTestCase.fetch方法代码示例

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


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

示例1: test_registering

# 需要导入模块: from tornado.testing import AsyncHTTPTestCase [as 别名]
# 或者: from tornado.testing.AsyncHTTPTestCase import fetch [as 别名]
    def test_registering(self):
        registry = PluginRegistry.getInstance("WebhookRegistry")
        hook = TestWebhook()
        registry.register_handler("application/vnd.gosa.test+plain", hook)
        url, token = registry.registerWebhook("admin", "test-webhook", "application/vnd.gosa.test+plain")

        token = bytes(token, 'ascii')
        signature_hash = hmac.new(token, msg=b"Test", digestmod="sha512")
        signature = 'sha1=' + signature_hash.hexdigest()
        headers = {
            'Content-Type': 'application/vnd.gosa.test+plain',
            'HTTP_X_HUB_SENDER': 'test-webhook',
            'HTTP_X_HUB_SIGNATURE': signature
        }
        with mock.patch.object(hook, "content") as m_content:
            AsyncHTTPTestCase.fetch(self, "/hooks/", method="POST", headers=headers, body=b"Test")
            m_content.assert_called_with(b"Test")
            m_content.reset_mock()

            registry.unregisterWebhook("admin", "test-webhook", "application/vnd.gosa.test+plain")
            AsyncHTTPTestCase.fetch(self, url, method="POST", headers=headers, body=b"Test")
            assert not m_content.called
开发者ID:gonicus,项目名称:gosa,代码行数:24,代码来源:test_registry.py

示例2: fetch

# 需要导入模块: from tornado.testing import AsyncHTTPTestCase [as 别名]
# 或者: from tornado.testing.AsyncHTTPTestCase import fetch [as 别名]
 def fetch(self, url, **kw):
     headers = kw.pop('headers', {})
     if self.__cookies != '':
         headers['Cookie'] = self.__cookies
     if self._xsrf:
         headers['X-XSRFToken'] = self._xsrf
         if len(headers['Cookie'])>0 and '_xsrf' not in headers['Cookie']:
             headers['Cookie'] = "%s;%s=%s" % (headers['Cookie'], '_xsrf', self._xsrf)
     # if 'body' in kw:
     #     print("URL: {}, Body: {}, Headers: {}".format(url, kw['body'] , headers))
     # else:
     #     print("URL: {}, Headers: {}".format(url, headers))
     resp = AsyncHTTPTestCase.fetch(self, url, headers=headers, **kw)
     self._update_cookies(resp.headers)
     return resp
开发者ID:gonicus,项目名称:gosa,代码行数:17,代码来源:RemoteTestCase.py

示例3: test_post

# 需要导入模块: from tornado.testing import AsyncHTTPTestCase [as 别名]
# 或者: from tornado.testing.AsyncHTTPTestCase import fetch [as 别名]
    def test_post(self):

        # create webhook post
        e = EventMaker()
        update = e.Event(
            e.BackendChange(
                e.DN("cn=Test,ou=people,dc=example,dc=net"),
                e.ModificationTime(datetime.now().strftime("%Y%m%d%H%M%SZ")),
                e.ChangeType("update")
            )
        )
        payload = etree.tostring(update)

        token = bytes(Environment.getInstance().config.get("webhooks.ldap_monitor_token"), 'ascii')
        signature_hash = hmac.new(token, msg=payload, digestmod="sha512")
        signature = 'sha1=' + signature_hash.hexdigest()

        headers = {
            'Content-Type': 'application/vnd.gosa.event+xml',
            'HTTP_X_HUB_SENDER': 'backend-monitor',
            'HTTP_X_HUB_SIGNATURE': signature
        }
        with mock.patch("gosa.backend.plugins.webhook.registry.zope.event.notify") as m_notify:
            AsyncHTTPTestCase.fetch(self, "/hooks/", method="POST", headers=headers, body=payload)
            assert m_notify.called
            m_notify.reset_mock()

            # unregistered sender
            headers['HTTP_X_HUB_SENDER'] = 'unknown'
            resp = AsyncHTTPTestCase.fetch(self, "/hooks/", method="POST", headers=headers, body=payload)
            assert resp.code == 401
            assert not m_notify.called

            # wrong signature
            headers['HTTP_X_HUB_SENDER'] = 'backend-monitor'
            headers['HTTP_X_HUB_SIGNATURE'] = 'sha1=823rjadfkjlasasddfdgasdfgasd'
            resp = AsyncHTTPTestCase.fetch(self, "/hooks/", method="POST", headers=headers, body=payload)
            assert resp.code == 401
            assert not m_notify.called

            # no signature
            del headers['HTTP_X_HUB_SIGNATURE']
            resp = AsyncHTTPTestCase.fetch(self, "/hooks/", method="POST", headers=headers, body=payload)
            assert resp.code == 401
            assert not m_notify.called

            # no handler for content type
            headers['HTTP_X_HUB_SIGNATURE'] = signature
            headers['Content-Type'] = 'application/vnd.gosa.unknown+xml'
            resp = AsyncHTTPTestCase.fetch(self, "/hooks/", method="POST", headers=headers, body=payload)
            assert resp.code == 401
            assert not m_notify.called
开发者ID:gonicus,项目名称:gosa,代码行数:54,代码来源:test_registry.py

示例4: fetch

# 需要导入模块: from tornado.testing import AsyncHTTPTestCase [as 别名]
# 或者: from tornado.testing.AsyncHTTPTestCase import fetch [as 别名]
 def fetch(self, path, **kwargs):
     response = AsyncHTTPTestCase.fetch(self, path, **kwargs)
     if response.body is not None:
         response.value = response.body.decode('utf-8')
     return response
开发者ID:censhin,项目名称:tornado-bootstrap,代码行数:7,代码来源:base.py


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