当前位置: 首页>>代码示例>>Python>>正文


Python Mock.headers方法代码示例

本文整理汇总了Python中unittest.mock.Mock.headers方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.headers方法的具体用法?Python Mock.headers怎么用?Python Mock.headers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在unittest.mock.Mock的用法示例。


在下文中一共展示了Mock.headers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_guess_user_ip_from_request

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import headers [as 别名]
def test_guess_user_ip_from_request():
    handler = SentryExceptionHandler(Mock())
    request = Mock()

    request.env = {}
    request.headers = {}
    assert handler.guess_user_ip_from_request(request) == '127.0.0.1'

    request.env = {'REMOTE_ADDR': '192.168.99.100'}
    assert handler.guess_user_ip_from_request(request) == '192.168.99.100'

    request.headers = {'X-FORWARDED-FOR': '10.0.8.2'}
    assert handler.guess_user_ip_from_request(request) == '10.0.8.2'
开发者ID:conceptsandtraining,项目名称:hug_sentry,代码行数:15,代码来源:test_sentry_handler.py

示例2: test_wants_metadata

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import headers [as 别名]
    def test_wants_metadata(self):

        request = Mock()
        for metadata_state in (True, False):
            request.headers = {
                'Accept': 'application/json;metadata={}'.format(str(metadata_state))
            }
            assert_equal(wants_metadata(request), metadata_state)

            request.headers = {
                'Accept': 'application/json;metadata={}'.format(str(metadata_state).lower())
            }
            assert_equal(wants_metadata(request), metadata_state)

        request.headers = {'Accept:' 'application/json;metadata=wibble'}
        assert_equal(wants_metadata(request), False)
开发者ID:percival-detector,项目名称:odin,代码行数:18,代码来源:test_adapter.py

示例3: setUp

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import headers [as 别名]
 def setUp(self):
     response = Mock()
     response.content = json.dumps({'status': 'ok'})
     response.headers = {'Content-Type': 'application/json'}
     response.ok = True
     response.status_code = requests.codes.ok
     self.response = response
开发者ID:maxcountryman,项目名称:rauth,代码行数:9,代码来源:base.py

示例4: request_mock

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import headers [as 别名]
def request_mock():
    request = Mock()
    request.method = 'GET'
    request.headers = {'Accept': 'appliaction/json'}
    request.body = None
    request.uri = '/'
    return request
开发者ID:2gis,项目名称:httpsrvvcr,代码行数:9,代码来源:recorder_test.py

示例5: test_decorated_method_bad_accept

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import headers [as 别名]
    def test_decorated_method_bad_accept(self):

        request = Mock()
        request.data = 'Some text'
        request.headers = {'Accept': 'application/hdf', 'Content-Type': 'text/plain'}

        response = self.decorated_method(self.path, request)
        assert_equal(response.status_code, 406)
        assert_equal(response.data, 'Requested content types not supported')
开发者ID:jamesh1999,项目名称:odin,代码行数:11,代码来源:test_adapter.py

示例6: test_decorated_method_bad_content

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import headers [as 别名]
    def test_decorated_method_bad_content(self):

        json_request = Mock()
        json_request.data = 'wibble'
        json_request.headers = {'Accept': 'application/json', 'Content-Type': 'application/hdf'}

        response = self.decorated_method(self.path, json_request)
        assert_equal(response.status_code, 415)
        assert_equal(response.data, 'Request content type (application/hdf) not supported')
开发者ID:jamesh1999,项目名称:odin,代码行数:11,代码来源:test_adapter.py

示例7: test_decorated_method_no_accept_no_default

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import headers [as 别名]
    def test_decorated_method_no_accept_no_default(self):

        request = Mock()
        request.data = 'Some text'
        request.headers = {'Content-Type': 'text/plain'}

        response = self.decorated_method_without_default(self.path, request)
        assert_equal(response.status_code, self.response_code)
        assert_equal(response.content_type, self.response_type_plain)
        assert_equal(response.data, self.response_data_plain)
开发者ID:jamesh1999,项目名称:odin,代码行数:12,代码来源:test_adapter.py

