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


Python MagicMock.ok方法代码示例

本文整理汇总了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)
开发者ID:redshiftzero,项目名称:pgpbuddy,代码行数:11,代码来源:mock_gpg.py

示例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)
开发者ID:redshiftzero,项目名称:pgpbuddy,代码行数:11,代码来源:mock_gpg.py

示例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
     )
开发者ID:CDE-UNIBE,项目名称:qcat,代码行数:11,代码来源:test_client.py

示例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
     )
开发者ID:CDE-UNIBE,项目名称:qcat,代码行数:11,代码来源:test_client.py

示例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')
开发者ID:box,项目名称:ClusterRunner,代码行数:17,代码来源:test_cluster_slave.py

示例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() == ''
开发者ID:alterrebe,项目名称:senza,代码行数:26,代码来源:test_templates.py

示例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
开发者ID:box,项目名称:ClusterRunner,代码行数:7,代码来源:test_cluster_slave.py


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