本文整理汇总了Python中mock.MagicMock.state方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.state方法的具体用法?Python MagicMock.state怎么用?Python MagicMock.state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.state方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _mock_get
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import state [as 别名]
def _mock_get(pk=None):
result = MagicMock()
if pk == '1111':
result.state = 'published'
result.pk = '1111'
else:
result.state = 'uploaded'
result.pk = '2222'
return result
示例2: setUp
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import state [as 别名]
def setUp(self):
# Mock resource model
resource1 = MagicMock()
resource1.name = 'Resource1'
resource1.version = '1.0'
resource1.description = 'Test resource 1'
resource1.content_type = 'text/plain'
resource1.state = 'created'
resource1.open = False
resource1.get_url.return_value = 'http://localhost/media/resources/resource1'
resource2 = MagicMock()
resource2.name = 'Resource2'
resource2.version = '2.0'
resource2.description = 'Test resource 2'
resource2.content_type = 'text/plain'
resource2.state = 'created'
resource2.open = False
resource2.get_url.return_value = 'http://localhost/media/resources/resource2'
resource3 = MagicMock()
resource3.name = 'Resource3'
resource3.version = '2.0'
resource3.description = 'Test resource 3'
resource3.content_type = 'text/plain'
resource3.state = 'created'
resource3.open = True
resource3.get_url.return_value = 'http://localhost/media/resources/resource3'
resource4 = MagicMock()
resource4.name = 'Resource4'
resource4.version = '1.0'
resource4.description = 'Test resource 4'
resource4.content_type = 'text/plain'
resource4.state = 'created'
resource4.open = True
resource4.get_url.return_value = 'http://localhost/media/resources/resource4'
resource4.offerings = ['1111', '2222']
resources_management.Resource = MagicMock()
resources_management.Resource.objects.filter.return_value = [
resource1,
resource2,
resource3,
resource4
]
self.user = MagicMock()
self.org = MagicMock()
self.user.userprofile.current_organization = self.org
示例3: test_builder_assigns_address_components_if_formatted_address_present
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import state [as 别名]
def test_builder_assigns_address_components_if_formatted_address_present():
address_parser_mock = MagicMock(spec=address_parser)
parsed_address_mock = MagicMock()
address = 'fake_address'
city = 'fake_city'
state = 'fake_state'
zip_code = 'fake_zip_code'
formatted_address = 'fake_formatted_address '
parsed_address_mock.address1 = address
parsed_address_mock.city = city
parsed_address_mock.state = state
parsed_address_mock.zip_code = zip_code
parsed_address_mock.formatted_address = formatted_address
address_parser_mock.parse_address = MagicMock(return_value=parsed_address_mock)
builder = ListingBuilder(address_parser_mock, formatted_address='x')
builder.listing_attrs_output = MagicMock()
builder._build_formatted_address()
call_list = [
call(listing_builder.ADDRESS, address),
call(listing_builder.CITY, city),
call(listing_builder.STATE, state),
call(listing_builder.ZIP_CODE, zip_code),
call(listing_builder.FORMATTED_ADDRESS, formatted_address),
]
assert builder.listing_attrs_output.__setitem__.call_args_list == call_list
示例4: test_ChuteApi_get_chute
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import state [as 别名]
def test_ChuteApi_get_chute(ChuteStorage, ChuteContainer):
update_manager = MagicMock()
api = chute_api.ChuteApi(update_manager)
request = MagicMock()
request.user = User.get_internal_user()
container = MagicMock()
container.getStatus.return_value = "running"
ChuteContainer.return_value = container
chute = MagicMock()
chute.name = "test"
chute.state = "running"
chute.version = 5
chute.environment = {}
chute.resources = {}
ChuteStorage.chuteList = {
"test": chute
}
data = api.get_chute(request, chute.name)
assert isinstance(data, basestring)
result = json.loads(data)
assert result['name'] == chute.name
assert result['version'] == chute.version
示例5: test_50_start
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import state [as 别名]
def test_50_start(self, get_driver):
auth = Authentication([{'id': 'ost', 'type': 'OpenStack', 'username': 'user',
'password': 'pass', 'tenant': 'tenant', 'host': 'https://server.com:5000'}])
ost_cloud = self.get_ost_cloud()
inf = MagicMock()
inf.get_next_vm_id.return_value = 1
vm = VirtualMachine(inf, "1", ost_cloud.cloud, "", "", ost_cloud)
driver = MagicMock()
get_driver.return_value = driver
node = MagicMock()
node.id = "1"
node.state = "running"
node.extra = {'flavorId': 'small'}
node.public_ips = ['158.42.1.1']
node.private_ips = ['10.0.0.1']
node.driver = driver
driver.list_nodes.return_value = [node]
driver.ex_start_node.return_value = True
success, _ = ost_cloud.start(vm, auth)
self.assertTrue(success, msg="ERROR: stopping VM info.")
self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
self.clean_log()
示例6: test_50_start
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import state [as 别名]
def test_50_start(self, get_driver):
auth = Authentication([{'id': 'libcloud', 'type': 'LibCloud', 'username': 'user',
'password': 'pass', 'driver': 'EC2'}])
lib_cloud = self.get_lib_cloud()
inf = MagicMock()
inf.get_next_vm_id.return_value = 1
vm = VirtualMachine(inf, "1", lib_cloud.cloud, "", "", lib_cloud)
driver = MagicMock()
get_driver.return_value = driver
node = MagicMock()
node.id = "1"
node.state = "running"
node.driver = driver
driver.list_nodes.return_value = [node]
driver.ex_stop_node.return_value = True
success, _ = lib_cloud.start(vm, auth)
self.assertTrue(success, msg="ERROR: stopping VM info.")
self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
self.clean_log()
示例7: test_ChuteApi_get_chutes
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import state [as 别名]
def test_ChuteApi_get_chutes(ChuteStorage, ChuteContainer):
update_manager = MagicMock()
api = chute_api.ChuteApi(update_manager)
request = MagicMock()
container = MagicMock()
container.getStatus.return_value = "running"
ChuteContainer.return_value = container
storage = MagicMock()
ChuteStorage.return_value = storage
chute = MagicMock()
chute.environment = {}
chute.name = "test"
chute.state = "running"
chute.resources = {}
chute.version = 5
chute.get_owner.return_value = "paradrop"
storage.getChuteList.return_value = [chute]
data = api.get_chutes(request)
assert isinstance(data, basestring)
result = json.loads(data)
assert result[0]['name'] == chute.name
assert result[0]['version'] == chute.version
示例8: _ec2_instance
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import state [as 别名]
def _ec2_instance(self, state='running', id='i-456', launch_time=datetime(2017, 1, 1, tzinfo=utc)):
instance = MagicMock()
instance.id = id
state_codes = {'running': 16}
instance.state = {'Code': state_codes.get(state, -1), 'Name': state} # 'Code' should vary but probably isn't being used
instance.tags = [{'Key': 'Name', 'Value': 'dummy1--test--1'}]
instance.launch_time = launch_time
return instance
示例9: _mock_get_up
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import state [as 别名]
def _mock_get_up(pk=None):
result = MagicMock()
result.state = 'uploaded'
if pk == '1111':
result.pk = '1111'
else:
result.pk = '2222'
return result
示例10: test_55_alter
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import state [as 别名]
def test_55_alter(self, get_driver):
radl_data = """
network net ()
system test (
cpu.arch='x86_64' and
cpu.count=1 and
memory.size=512m and
net_interface.0.connection = 'net' and
net_interface.0.dns_name = 'test' and
disk.0.os.name = 'linux' and
disk.0.image.url = 'one://server.com/1' and
disk.0.os.credentials.username = 'user' and
disk.0.os.credentials.password = 'pass'
)"""
radl = radl_parse.parse_radl(radl_data)
new_radl_data = """
system test (
cpu.count>=2 and
memory.size>=2048m
)"""
new_radl = radl_parse.parse_radl(new_radl_data)
auth = Authentication([{'id': 'ost', 'type': 'OpenStack', 'username': 'user',
'password': 'pass', 'tenant': 'tenant', 'host': 'https://server.com:5000'}])
ost_cloud = self.get_ost_cloud()
inf = MagicMock()
inf.get_next_vm_id.return_value = 1
vm = VirtualMachine(inf, "1", ost_cloud.cloud, radl, radl, ost_cloud)
driver = MagicMock()
get_driver.return_value = driver
node = MagicMock()
node.id = "1"
node.state = "running"
node.extra = {'flavorId': 'small'}
node.public_ips = ['158.42.1.1']
node.private_ips = ['10.0.0.1']
node.driver = driver
driver.list_nodes.return_value = [node]
node_size = MagicMock()
node_size.ram = 2048
node_size.price = 1
node_size.disk = 1
node_size.vcpus = 2
node_size.name = "small"
driver.list_sizes.return_value = [node_size]
driver.ex_resize.return_value = True
success, _ = ost_cloud.alterVM(vm, new_radl, auth)
self.assertTrue(success, msg="ERROR: modifying VM info.")
self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
self.clean_log()
示例11: test_30_updateVMInfo
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import state [as 别名]
def test_30_updateVMInfo(self, get_driver):
radl_data = """
network net (outbound = 'yes')
system test (
cpu.arch='x86_64' and
cpu.count=1 and
memory.size=512m and
net_interface.0.connection = 'net' and
net_interface.0.ip = '158.42.1.1' and
net_interface.0.dns_name = 'test' and
disk.0.os.name = 'linux' and
disk.0.image.url = 'aws://ami-id' and
disk.0.os.credentials.username = 'user' and
disk.0.os.credentials.password = 'pass'
)"""
radl = radl_parse.parse_radl(radl_data)
radl.check()
auth = Authentication([{'id': 'libcloud', 'type': 'LibCloud', 'username': 'user',
'password': 'pass', 'driver': 'EC2'}])
lib_cloud = self.get_lib_cloud()
inf = MagicMock()
inf.get_next_vm_id.return_value = 1
vm = VirtualMachine(inf, "1", lib_cloud.cloud, radl, radl, lib_cloud)
driver = MagicMock()
driver.name = "Amazon EC2"
get_driver.return_value = driver
node = MagicMock()
node.id = "1"
node.state = "running"
node.extra = {'availability': 'use-east-1'}
node.public_ips = []
node.private_ips = ['10.0.0.1']
node.driver = driver
node.size = MagicMock()
node.size.ram = 512
node.size.price = 1
node.size.disk = 1
node.size.vcpus = 1
node.size.name = "small"
driver.list_nodes.return_value = [node]
volume = MagicMock()
volume.id = "vol1"
volume.extra = {"state": "available"}
volume.attach.return_value = True
driver.create_volume.return_value = volume
driver.ex_allocate_address.return_value = "10.0.0.1"
success, vm = lib_cloud.updateVMInfo(vm, auth)
self.assertTrue(success, msg="ERROR: updating VM info.")
self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
self.clean_log()
示例12: test_reloadChutes
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import state [as 别名]
def test_reloadChutes(mockStore, mockSettings, mResources, mWait, mTime, mOut, mTimeint):
"""
Test that the reloadChutes function does it's job.
"""
#Test that if pdconfd isn't enabled we return an empty list
mockSettings.PDCONFD_ENABLED = False
storage = MagicMock()
mockStore.return_value = storage
#Call
ret = restart.reloadChutes()
#Assertions
assert ret == []
assert not mockStore.called
#Test that if pdconfd is enabled we do our job
mTimeint.return_value = 'Now'
mockSettings.PDCONFD_ENABLED = True
mockSettings.RESERVED_CHUTE = 'PDROP'
ch1 = MagicMock()
ch2 = MagicMock()
ch3 = MagicMock()
ch1.state = 'running'
ch1.name = 'ch1'
ch2.state = 'stopped'
ch3.state = 'running'
ch3.name = 'ch3'
storage.getChuteList.return_value = [ch1, ch2, ch3]
mWait.side_effect = [None, None, '[{"success": false, "comment": "PDROP"},{"success": false, "comment": "ch1"},{"success": false, "comment": "ch2"},{"success": true, "comment": "ch3"},{"success": true, "comment": "error"}]']
#Call
ret = restart.reloadChutes()
#Assertions
mResources.assert_called_with(ch3)
assert mResources.call_count == 2
assert mTime.sleep.call_count == 2
assert mTime.sleep.called_with(1)
assert mOut.warn.call_count == 2
assert 'Failed to load a system config section' in str(mOut.warn.call_args_list[0])
assert 'Failed to load config section for unrecognized chute: ch2' in str(mOut.warn.call_args_list[1])
assert dict(updateClass='CHUTE', updateType='stop', name=ch1.name, tok=mTimeint.return_value, func=restart.updateStatus, warning=restart.FAILURE_WARNING) in ret
assert dict(updateClass='CHUTE', updateType='restart', name=ch3.name, tok=mTimeint.return_value, func=restart.updateStatus) in ret
示例13: test_30_updateVMInfo
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import state [as 别名]
def test_30_updateVMInfo(self, get_driver):
radl_data = """
network net (outbound = 'yes')
system test (
cpu.arch='x86_64' and
cpu.count=1 and
memory.size=512m and
net_interface.0.connection = 'net' and
net_interface.0.dns_name = 'test' and
disk.0.os.name = 'linux' and
disk.0.image.url = 'gce://us-central1-a/centos-6' and
disk.0.os.credentials.username = 'user' and
disk.1.size=1GB and
disk.1.device='hdb' and
disk.1.mount_path='/mnt/path'
)"""
radl = radl_parse.parse_radl(radl_data)
radl.check()
auth = Authentication([{'id': 'one', 'type': 'GCE', 'username': 'user',
'password': 'pass\npass', 'project': 'proj'}])
gce_cloud = self.get_gce_cloud()
inf = MagicMock()
inf.get_next_vm_id.return_value = 1
vm = VirtualMachine(inf, "1", gce_cloud.cloud, radl, radl, gce_cloud)
driver = MagicMock()
get_driver.return_value = driver
node = MagicMock()
zone = MagicMock()
node.id = "1"
node.state = "running"
node.extra = {'flavorId': 'small'}
node.public_ips = []
node.public_ips = ['158.42.1.1']
node.private_ips = ['10.0.0.1']
node.driver = driver
zone.name = 'us-central1-a'
node.extra = {'zone': zone}
driver.ex_get_node.return_value = node
volume = MagicMock()
volume.id = "vol1"
volume.attach.return_value = True
volume.extra = {'status': 'READY'}
driver.create_volume.return_value = volume
success, vm = gce_cloud.updateVMInfo(vm, auth)
self.assertTrue(success, msg="ERROR: updating VM info.")
self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
self.clean_log()
示例14: mock_ec2_instance
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import state [as 别名]
def mock_ec2_instance(name, state='stopped', **kwargs):
instance = MagicMock(
name='ec2-instance-' + name,
tags=[
{
'Key': 'Name',
'Value': name
}
],
**kwargs
)
instance.state = {'Name': state, 'Code': 0}
return instance
示例15: test_60_finalize
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import state [as 别名]
def test_60_finalize(self, sleep, get_driver):
auth = Authentication([{'id': 'ost', 'type': 'OpenStack', 'username': 'user',
'password': 'pass', 'tenant': 'tenant', 'host': 'https://server.com:5000'}])
ost_cloud = self.get_ost_cloud()
radl_data = """
system test (
cpu.count>=2 and
memory.size>=2048m
)"""
radl = radl_parse.parse_radl(radl_data)
inf = MagicMock()
inf.get_next_vm_id.return_value = 1
vm = VirtualMachine(inf, "1", ost_cloud.cloud, radl, radl, ost_cloud)
driver = MagicMock()
driver.name = "OpenStack"
get_driver.return_value = driver
node = MagicMock()
node.id = "1"
node.state = "running"
node.extra = {'flavorId': 'small'}
node.public_ips = ['158.42.1.1']
node.private_ips = ['10.0.0.1']
node.driver = driver
node.destroy.return_value = True
driver.list_nodes.return_value = [node]
sg = MagicMock()
sg.id = sg.name = "sg1"
driver.ex_get_node_security_groups.return_value = [sg]
keypair = MagicMock()
driver.get_key_pair.return_value = keypair
vm.keypair = keypair
driver.delete_key_pair.return_value = True
driver.delete_security_group.return_value = True
driver.ex_list_floating_ips.return_value = []
success, _ = ost_cloud.finalize(vm, auth)
self.assertTrue(success, msg="ERROR: finalizing VM info.")
self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
self.clean_log()