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


Python MagicMock.has_calls方法代码示例

本文整理汇总了Python中mock.MagicMock.has_calls方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.has_calls方法的具体用法?Python MagicMock.has_calls怎么用?Python MagicMock.has_calls使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mock.MagicMock的用法示例。


在下文中一共展示了MagicMock.has_calls方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_list_remove

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import has_calls [as 别名]
  def test_list_remove(self):
    key = "my_awesome_key"

    mock_file = MagicMock()
    mock_file.__str__ = lambda x: key
    mock_file.exists.return_value = True
    mock_path = MagicMock(return_value=mock_file)

    mock_hashlib = MagicMock()
    mock_hashlib.md5.hexdigest.return_value = "HASH"

    mock_user = MagicMock()
    mock_user.path = "path"
    mock_user.name = "test"

    with patch.multiple('models.lists.keys', Path=mock_path,
                        hashlib=mock_hashlib):
      keys = ListKeys(mock_user)

      keys.remove(key)

      mock_path.has_calls([
          call("path", 'keydir', 'HASH'),
          call(mock_file, "test.pub"),
      ])

      commit_message = "Removed key for user test"
      mock_user.git.commit.has_calls([call(["my_awesome_key"],
                                           commit_message,
                                           action='remove')])
开发者ID:bcersows,项目名称:pyolite,代码行数:32,代码来源:test_keys.py

示例2: test_if_we_commit_after_a_key_append

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import has_calls [as 别名]
  def test_if_we_commit_after_a_key_append(self):
    key_path = "tests/fixtures/simple_key.pub"

    mock_file = MagicMock()
    mock_file.__str__ = lambda x: key_path
    mock_path = MagicMock(return_value=mock_file)

    mock_hashlib = MagicMock()
    mock_hashlib.md5.hexdigest.return_value = "HASH"

    mock_user = MagicMock()
    mock_user.path = "path"
    mock_user.name = "test"

    with patch.multiple('models.lists.keys', Path=mock_path,
                        hashlib=mock_hashlib):
      keys = ListKeys(mock_user)

      keys.append(key_path)

    mock_path.has_calls([
        call("path", key_path),
        call("path", "keydir", "HASH"),
        call(mock_file, "test"),
    ])

    eq_(mock_file.isfile.call_count, 1)
    eq_(mock_file.mkdir.call_count, 1)
    mock_file.write_file.assert_called_once_with('nothing to see here\n')
开发者ID:bcersows,项目名称:pyolite,代码行数:31,代码来源:test_keys.py

示例3: test_get_transaction_from_token

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import has_calls [as 别名]
    def test_get_transaction_from_token(self):
        transaction = TransactionFactory()

        mocked_view = MagicMock()
        token = _get_jwt_token(transaction)

        self.assertEquals(get_transaction_from_token(mocked_view)(None, token),
                          mocked_view())
        mocked_view.has_calls([call(None, transaction, False), call()])
开发者ID:PressLabs,项目名称:silver,代码行数:11,代码来源:test_payments_util.py

示例4: test_get_blob_data

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import has_calls [as 别名]
    def test_get_blob_data(self):
        mocked_repo = MagicMock()
        mocked_git_object = MagicMock()
        mocked_git_object().data = "some data"

        repo = Repository(mocked_repo)
        repo.get_git_object = mocked_git_object

        assert repo.get_blob_data("tree", "path") == "some data"
        mocked_git_object.has_calls([call("tree", "path")])
开发者ID:krodyrobi,项目名称:gitfs,代码行数:12,代码来源:test_repository.py

示例5: test_get_blob_size

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import has_calls [as 别名]
    def test_get_blob_size(self):
        mocked_repo = MagicMock()
        mocked_git_object = MagicMock()
        mocked_git_object().size = 42

        repo = Repository(mocked_repo)
        repo.get_git_object = mocked_git_object

        assert repo.get_blob_size("tree", "path") == 42
        mocked_git_object.has_calls([call("tree", "path")])
开发者ID:krodyrobi,项目名称:gitfs,代码行数:12,代码来源:test_repository.py

示例6: test_list_addition

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import has_calls [as 别名]
    def test_list_addition(self):
        mock_user = MagicMock()
        mock_append = MagicMock()

        keys = ListKeys(mock_user)
        keys.append = mock_append

        keys = keys + ["first_key", "second_key"]

        mock_append.has_calls([call("first_key"), call("second_key")])
