本文整理汇总了Python中requests.models方法的典型用法代码示例。如果您正苦于以下问题:Python requests.models方法的具体用法?Python requests.models怎么用?Python requests.models使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类requests
的用法示例。
在下文中一共展示了requests.models方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _mock_network_post_and_put
# 需要导入模块: import requests [as 别名]
# 或者: from requests import models [as 别名]
def _mock_network_post_and_put(self, expected_results_api_url, expected_idle_api_url):
# Since subjob execution and teardown is async, we use Events to tell our test when each thread has completed.
subjob_done_event = Event()
setup_done_event = Event()
teardown_done_event = Event()
def _get_success_mock_response():
mock_response = MagicMock(spec=requests.models.Response, create=True)
mock_response.status_code = http.client.OK
mock_response.ok = True
return mock_response
def fake_network_post(url, *args, **kwargs):
if url == expected_results_api_url:
subjob_done_event.set() # Consider subjob finished once code posts to results url.
return _get_success_mock_response()
def fake_network_put(url, request_params, **kwargs):
if url == expected_idle_api_url:
if request_params['slave']['state'] == SlaveState.SETUP_COMPLETED:
setup_done_event.set()
elif request_params['slave']['state'] == SlaveState.IDLE:
teardown_done_event.set()
return _get_success_mock_response()
self.mock_network.post = fake_network_post
self.mock_network.post_with_digest = fake_network_post
self.mock_network.put = fake_network_put
self.mock_network.put_with_digest = fake_network_put
return subjob_done_event, teardown_done_event, setup_done_event
示例2: test_slave_dies_on_http_404_from_master
# 需要导入模块: import requests [as 别名]
# 或者: from requests import models [as 别名]
def test_slave_dies_on_http_404_from_master(self):
slave = self._create_cluster_slave()
slave.connect_to_master(self._FAKE_MASTER_URL)
mock_response = MagicMock(spec=requests.models.Response, create=True)
mock_response.ok = False
mock_response.status_code = http.client.NOT_FOUND
self.mock_network.post_with_digest.return_value = mock_response
slave._run_heartbeat()
self.mock_network.post_with_digest.assert_called_once_with(
ANY,request_params={'slave': {'heartbeat': True}}, secret=ANY)
self.assertEqual(self._mock_sys.exit.call_count, 1,
'slave dies when it receives HTTP 404 from master')
示例3: test_slave_dies_if_master_reponds_with_is_alive_false
# 需要导入模块: import requests [as 别名]
# 或者: from requests import models [as 别名]
def test_slave_dies_if_master_reponds_with_is_alive_false(self):
slave = self._create_cluster_slave()
slave.connect_to_master(self._FAKE_MASTER_URL)
mock_response = MagicMock(spec=requests.models.Response, create=True)
mock_response.json.return_value = {'is_alive': False}
self.mock_network.post_with_digest.return_value = mock_response
slave._run_heartbeat()
self.mock_network.post_with_digest.assert_called_once_with(
ANY,request_params={'slave': {'heartbeat': True}}, secret=ANY)
self.assertEqual(self._mock_sys.exit.call_count, 1,
'slave dies when master responds with is_alive = False')