本文整理汇总了Python中mock.mock.MagicMock.headers方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.headers方法的具体用法?Python MagicMock.headers怎么用?Python MagicMock.headers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.headers方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_request
# 需要导入模块: from mock.mock import MagicMock [as 别名]
# 或者: from mock.mock.MagicMock import headers [as 别名]
def test_request(self, connect_mock):
httpsconn_mock = MagicMock(create = True)
self.cachedHTTPSConnection.httpsconn = httpsconn_mock
dummy_request = MagicMock(create = True)
dummy_request.get_method.return_value = "dummy_get_method"
dummy_request.get_full_url.return_value = "dummy_full_url"
dummy_request.get_data.return_value = "dummy_get_data"
dummy_request.headers = "dummy_headers"
responce_mock = MagicMock(create = True)
responce_mock.read.return_value = "dummy responce"
httpsconn_mock.getresponse.return_value = responce_mock
# Testing normal case
responce = self.cachedHTTPSConnection.request(dummy_request)
self.assertEqual(responce, responce_mock.read.return_value)
httpsconn_mock.request.assert_called_once_with(
dummy_request.get_method.return_value,
dummy_request.get_full_url.return_value,
dummy_request.get_data.return_value,
dummy_request.headers)
# Testing case of exception
try:
def side_eff():
raise Exception("Dummy exception")
httpsconn_mock.read.side_effect = side_eff
responce = self.cachedHTTPSConnection.request(dummy_request)
self.fail("Should raise IOError")
except Exception, err:
# Expected
pass