开发者ID:Codevolve,项目名称:pyolite,代码行数:12,代码来源:test_keys.py

示例7: test_truncate

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import has_calls [as 别名]
    def test_truncate(self):
        mocked_open = MagicMock()
        mocked_file = MagicMock(spec=file)

        with patch('gitfs.views.passthrough.open', create=True) as mocked_open:
            mocked_open().__enter__.return_value = mocked_file
            view = PassthroughView(repo=self.repo, repo_path=self.repo_path)
            view.truncate("/magic/path", 0, 0)

            mocked_open.has_calls([call("/the/root/path/magic/path", "r+")])
            mocked_file.truncate.assert_called_once_with(0)
开发者ID:AlexSnet,项目名称:gitfs,代码行数:13,代码来源:test_passthrough.py

示例8: test_get_transaction_from_expired_token

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import has_calls [as 别名]
    def test_get_transaction_from_expired_token(self):
        transaction = TransactionFactory()

        mocked_view = MagicMock()
        with patch('silver.utils.payments.datetime') as mocked_datetime:
            mocked_datetime.utcnow.return_value = datetime.utcnow() - timedelta(days=2 * 365)
            token = _get_jwt_token(transaction)

        self.assertEquals(get_transaction_from_token(mocked_view)(None, token),
                          mocked_view())
        mocked_view.has_calls([call(None, transaction, True), call()])
开发者ID:PressLabs,项目名称:silver,代码行数:13,代码来源:test_payments_util.py

示例9: test_rename

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import has_calls [as 别名]
    def test_rename(self):
        mocked_rename = MagicMock()
        mocked_rename.return_value = "magic"

        with patch('gitfs.views.passthrough.os.rename', mocked_rename):
            view = PassthroughView(repo=self.repo, repo_path=self.repo_path)
            result = view.rename("/magic/path", "/magic/new")

            assert result == "magic"
            old = '/the/root/path/magic/path'
            new = '/the/root/path/magic/new'
            mocked_rename.has_calls([call(old), call(new)])
开发者ID:AlexSnet,项目名称:gitfs,代码行数:14,代码来源:test_passthrough.py

示例10: test_retry

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import has_calls [as 别名]
    def test_retry(self):
        mocked_time = MagicMock()
        mocked_method = MagicMock(side_effect=ValueError)

        with patch.multiple('gitfs.utils.decorators.retry', wraps=MockedWraps,
                            time=mocked_time):
            again = retry(times=3)

            with pytest.raises(ValueError):
                again(mocked_method)("arg", kwarg="kwarg")

            mocked_time.sleep.has_calls([call(3), call(3), call(1)])
            mocked_method.has_calls([call("arg", kwarg="kwarg")])
开发者ID:HWL-RobAt,项目名称:gitfs,代码行数:15,代码来源:test_decorators.py

示例11: test_list_addition

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import has_calls [as 别名]
  def test_list_addition(self):
    mock_user = MagicMock()
    mock_append = MagicMock()

    keys = ListKeys(mock_user)
    keys.append = mock_append

    keys = keys + ['first_key', 'second_key']

    mock_append.has_calls([
        call('first_key'),
        call('second_key'),
    ])
开发者ID:bcersows,项目名称:pyolite,代码行数:15,代码来源:test_keys.py

示例12: test_stage

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import has_calls [as 别名]
    def test_stage(self):
        mocked_repo = MagicMock()
        mocked_sanitize = MagicMock()
        mocked_queue = MagicMock()

        mocked_sanitize.return_value = ["to-stage"]

        current = CurrentView(repo=mocked_repo,
                              repo_path="repo_path",
                              queue=mocked_queue, ignore=CachedIgnore("f"))
        current._sanitize = mocked_sanitize
        current._stage("message", ["add"], ["remove"])

        mocked_queue.commit.assert_called_once_with(add=['to-stage'],
                                                    remove=['to-stage'],
                                                    message="message")
        mocked_repo.index.add.assert_called_once_with(["to-stage"])
        mocked_repo.index.remove.assert_called_once_with(["to-stage"])

        mocked_sanitize.has_calls([call(['add']), call(['remove'])])
开发者ID:calind,项目名称:gitfs,代码行数:22,代码来源:test_current.py


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