當前位置: 首頁>>代碼示例>>Python>>正文


Python Request.headers['Content-Type']方法代碼示例

本文整理匯總了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
開發者ID:jayvdb,項目名稱:vcrpy,代碼行數:10,代碼來源:test_filters.py

示例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
開發者ID:Bjwebb,項目名稱:vcrpy,代碼行數:23,代碼來源:test_filters.py

示例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'{}'
開發者ID:Bjwebb,項目名稱:vcrpy,代碼行數:8,代碼來源:test_filters.py

示例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'{}'
開發者ID:jayvdb,項目名稱:vcrpy,代碼行數:8,代碼來源:test_filters.py


注:本文中的vcr.request.Request.headers['Content-Type']方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。