本文整理汇总了Python中aiohttp.client.ClientSession.patch方法的典型用法代码示例。如果您正苦于以下问题:Python ClientSession.patch方法的具体用法?Python ClientSession.patch怎么用?Python ClientSession.patch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aiohttp.client.ClientSession
的用法示例。
在下文中一共展示了ClientSession.patch方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_http_methods
# 需要导入模块: from aiohttp.client import ClientSession [as 别名]
# 或者: from aiohttp.client.ClientSession import patch [as 别名]
def test_http_methods(self, patched):
session = ClientSession(loop=self.loop)
add_params = dict(
headers={"Authorization": "Basic ..."},
max_redirects=2,
encoding="latin1",
version=aiohttp.HttpVersion10,
compress="deflate",
chunked=True,
expect100=True,
read_until_eof=False)
run = self.loop.run_until_complete
# Check GET
run(session.get(
"http://test.example.com",
params={"x": 1},
**add_params))
self.assertEqual(
patched.call_count, 1, "`ClientSession.request` not called")
self.assertEqual(
list(patched.call_args),
[("GET", "http://test.example.com",),
dict(
params={"x": 1},
allow_redirects=True,
**add_params)])
# Check OPTIONS
run(session.options(
"http://opt.example.com",
params={"x": 2},
**add_params))
self.assertEqual(
patched.call_count, 2, "`ClientSession.request` not called")
self.assertEqual(
list(patched.call_args),
[("OPTIONS", "http://opt.example.com",),
dict(
params={"x": 2},
allow_redirects=True,
**add_params)])
# Check HEAD
run(session.head(
"http://head.example.com",
params={"x": 2},
**add_params))
self.assertEqual(
patched.call_count, 3, "`ClientSession.request` not called")
self.assertEqual(
list(patched.call_args),
[("HEAD", "http://head.example.com",),
dict(
params={"x": 2},
allow_redirects=False,
**add_params)])
# Check POST
run(session.post(
"http://post.example.com",
params={"x": 2},
data="Some_data",
files={"x": '1'},
**add_params))
self.assertEqual(
patched.call_count, 4, "`ClientSession.request` not called")
self.assertEqual(
list(patched.call_args),
[("POST", "http://post.example.com",),
dict(
params={"x": 2},
data="Some_data",
files={"x": '1'},
**add_params)])
# Check PUT
run(session.put(
"http://put.example.com",
params={"x": 2},
data="Some_data",
files={"x": '1'},
**add_params))
self.assertEqual(
patched.call_count, 5, "`ClientSession.request` not called")
self.assertEqual(
list(patched.call_args),
[("PUT", "http://put.example.com",),
dict(
params={"x": 2},
data="Some_data",
files={"x": '1'},
**add_params)])
# Check PATCH
run(session.patch(
"http://patch.example.com",
params={"x": 2},
data="Some_data",
files={"x": '1'},
**add_params))
self.assertEqual(
patched.call_count, 6, "`ClientSession.request` not called")
self.assertEqual(
list(patched.call_args),
[("PATCH", "http://patch.example.com",),
#.........这里部分代码省略.........