本文整理汇总了Python中mock.Mock.name方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.name方法的具体用法?Python Mock.name怎么用?Python Mock.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.Mock
的用法示例。
在下文中一共展示了Mock.name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_responder_call_hashcat
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import name [as 别名]
def test_responder_call_hashcat(self, mock_os, mock_subprocess):
self.handler.accept_eula = Mock()
self.handler.get_configs = Mock()
self.handler.get_configs.return_value = ['hashcat', 'ruleset', 'wordlist']
outfile = Mock()
outfile.name = 'outfile'
self.handler.get_outfile = Mock()
self.handler.get_outfile.return_value = outfile
junkfile = Mock()
junkfile.name = 'junkfile'
self.handler.get_junkfile = Mock()
self.handler.get_junkfile.return_value = junkfile
tempfile = Mock()
tempfile.name = 'tempfile'
self.handler.get_tempfile = Mock()
self.handler.get_tempfile.return_value = tempfile
self.handler.outpath = 'outpath'
mock_os.path = Mock()
mock_os.path.exists.return_value = True
mock_subprocess.Popen = Mock()
self.handler.call_hashcat('5600', 'SMB-NTLMv2.txt')
self.assertEqual(['hashcat', '-m', '5600', '-r', 'ruleset', '-o', 'outfile', 'junkfile', 'wordlist'], mock_subprocess.Popen.call_args[0][0])
示例2: test_dirty_save
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import name [as 别名]
def test_dirty_save(self):
age_field = Mock()
age_field.name = 'age'
age_field.value_to_string.return_value = 30
name_field = Mock()
name_field.name = 'name'
name_field.value_to_string.return_value = 'Bob'
class DirtyUser(mock_orm.Model):
_fields = [age_field, name_field]
pk = 3
class DirtyUserResource(resources.ModelResource):
parent_resource_path = 'users'
model_class = DirtyUser
fields = [
fields.AttributeField(attribute='name', type=str),
fields.AttributeField(attribute='age', type=int)
]
dirty_user = DirtyUser()
dirty_user.save = Mock()
dirty_user.is_dirty = lambda: True
resource = DirtyUserResource(dirty_user)
resource.put(mock_context(), {
'name': 'Bob',
'age': 30,
'resourceUri': 'uri://users/1'
})
self.assertTrue(dirty_user.save.called)
示例3: test_print_instance
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import name [as 别名]
def test_print_instance(colorize):
colorize.return_value = 'fancy-cloud'
# as name is an argument in the Mock constructor
# we have to set it on an instance
group1 = Mock()
group1.name = 'group1'
group2 = Mock()
group2.name = 'group2'
groups = [group1, group2]
instance = Mock(
name='cloud',
instance_type='fancy',
status='happy',
tags={'owner': 'ofs'},
launch_time=datetime.datetime(2000, 01, 01),
groups=groups,
availability_zone='cloud-zone'
)
expected = [
'fancy-cloud',
'fancy',
'fancy-cloud',
'ofs',
'fancy-cloud',
'group1,group2',
'cloud-zone',
]
result = print_instance_summary(instance)
assert result == expected
示例4: test_server_sends_marshaled_exception_when_callback_raises_exception
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import name [as 别名]
def test_server_sends_marshaled_exception_when_callback_raises_exception(self, mock_command_response):
request = '{"name": "foobar", "arg": {"arg1": "value"}}'
expected = '{"error": "raise me!", "value": null}'
command_response = Mock(CommandResponse)
command_response.error = "raise me!"
command_response.value = None
mock_command_response.return_value = command_response
callback = Mock(side_effect=BusCtlServerError())
marshaler = Mock(Marshaler)
server = BusCtlServer()
server._marshaler = marshaler
command = Mock()
command.name = "foobar"
marshaler.unmarshal_command.return_value = command
marshaler.marshal_response.return_value = expected
command_class = Mock()
command_class.name = "foobar"
server.add_command(command_class, callback)
response = server._process_next_command(request)
self.assertEqual(response, expected)
marshaler.marshal_response.assert_called_once_with(command_response)
示例5: make_bigip
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import name [as 别名]
def make_bigip():
bigip = Mock()
vip_port = '1010'
vaddr = '192.168.1.1'
netmask = '255.255.255.0'
protocol = 'HTTP'
lb_id = 'TEST_FOO'
fwd_name = 'hello'
name = 'name'
dest = "{}/{}:{}".format(fwd_name, lb_id, vip_port)
partition = 'Common'
va = Mock()
vs = Mock()
bigip.tm.ltm.virtuals.get_collection.return_value = \
[vs]
vs.destination = dest
vs.mask = netmask
vs.ipProtocol = protocol
vs.name = name
bigip.tm.ltm.virtual_address_s.virtual_address.load.return_value \
= va
va.raw = dict(address=vaddr)
bigip.vip_port = vip_port
bigip.vaddr = vaddr
bigip.netmask = netmask
bigip.protocol = protocol
bigip.lb_id = lb_id
bigip.fwd_name = fwd_name
bigip.name = name
bigip.dest = dest
bigip.partition = partition
return bigip
示例6: test_resource_offers_creates_nodes
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import name [as 别名]
def test_resource_offers_creates_nodes(self, mock_get_slave):
mock_get_slave.return_value = SlaveInfo(u'localhost', 5151)
mock_cpu = Mock()
mock_cpu.name = u'cpus'
mock_cpu.value = 10
mock_disk = Mock()
mock_disk.name = u'disk'
mock_disk.value = 4000
mock_mem = Mock()
mock_mem.name = u'mem'
mock_mem.value = 100000
mock_offer = Mock()
mock_offer.id.value = 1
mock_offer.slave_id.value = 1
mock_offer.hostname.value = u'localhost'
mock_offer.resources = [mock_cpu, mock_disk, mock_mem]
offers = [mock_offer]
my_scheduler, driver, master_info = self._get_mocked_scheduler_driver_master()
localhost_exists = Node.objects.filter(hostname=u'localhost').exists()
self.assertFalse(localhost_exists, 'there should not be a node before the first offer')
my_scheduler.resourceOffers(driver, offers)
localhost_exists = Node.objects.all().exists()
self.assertTrue(localhost_exists, 'there should be a node after the first offer')
示例7: test_with_two_valid_issues
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import name [as 别名]
def test_with_two_valid_issues(self, mock1, mock2):
'''
A commit with two issues with correct labels
'''
# Mock the commit message
mock1.return_value = (
'This is a test commit\n\n'
'Fixes: #1234\n'
'Updates: #4567')
commit_msg = commit.get_commit_message()
c = commit.CommitHandler('glusterfs')
issues = c.parse_commit_message(commit_msg)
self.assertEqual(issues,
[{
'id': '1234',
'status': 'Fixes'
}, {
'id': '4567',
'status': 'Updates'
}]
)
# Handle a valid issue
mock2.side_effect = None
ghub = handle_github.GitHubHandler('glusterfs', True)
ghub.ghub = Mock(name='mockedgithub')
label1 = Mock(name='mockedlabel')
label1.name = 'SpecApproved'
label2 = Mock(name='mockedlabel')
label2.name = 'DocApproved'
ghub.ghub.issue.return_value.labels = [label1, label2]
for issue in issues:
self.assertTrue(ghub.check_issue(issue['id']))
示例8: test_gameplay
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import name [as 别名]
def test_gameplay(self):
host = Mock(spec=Player)
player1 = Mock(spec=Player)
player1.name = "Jeb"
player2 = Mock(spec=Player)
player2.name = "Zedd"
game = GameFactory(Mock(new_id=Mock(return_value="0000")), Mock(spec=NotificationManager)).new_game(host)
game.register_player(player1)
game.register_player(player2)
game = game.start()
expected_story = ""
first_player_prompt = "First player prompt"
second_player_prompt = "Second player prompt"
for i in range(0, TOTAL_ROUNDS):
game = game.receive_prompt(Prompt(first_player_prompt, player1.name))
game = game.receive_prompt(Prompt(second_player_prompt, player2.name))
choice = first_player_prompt if i % 2 == 0 else second_player_prompt
expected_story = "{} {}".format(expected_story, choice)
game = game.choose_prompt(ChoosePrompt(choice))
self.assertIs(type(game), CompleteGame)
self.assertEqual(game.story, expected_story)
示例9: test_topological_order_packages
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import name [as 别名]
def test_topological_order_packages(self):
plist = []
self.assertEqual([], _topological_order_packages(plist))
p1 = Mock('catkin.topological_order.PackageData')
p1.name = 'p1'
p1.build_depends = set(['p3', 'px'])
p1.message_generator = Mock()
p2 = Mock('catkin.topological_order.PackageData')
p2.name = 'p2'
p2.build_depends = set(['p1', 'p3'])
p2.message_generator = Mock()
p3 = Mock('catkin.topological_order.PackageData')
p3.name = 'p3'
p3.build_depends = set()
p3.message_generator = Mock()
p4 = Mock('catkin.topological_order.PackageData')
p4.name = 'catkin'
plist = [p1, p2, p3]
self.assertEqual([['p3', p3], ['p1', p1], ['p2', p2]],
_topological_order_packages(plist))
示例10: test__has_access_to_location
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import name [as 别名]
def test__has_access_to_location(self):
location = Location("i4x://edX/toy/course/2012_Fall")
self.assertFalse(access._has_access_to_location(None, location, "staff", None))
u = Mock()
u.is_authenticated.return_value = False
self.assertFalse(access._has_access_to_location(u, location, "staff", None))
u = Mock(is_staff=True)
self.assertTrue(access._has_access_to_location(u, location, "instructor", None))
# A user has staff access if they are in the staff group
u = Mock(is_staff=False)
g = Mock()
g.name = "staff_edX/toy/2012_Fall"
u.groups.all.return_value = [g]
self.assertTrue(access._has_access_to_location(u, location, "staff", None))
# A user has staff access if they are in the instructor group
g.name = "instructor_edX/toy/2012_Fall"
self.assertTrue(access._has_access_to_location(u, location, "staff", None))
# A user has instructor access if they are in the instructor group
g.name = "instructor_edX/toy/2012_Fall"
self.assertTrue(access._has_access_to_location(u, location, "instructor", None))
# A user does not have staff access if they are
# not in either the staff or the the instructor group
g.name = "student_only"
self.assertFalse(access._has_access_to_location(u, location, "staff", None))
# A user does not have instructor access if they are
# not in the instructor group
g.name = "student_only"
self.assertFalse(access._has_access_to_location(u, location, "instructor", None))
示例11: testGetSuggestedInstancesTwoDifferentSize
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import name [as 别名]
def testGetSuggestedInstancesTwoDifferentSize(self, getAutoScalingGroupsMock):
region = "us-west-2"
# Instance 1
instanceMock1 = Mock(spec="boto.ec2.auto_scale.group.AutoScalingGroup")
instanceMock1.name = "testName1"
instanceMock1.desired_capacity = 64
# Instance 2
instanceMock2 = Mock(spec="boto.ec2.auto_scale.group.AutoScalingGroup")
instanceMock2.name = "testName2"
instanceMock2.desired_capacity = 65
getAutoScalingGroupsMock.return_value = [
instanceMock1,
instanceMock2,
]
suggestions = asg_utils.getSuggestedInstances(region)
self.assertIsInstance(suggestions, types.GeneratorType)
suggestions = list(suggestions)
self.assertSequenceEqual(suggestions, [
{"id": "testName2", "name": "testName2", "namespace": "AWS/AutoScaling",
"region": region},
{"id": "testName1", "name": "testName1", "namespace": "AWS/AutoScaling",
"region": region},
])
getAutoScalingGroupsMock.assert_call_once_with(region)
示例12: test_get_installed_classes
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import name [as 别名]
def test_get_installed_classes(self, pkg_resources):
bad_plugin = Mock()
bad_plugin.name = "bad"
bad_plugin.load.side_effect = ImportError
fake_plugin = Mock()
fake_plugin.name = "fakeplugin"
fake_plugin.load.return_value = FakePlugin
incomplete_plugin = Mock()
incomplete_plugin.name = "incomplete"
incomplete_plugin.load.return_value = IncompletePlugin
other_plugin = Mock()
other_plugin.name = "other"
other_plugin.load.return_value = OtherPlugin
pkg_resources.iter_entry_points.return_value = [
bad_plugin,
fake_plugin,
incomplete_plugin,
other_plugin
]
self.assertEqual(
FakePlugin.get_installed_classes(),
{"fakeplugin": FakePlugin}
)
示例13: test_repo_groups
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import name [as 别名]
def test_repo_groups(self):
line_evaluator = Mock()
line_evaluator.key = "line"
line_evaluator.matches = Mock(return_value=True)
rule = Mock()
rule.name = "os_code_exec::python"
rule.evaluators = [line_evaluator]
junk_repo = Mock()
junk_repo.name = 'junk'
local_repo = Mock()
local_repo.name = 'tooling'
repo_groups = {
'skipped_repos': ['junk'],
'local_repos': ['tooling']
}
rules_to_groups = {
'skipped_repos': [{'except': '.*'}],
'local_repos': [
{'match': '.*'},
{'except': 'os_code_exec::.*'}
]
}
code_checker = CodeChecker(context_processors=[], rules=[rule],
repo_groups=repo_groups, rules_to_groups=rules_to_groups)
check_context = {"filename": "macbeth.txt"}
self.assertEquals(code_checker.check(lines=self.code, context=check_context, repo=junk_repo), [])
self.assertEquals(code_checker.check(lines=self.code, context=check_context, repo=local_repo), [])
示例14: test_data
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import name [as 别名]
def test_data(self):
datastore = Mock()
datastore.name = self.module.datastore
ds_version = Mock()
ds_version.name = self.module.datastore_version
with patch.object(models, 'get_datastore_version',
Mock(return_value=(datastore, ds_version))):
view = DetailedModuleView(self.module)
result = view.data()
self.assertEqual(self.module.name, result['module']['name'])
self.assertEqual(self.module.type, result['module']['type'])
self.assertEqual(self.module.md5, result['module']['md5'])
self.assertEqual(self.module.created, result['module']['created'])
self.assertEqual(self.module.updated, result['module']['updated'])
self.assertEqual(self.module.datastore_version,
result['module']['datastore_version'])
self.assertEqual(self.module.datastore,
result['module']['datastore'])
self.assertEqual(self.module.auto_apply,
result['module']['auto_apply'])
self.assertEqual(self.module.tenant_id,
result['module']['tenant_id'])
self.assertEqual(self.module.is_admin,
result['module']['is_admin'])
self.assertEqual(self.module.priority_apply,
result['module']['priority_apply'])
self.assertEqual(self.module.apply_order,
result['module']['apply_order'])
示例15: test_update_cluster_with_same_discovery
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import name [as 别名]
def test_update_cluster_with_same_discovery(self):
riak_discovery = Mock()
riak_discovery.name = "riak"
dns_discovery = Mock()
dns_discovery.name = "dns"
cluster = Mock()
cluster.name = "app"
cluster.discovery = "riak"
cluster.config = {"discovery": "riak"}
writer = Writer("/etc/configs")
writer.add_configurable(Cluster, "app", cluster)
writer.add_configurable(Discovery, "riak", riak_discovery)
writer.add_configurable(Discovery, "dns", dns_discovery)
writer.update_configurable(
Cluster, cluster.name, {"discovery": "riak"}
)
self.assertEqual(writer.nodes_updated.is_set(), True)
self.assertEqual(riak_discovery.stop_watching.called, False)
self.assertEqual(dns_discovery.start_watching.called, False)