本文整理匯總了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'{}'