本文整理汇总了Python中vcr.request.Request.headers['Content-Type']方法的典型用法代码示例。如果您正苦于以下问题:Python Request.headers['Content-Type']方法的具体用法?Python Request.headers['Content-Type']怎么用?Python Request.headers['Content-Type']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vcr.request.Request
的用法示例。
在下文中一共展示了Request.headers['Content-Type']方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_remove_json_post_data_parameters
# 需要导入模块: from vcr.request import Request [as 别名]
# 或者: from vcr.request.Request import headers['Content-Type'] [as 别名]
def test_remove_json_post_data_parameters():
body = b'{"id": "secret", "foo": "bar", "baz": "qux"}'
request = Request('POST', 'http://google.com', body, {})
request.headers['Content-Type'] = 'application/json'
remove_post_data_parameters(request, ['id'])
request_body_json = json.loads(request.body.decode('utf-8'))
expected_json = json.loads(b'{"foo": "bar", "baz": "qux"}'.decode('utf-8'))
assert request_body_json == expected_json
示例2: test_replace_json_post_data_parameters
# 需要导入模块: from vcr.request import Request [as 别名]
# 或者: from vcr.request.Request import headers['Content-Type'] [as 别名]
def test_replace_json_post_data_parameters():
# This tests all of:
# 1. keeping a parameter
# 2. removing a parameter
# 3. replacing a parameter
# 4. replacing a parameter using a callable
# 5. removing a parameter using a callable
# 6. replacing a parameter that doesn't exist
body = b'{"one": "keep", "two": "lose", "three": "change", "four": "shout", "five": "whisper"}'
request = Request('POST', 'http://google.com', body, {})
request.headers['Content-Type'] = 'application/json'
replace_post_data_parameters(request, [
('two', None),
('three', 'tada'),
('four', lambda key, value, request: value.upper()),
('five', lambda key, value, request: None),
('six', 'doesntexist'),
])
request_data = json.loads(request.body.decode('utf-8'))
expected_data = json.loads('{"one": "keep", "three": "tada", "four": "SHOUT"}')
assert request_data == expected_data
示例3: test_remove_all_json_post_data_parameters
# 需要导入模块: from vcr.request import Request [as 别名]
# 或者: from vcr.request.Request import headers['Content-Type'] [as 别名]
def test_remove_all_json_post_data_parameters():
body = b'{"id": "secret", "foo": "bar"}'
request = Request('POST', 'http://google.com', body, {})
request.headers['Content-Type'] = 'application/json'
replace_post_data_parameters(request, [('id', None), ('foo', None)])
assert request.body == b'{}'
示例4: test_remove_nonexistent_json_post_data_parameters
# 需要导入模块: from vcr.request import Request [as 别名]
# 或者: from vcr.request.Request import headers['Content-Type'] [as 别名]
def test_remove_nonexistent_json_post_data_parameters():
body = b'{}'
request = Request('POST', 'http://google.com', body, {})
request.headers['Content-Type'] = 'application/json'
remove_post_data_parameters(request, ['id'])
assert request.body == b'{}'