示例8: test_decorated_method_no_default_json

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import headers [as 别名]
    def test_decorated_method_no_default_json(self):

        request = Mock()
        request.data = '{\'request\' : 1234}'
        request.headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}

        response = self.decorated_method_without_default(self.path, request)
        assert_equal(response.status_code, self.response_code)
        assert_equal(response.content_type, self.response_type_json)
        assert_equal(response.data, self.response_data_json)
开发者ID:jamesh1999,项目名称:odin,代码行数:12,代码来源:test_adapter.py

示例9: test_decorated_method_plaintext

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import headers [as 别名]
    def test_decorated_method_plaintext(self):

        plain_request = Mock()
        plain_request.data = 'Simple plain text request'
        plain_request.headers = {'Accept': 'text/plain', 'Content-Type': 'text/plain'}

        response = self.decorated_method(self.path, plain_request)
        assert_equal(response.status_code, self.response_code)
        assert_equal(response.content_type, self.response_type_plain)
        assert_equal(response.data, self.response_data_plain)
开发者ID:jamesh1999,项目名称:odin,代码行数:12,代码来源:test_adapter.py

示例10: mock_urlopen

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import headers [as 别名]
 def mock_urlopen(url, data=None):
     headers = {"Replay-Nonce": "MockNonce"}
     response = Mock()
     response.status = 200
     if url.endswith("/new-reg"):
         headers["Location"] = "mock://reg-location"
         response.status = 201
     response.headers = headers
     response.read = Mock(return_value=b'{"mock": true}')
     return response
开发者ID:drdaeman,项目名称:le_client,代码行数:12,代码来源:tests.py

示例11: test_smartapp_webhook

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import headers [as 别名]
async def test_smartapp_webhook(hass):
    """Test the smartapp webhook calls the manager."""
    manager = Mock()
    manager.handle_request = Mock()
    manager.handle_request.return_value = mock_coro(return_value={})
    hass.data[DOMAIN][DATA_MANAGER] = manager
    request = Mock()
    request.headers = []
    request.json.return_value = mock_coro(return_value={})
    result = await smartapp.smartapp_webhook(hass, '', request)

    assert result.body == b'{}'
开发者ID:Martwall,项目名称:home-assistant,代码行数:14,代码来源:test_smartapp.py

示例12: requests_factory

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import headers [as 别名]
def requests_factory(text='some text',
                     location='some location',
                     content=b'some content'):
    requests = Mock()

    get_response = Mock()
    get_response.text = text
    get_response.content = content

    head_response = Mock()
    head_response.headers = {'Location': location}

    requests.get = Mock(return_value=get_response)
    requests.head = Mock(return_value=head_response)

    return requests
开发者ID:dduong42,项目名称:Booksee,代码行数:18,代码来源:factories.py

示例13: test_adapter_put_bad_accept_type

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import headers [as 别名]
 def test_adapter_put_bad_accept_type(self):
     bad_request = Mock()
     bad_request.headers = {'Accept': 'text/plain'}
     response = self.adapter.put(self.path, bad_request)
     assert_equal(response.data, 'Requested content types not supported')
     assert_equal(response.status_code, 406)
开发者ID:jamesh1999,项目名称:odin,代码行数:8,代码来源:test_dummy.py

示例14: test_adapter_put_bad_content_type

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import headers [as 别名]
 def test_adapter_put_bad_content_type(self):
     bad_request = Mock()
     bad_request.headers = {'Content-Type': 'text/plain'}
     response = self.adapter.put(self.path, bad_request)
     assert_equal(response.data, 'Request content type (text/plain) not supported')
     assert_equal(response.status_code, 415)
开发者ID:jamesh1999,项目名称:odin,代码行数:8,代码来源:test_dummy.py

示例15: response_mock

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import headers [as 别名]
def response_mock():
    response = Mock()
    response.code = 200
    response.body = b'Response body'
    response.headers = {'Content-Type': 'text/plain', 'Content-Length': 100}
    return response
开发者ID:2gis,项目名称:httpsrvvcr,代码行数:8,代码来源:recorder_test.py


注:本文中的unittest.mock.Mock.headers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。