本文整理汇总了Python中mock.MagicMock.path方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.path方法的具体用法?Python MagicMock.path怎么用?Python MagicMock.path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.path方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_user_edit_permissions
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import path [as 别名]
def test_user_edit_permissions(self):
mocked_repo = MagicMock()
mocked_repository = MagicMock()
mocked_user = MagicMock()
mock_single_user = MagicMock()
mock_single_user.name = 'another_user'
mock_single_user.__str__ = lambda x: 'another_user'
mocked_repository.name = 'test_repo'
mocked_repository.path = 'path'
mocked_user.get.return_value = mock_single_user
mocked_repo.users = ['user']
with patch.multiple('models.lists.users',
Repo=MagicMock(return_value=mocked_repo),
User=mocked_user):
repo_users = ListUsers(mocked_repository)
repo_users.edit('test', 'R')
pattern = r'(\s*)([RW+DC]*)(\s*)=(\s*)%s' % 'another_user'
string = r"\n %s = %s" % ('R', 'another_user')
mocked_repo.replace.assert_called_once_with(pattern, string)
message = "User another_user has R permission for repository test_repo"
mocked_repository.git.commit.has_calls([call(['conf'], message)])
示例2: test_it_should_add_a_new_user_to_repo_if_is_valid
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import path [as 别名]
def test_it_should_add_a_new_user_to_repo_if_is_valid(self):
mocked_repo = MagicMock()
mocked_repository = MagicMock()
mocked_user = MagicMock()
mock_single_user = MagicMock()
mock_single_user.name = 'another_user'
mock_single_user.__str__ = lambda x: 'another_user'
mocked_repository.name = 'test_repo'
mocked_repository.path = 'path'
mocked_user.get.return_value = mock_single_user
mocked_repo.users = ['user']
with patch.multiple('models.lists.users',
Repo=MagicMock(return_value=mocked_repo),
User=mocked_user):
repo_users = ListUsers(mocked_repository)
repo_users.add('test', 'RW+')
content = ' RW+ = another_user\n'
mocked_repo.write.assert_called_once_with(content)
message = 'User another_user added to repo test_repo ' \
'with permissions: RW+'
mocked_repository.git.commit.has_calls([call(['conf'], message)])
示例3: test_user_removing
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import path [as 别名]
def test_user_removing(self):
mocked_repo = MagicMock()
mocked_repository = MagicMock()
mocked_user = MagicMock()
mock_single_user = MagicMock()
mock_single_user.name = 'another_user'
mock_single_user.__str__ = lambda x: 'another_user'
mocked_repository.name = 'test_repo'
mocked_repository.path = 'path'
mocked_user.get.return_value = mock_single_user
mocked_repo.users = ['user']
with patch.multiple('models.lists.users',
Repo=MagicMock(return_value=mocked_repo),
User=mocked_user):
repo_users = ListUsers(mocked_repository)
repo_users.remove('test')
pattern = r'(\s*)([RW+DC]*)(\s*)=(\s*)%s' % 'another_user'
mocked_repo.replace.assert_called_once_with(pattern, "")
message = "Deleted user another_user from repository test_repo"
mocked_repository.git.commit.has_calls([call(['conf'], message)])
示例4: test_users_set
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import path [as 别名]
def test_users_set(self):
mocked_repo = MagicMock()
mocked_repository = MagicMock(config="")
mocked_repository.get_config.return_value = ""
mocked_user = MagicMock()
mock_single_user = MagicMock()
mock_single_user.name = 'user'
mocked_repository.name = 'test_repo'
mocked_repository.path = 'path'
mocked_user.get.return_value = mock_single_user
with patch.multiple('pyolite.models.lists.users',
Repo=MagicMock(return_value=mocked_repo),
User=mocked_user):
repo_users = ListUsers(mocked_repository)
repo_users.set((('mocked', 'R'), ('mocked', 'RW+')))
serialized_users = "repo test_repo\n R = user\n" \
" RW+ = user\n"
mocked_repo.overwrite.assert_called_once_with(serialized_users)
message = "Initialized repository test_repo with users: test, user"
mocked_repository.git.commit.has_calls([call(['conf'], message)])
示例5: test_if_we_commit_after_a_key_append
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import path [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')
示例6: test_generate_deploy_script_withRestartOption_ShouldPrintStopStart
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import path [as 别名]
def test_generate_deploy_script_withRestartOption_ShouldPrintStopStart(self):
expected_script = """\
# Rollback information saved in {0}rollback-info_test
:stop-servers()
undeploy abc-v1.0.0 --keep-content --all-relevant-server-groups
deploy {1} --runtime-name=abc.war --name=abc-v1.2.3 --server-groups=group
:start-servers()\
""".format(current_dir + os.sep,
current_dir + os.sep + "v1.2.3" + os.sep + "abc.war")
args = MagicMock()
args.path = current_dir + os.sep + "v1.2.3"
args.undeploy_pattern = None
args.undeploy_tag = None
args.restart = True
mock_controller = MagicMock()
mock_controller.domain = True
deploy.common.initialize_controller = MagicMock(
return_value=mock_controller
)
script = deploy.generate_deploy_script(args)
self.assertEqual(script, expected_script)
示例7: TestCommandParsing
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import path [as 别名]
def TestCommandParsing(self):
request = MagicMock()
request.path = "/test"
request.query = "item1=value1"
request.remote_ip = "1.2.3.4"
request.method = "PUT"
request.headers = {
'User': 'test_user',
'Creation-Time': 'test_time',
'User-Agent': 'test_user_agent'
}
request.body="item2=value2&item2=value3&item2=value4"
self.command = Command(request)
self.assertEqual(self.command.command_name, 'test')
self.assertEqual(self.command.command_type, 'PUT')
self.assertEqual(self.command.has_param('item1'), True)
self.assertEqual(self.command.has_param('item2'), True)
self.assertEqual(self.command.has_param('item3'), False)
self.assertEqual(self.command.get_param('item1'), 'value1')
self.assertEqual('value2' in self.command.get_param('item2'), True)
self.assertEqual('value3' in self.command.get_param('item2'), True)
self.assertEqual('value4' in self.command.get_param('item2'), True)
data = self.command.format_trace
self.assertEqual(data['Username'], 'test_user')
self.assertEqual(data['Created'], 'test_time')
self.assertEqual(data['Source_Address'], '1.2.3.4')
self.assertEqual(data['Source_ID'], 'test_user_agent')
示例8: test034_launch_asynchronous_ftp_error
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import path [as 别名]
def test034_launch_asynchronous_ftp_error(self,
m_session_transaction,
m_Scan,
m_ftp_ctrl,
m_add_empty_result):
m_scan, m_session = MagicMock(), MagicMock()
fw1, fw2 = MagicMock(), MagicMock()
file1, file2 = MagicMock(), MagicMock()
pathf1, pathf2 = 'path-file1', 'path-file2'
file1.path = pathf1
file2.path = pathf2
fw1.file.sha256 = "sha256file1"
fw1.file.mimetype = "mimetypefile1"
fw2.file.sha256 = "sha256file2"
fw2.file.mimetype = "mimetypefile2"
m_scan.files_web = [fw1, fw2]
m_scan.files = [file1, file2]
probe1, probe2 = "Probe1", "Probe2"
probelist = [probe1, probe2]
m_scan.get_probe_list.return_value = probelist
m_add_empty_result.return_value = probelist
m_session_transaction().__enter__.return_value = m_session
m_scan.status = IrmaScanStatus.ready
m_scan.mimetype_filtering = False
m_Scan.load_from_ext_id.return_value = m_scan
scanid = "scanid"
m_ftp_ctrl.upload_scan.side_effect = IrmaFtpError()
module.launch_asynchronous(scanid)
expected = IrmaScanStatus.error_ftp_upload
m_scan.set_status.assert_called_once_with(expected)
示例9: test015_new_file_existing
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import path [as 别名]
def test015_new_file_existing(self, m_sha256sum):
m_file = MagicMock()
m_file.path = "whatever"
self.File.load_from_sha256.return_value = m_file
fobj, session = MagicMock(), MagicMock()
res = module._new_file(fobj, session)
self.assertEqual(res, m_file)
示例10: test_list_remove
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import path [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')])
示例11: get_request
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import path [as 别名]
def get_request(
self, package=None, perms="", user=None, use_base_url=False, path=None
):
""" Construct a fake request """
request = MagicMock()
request.registry.fallback = self.fallback
request.registry.always_show_upstream = self.always_show_upstream
request.registry.fallback_url = self.fallback_url
request.registry.fallback_base_url = (
self.fallback_base_url if use_base_url else None
)
request.userid = user
request.access.can_update_cache = lambda: "c" in perms
request.access.has_permission.side_effect = lambda n, p: "r" in perms
request.is_logged_in = user is not None
request.request_login = six.create_bound_method(_request_login, request)
pkgs = []
if package is not None:
pkgs.append(package)
if path is not None:
request.path = path
request.db.all.return_value = pkgs
return request
示例12: test_new_file_existing_deleted
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import path [as 别名]
def test_new_file_existing_deleted(self, m_sha256sum, m_build_sha256_path,
m_save_to_file, m_os):
m_file = MagicMock()
fobj = MagicMock()
m_file.path = "filepath"
sha256val = "whatever"
m_os.path.exists(m_file.path).return_value = False
m_sha256sum.return_value = sha256val
m_session = MagicMock()
m_session.query(module.File).filter(
module.File.sha256 == sha256val
).one.return_value = m_file
m_file.path = None
res = module.File.get_or_create(fobj, m_session)
m_build_sha256_path.assert_called()
m_save_to_file.assert_called()
self.assertEqual(res, m_file)
示例13: test016_download_deleted_file
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import path [as 别名]
def test016_download_deleted_file(self, m_File, m_open):
sha256 = "whatever"
m_fobj = MagicMock()
m_fobj.path = None
m_File.load_from_sha256.return_value = m_fobj
with self.assertRaises(IrmaDatabaseResultNotFound) as context:
api_files._download(sha256, self.db)
self.assertEqual(str(context.exception), "downloading a removed file")
示例14: test_search
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import path [as 别名]
def test_search(self, search):
search.return_value = (("foo", "foodesc"),)
repo = MagicMock()
repo.path = "/dev/null"
self.assertEqual(
list(bw_repo_plugin_search(repo, MagicMock())),
["foo: foodesc"],
)
示例15: test_wizard
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import path [as 别名]
def test_wizard(self):
args = Mock()
args.path = '/tmp/foo'
cli.getch = Mock(side_effect=chain(repeat('b', 10), 'c',
repeat('b', 10)))
cli.get_devices = Mock(side_effect=self.devices)
spreads.config['keep'] = False
cli.wizard(args, self.devices)