本文整理汇总了Python中mock.Mock.ok方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.ok方法的具体用法?Python Mock.ok怎么用?Python Mock.ok使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.Mock
的用法示例。
在下文中一共展示了Mock.ok方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_wait_for_volume_status_good_response_code_bad_status
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import ok [as 别名]
def test_wait_for_volume_status_good_response_code_bad_status(self):
volume_name = 'mock_volume'
expected_status = 'available'
timeout = 10
poll_rate = 2
client = Mock(spec=VolumesClient)
config = Mock(spec=VolumesAPIConfig)
config.volume_status_poll_frequency = 1
volume_model = Mock(spec=VolumeResponse)
volume_model.status = expected_status
response = Mock(spec=Response)
response.ok = True
response.entity = volume_model
client.get_volume_info = MagicMock(
return_value=response)
behavior = VolumesAPI_Behaviors(client, config)
resp = behavior.wait_for_volume_status(
volume_name, expected_status, timeout, poll_rate=poll_rate)
self.assertIsNone(resp)
示例2: test_wait_for_volume_status_good_response_code_configured_poll_rate
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import ok [as 别名]
def test_wait_for_volume_status_good_response_code_configured_poll_rate(
self):
client = Mock(spec=VolumesClient)
config = Mock(spec=VolumesAPIConfig)
config.volume_status_poll_frequency = 1
volume_model = Mock(spec=VolumeResponse)
volume_model.status = self.defaults.expected_status
response = Mock(spec=Response)
response.ok = True
response.entity = volume_model
client.get_volume_info = MagicMock(
return_value=response)
behavior = VolumesAPI_Behaviors(client, config)
resp = behavior.wait_for_volume_status(
self.defaults.volume_name, self.defaults.expected_status,
self.defaults.timeout)
self.assertIsNone(resp)
示例3: test_wait_for_snapshot_status_good_response_code_config_wait_period
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import ok [as 别名]
def test_wait_for_snapshot_status_good_response_code_config_wait_period(
self):
client = Mock(spec=VolumesClient)
config = Mock(spec=VolumesAPIConfig)
config.snapshot_status_poll_frequency = 1
snapshot_model = Mock(spec=VolumeSnapshotResponse)
snapshot_model.status = self.defaults.expected_status
response = Mock(spec=Response)
response.ok = True
response.entity = snapshot_model
client.get_snapshot_info = MagicMock(
return_value=response)
behavior = VolumesAPI_Behaviors(client, config)
resp = behavior.wait_for_snapshot_status(
self.defaults.snapshot_name, self.defaults.expected_status,
self.defaults.timeout)
self.assertIsNone(resp)
示例4: test_wait_for_snapshot_status_good_response_and_entity_bad_status
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import ok [as 别名]
def test_wait_for_snapshot_status_good_response_and_entity_bad_status(
self):
recieved_status = 'error'
client = Mock(spec=VolumesClient)
config = Mock(spec=VolumesAPIConfig)
config.snapshot_status_poll_frequency = 1
snapshot_model = Mock(spec=VolumeSnapshotResponse)
snapshot_model.status = recieved_status
response = Mock(spec=Response)
response.ok = True
response.entity = snapshot_model
client.get_snapshot_info = MagicMock(
return_value=response)
behavior = VolumesAPI_Behaviors(client, config)
with self.assertRaises(VolumesAPIBehaviorException):
behavior.wait_for_snapshot_status(
self.defaults.snapshot_name, self.defaults.expected_status,
self.defaults.timeout, poll_rate=self.defaults.poll_rate)
示例5: setUp
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import ok [as 别名]
def setUp(self):
# mock request object
request = Request()
request.method = "GET"
request.url = "http://example.com/"
request.params = {}
request.data = {}
request.params_and_data = {}
self.request = request
# mock response object
response = Mock()
response.content = "access_token=321"
response.headers = {"content-type": "text/html; charset=UTF-8"}
response.ok = True
response.status_code = 200
self.response = response
# mock raise_for_status with an error
def raise_for_status():
raise Exception("Response not OK!")
self.raise_for_status = raise_for_status
# mock hook object
hook = Mock()
hook.consumer_key = "123"
hook.consumer_secret = "456"
hook.access_token = "321"
hook.access_token_secret = "654"
self.hook = hook
示例6: test_api_get_fail
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import ok [as 别名]
def test_api_get_fail(self, mock_login, mock_get, mock_headers):
"""
Test ._api_get() raises an exception
"""
mock_login.return_value = self.account_id
mock_headers.return_value = {}
mock_response = Mock(spec=requests.Response)
mock_response.status_code = 500
mock_response.text = "Server error"
mock_response.ok = False
mock_get.return_value = mock_response
url = 'https://logentries.com/app/{account_id}/rest/tag'.format(account_id=self.account_id)
alert = SpecialAlertBase(self.username, self.password)
with self.assertRaises(ServerException):
alert._api_get(
url=url,
data={'k': 'v'}
)
mock_get.assert_called_once_with(
alert.session,
url=url,
headers={},
data={'k': 'v'}
)
示例7: non_json_response
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import ok [as 别名]
def non_json_response():
mock_network_response = Mock(DefaultNetworkResponse)
mock_network_response.content = b''
mock_network_response.ok = True
mock_network_response.status_code = 200
mock_network_response.json.side_effect = ValueError('No JSON object could be decoded')
return mock_network_response
示例8: test_get_hash_fail
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import ok [as 别名]
def test_get_hash_fail(self, m_get, m_get_gitbuilder_url):
m_get_gitbuilder_url.return_value = "http://baseurl.com"
mock_resp = Mock()
mock_resp.ok = False
m_get.return_value = mock_resp
result = suite.get_hash()
assert result is None
示例9: __one_bad_two_ok
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import ok [as 别名]
def __one_bad_two_ok(*args):
response = Mock()
response.ok = args[0] == 'http://example.com/oembed2'
response.text = 'hello, world'
response.headers = {'content-type': 'application/json'}
return response
示例10: generic_successful_response
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import ok [as 别名]
def generic_successful_response():
mock_network_response = Mock(DefaultNetworkResponse)
mock_network_response.content = b'{"message": "success"}'
mock_network_response.status_code = 200
mock_network_response.ok = True
mock_network_response.raw = Mock()
return mock_network_response
示例11: test_arbitrary_member
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import ok [as 别名]
def test_arbitrary_member(self, mock_request):
mock_response = Mock()
mock_response.ok = True
mock_response.content = json.dumps({"short_codes": []})
mock_request.return_value = mock_response
self.assertEqual([], self.client.sms.short_codes.list())
mock_request.assert_called_once_with("GET", ANY, params=ANY, auth=AUTH, timeout=sentinel.timeout)
示例12: test_download_graphs
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import ok [as 别名]
def test_download_graphs(self):
dest_dir = '/fake/path'
obj = self.klass(
hosts=['host1'],
time_from='now-3h',
dest_dir=dest_dir,
)
_format = obj.graph_defaults.get('format')
with patch('teuthology.task.pcp.requests.get', create=True) as m_get:
m_resp = Mock()
m_resp.ok = True
m_get.return_value = m_resp
with patch('teuthology.task.pcp.open', create=True) as m_open:
m_open.return_value = MagicMock(spec=file)
obj.download_graphs()
expected_filenames = []
for metric in obj.metrics:
expected_filenames.append(
"{}.{}".format(
os.path.join(
dest_dir,
obj._sanitize_metric_name(metric),
),
_format,
)
)
graph_filenames = []
for metric in obj.graphs.keys():
graph_filenames.append(obj.graphs[metric]['file'])
assert sorted(graph_filenames) == sorted(expected_filenames)
示例13: test_package_version_for_hash
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import ok [as 别名]
def test_package_version_for_hash(self, m_get):
mock_resp = Mock()
mock_resp.ok = True
mock_resp.text = "the_version"
m_get.return_value = mock_resp
result = util.package_version_for_hash("hash")
assert result == "the_version"
示例14: test_get_hash_success
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import ok [as 别名]
def test_get_hash_success(self, m_get):
mock_resp = Mock()
mock_resp.ok = True
mock_resp.text = "the_hash"
m_get.return_value = mock_resp
result = util.get_gitbuilder_hash()
assert result == "the_hash"
示例15: test_get_package_sha1_fetched_found
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import ok [as 别名]
def test_get_package_sha1_fetched_found(self):
resp = Mock()
resp.ok = True
resp.text = "the_sha1"
self.m_get.return_value = resp
super(TestGitbuilderProject, self)\
.test_get_package_sha1_fetched_found()