本文整理汇总了Python中unittest.mock.MagicMock.ok方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.ok方法的具体用法?Python MagicMock.ok怎么用?Python MagicMock.ok使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.ok方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mock_encrypt
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import ok [as 别名]
def mock_encrypt(success):
if success:
result = MagicMock(gnupg.Crypt)
result.ok = True
result.data = b"blabla"
else:
result = MagicMock(gnupg.Crypt)
result.ok = False
return MagicMock(return_value=result)
示例2: mock_sign
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import ok [as 别名]
def mock_sign(success):
if success:
result = MagicMock(gnupg.Sign)
result.ok = True
result.data = b'ladida'
else:
result = MagicMock(gnupg.Sign)
result.ok = False
return MagicMock(return_value=result)
示例3: test_search_users
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import ok [as 别名]
def test_search_users(self, mock_get, mock_request_post):
request_post = MagicMock()
request_post.status_code = 200
request_post.ok = PropertyMock(return_value=True)
request_post.json = lambda: dict(success=True)
mock_request_post.return_value = request_post
self.assertIsInstance(
self.remote_user_client.search_users('foo'), dict
)
示例4: test_get_user_info
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import ok [as 别名]
def test_get_user_info(self, mock_request_get):
api_request = MagicMock()
api_request.status_code = 200
api_request.ok = PropertyMock(return_value=True)
api_request.json = lambda: dict(success=True)
mock_request_get.return_value = api_request
self.assertIsInstance(
self.remote_user_client.get_user_information('123'), dict
)
示例5: test_slave_dies_on_http_404_from_master
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import ok [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')
示例6: test_get_latest_image
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import ok [as 别名]
def test_get_latest_image(monkeypatch):
mock_response = MagicMock()
mock_response.json.return_value = [{'created': '2016-06-09T07:12:34.413Z',
'created_by': 'someone',
'name': '0.90-p7'},
{'created': '2016-06-28T10:19:47.788Z',
'created_by': 'someone',
'name': '0.90-p8'},
{'created': '2016-07-01T06:58:32.956Z',
'created_by': 'someone',
'name': '0.90-test'},
{'created': '2016-07-12T06:58:32.956Z',
'created_by': 'someone',
'name': '0.91-SNAPSHOT'}]
mock_get = MagicMock()
mock_get.return_value = mock_response
monkeypatch.setattr('requests.get', mock_get)
assert get_latest_image() == 'registry.opensource.zalan.do/acid/spilo-9.5:0.90-test'
mock_response.ok = False
assert get_latest_image() == ''
示例7: _get_success_mock_response
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import ok [as 别名]
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