本文整理汇总了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
示例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
示例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
示例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