本文整理汇总了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')])
示例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')
示例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()])
示例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")])
示例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")])
示例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")])
示例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)
示例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()])
示例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)])
示例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")])
示例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'),
])
示例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'])])