本文整理汇总了Python中mock.MagicMock.create方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.create方法的具体用法?Python MagicMock.create怎么用?Python MagicMock.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import create [as 别名]
def test_create(self):
ctx = self.ctx
config = {BUCKET: 'bucket', POLICY: 'policy'}
iface = MagicMock()
iface.create = self.mock_return('location')
bucket_policy.create(ctx, iface, config)
self.assertEqual(ctx.instance.runtime_properties[POLICY], 'policy')
config = {BUCKET: 'bucket', POLICY: ['policy']}
iface = MagicMock()
iface.create = self.mock_return('location')
bucket_policy.create(ctx, iface, config)
self.assertEqual(ctx.instance.runtime_properties[POLICY], '["policy"]')
config = {POLICY: 'policy'}
ctx_target = self.get_mock_relationship_ctx(
"bucket",
test_target=self.get_mock_ctx("Bucket",
{},
{EXTERNAL_RESOURCE_ID: 'ext_id'}))
iface = MagicMock()
iface.create = self.mock_return('location')
with patch(PATCH_PREFIX + 'utils') as utils:
utils.find_rel_by_node_type = self.mock_return(ctx_target)
utils.clean_params = self.mock_return({POLICY: 'policy'})
bucket_policy.create(ctx, iface, config)
self.assertEqual(ctx.instance.runtime_properties[BUCKET],
'ext_id')
self.assertEqual(ctx.instance.runtime_properties[POLICY],
'policy')
示例2: test_create
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import create [as 别名]
def test_create(self):
ctx = self.get_mock_ctx("EBSVolume")
config = \
{
'AvailabilityZone': 'aq-testzone-1a',
'Size': 6,
'Tags':
[
{
'Key': 'test-tag-key-1',
'Value': 'test-tag-value-1',
},
{
'Key': 'test-tag-key-2',
'Value': 'test-tag-value-2',
}
],
'VolumeId': 'test_volume_id',
}
self.ebs_volume.resource_id = config[VOLUME_ID]
iface = MagicMock()
iface.create = self.mock_return(config)
ebs.create(ctx=ctx, iface=iface, resource_config=config)
self.assertEqual(self.ebs_volume.resource_id, 'test_volume_id')
示例3: test_create
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import create [as 别名]
def test_create(self):
bucket_object_request = {
'Body': 'test/path/test-object.txt',
'Key': 'test-object.txt'
}
config = self.resource_config['resource_config']['kwargs']
config.update(**bucket_object_request)
iface = MagicMock()
iface.create = self.mock_return(None)
download_file_mock = MagicMock()
_, file_path = tempfile.mkstemp()
download_file_mock.return_value = file_path
bucket_object.download_resource_file = download_file_mock
bucket_object.create(ctx=self.ctx,
iface=iface,
resource_config=config)
self.assertEqual(
self.ctx.instance.runtime_properties[BUCKET], 'test_bucket')
self.assertEqual(
self.ctx.instance.runtime_properties[EXTERNAL_RESOURCE_ID],
'test-object.txt')
示例4: test_prepare
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import create [as 别名]
def test_prepare(self):
ctx = self.get_mock_ctx("Vpc")
config = {VPC_ID: 'vpc', CIDR_BLOCK: 'cidr_block'}
iface = MagicMock()
iface.create = self.mock_return(config)
vpc.prepare(ctx, iface, config)
self.assertEqual(ctx.instance.runtime_properties['resource_config'],
config)
示例5: test_prepare
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import create [as 别名]
def test_prepare(self):
ctx = self.get_mock_ctx("Image")
config = {IMAGE_ID: 'image', OWNERS: 'owner'}
iface = MagicMock()
iface.create = self.mock_return(config)
image.prepare(ctx, iface, config)
self.assertEqual(ctx.instance.runtime_properties['resource_config'],
config)
示例6: test_create
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import create [as 别名]
def test_create(self):
ctx = self._get_ctx()
resource_config = {'config': None}
iface = MagicMock()
iface.create = self.mock_return({'HostedZone': {'Id': 'id'}})
hosted_zone.create(ctx, iface, resource_config)
rprop = ctx.instance.runtime_properties
self.assertEqual(rprop[constants.EXTERNAL_RESOURCE_ID], 'id')
self.assertEqual(rprop[constants.EXTERNAL_RESOURCE_ARN], 'id')
示例7: test_create
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import create [as 别名]
def test_create(self):
ctx = self.get_mock_ctx("Vpc")
config = {VPC_ID: 'vpc', CIDR_BLOCK: 'cidr_block'}
self.vpc.resource_id = config[VPC_ID]
iface = MagicMock()
iface.create = self.mock_return({VPC: config})
vpc.create(ctx=ctx, iface=iface, resource_config=config)
self.assertEqual(self.vpc.resource_id,
'vpc')
示例8: test_create
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import create [as 别名]
def test_create(self):
ctx = self.get_mock_ctx("NetworkAcl")
config = {NETWORKACL_ID: 'network acl', VPC_ID: 'vpc'}
self.networkacl.resource_id = config[NETWORKACL_ID]
iface = MagicMock()
iface.create = self.mock_return({'NetworkAcl': config})
networkacl.create(ctx=ctx, iface=iface, resource_config=config)
self.assertEqual(self.networkacl.resource_id,
'network acl')
示例9: test_create
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import create [as 别名]
def test_create(self):
ctx = self.get_mock_ctx("InternetGateway")
config = {INTERNETGATEWAY_ID: 'internet gateway'}
self.internet_gateway.resource_id = config[INTERNETGATEWAY_ID]
iface = MagicMock()
iface.create = self.mock_return({'InternetGateway': config})
internet_gateway.create(ctx=ctx, iface=iface, resource_config=config)
self.assertEqual(self.internet_gateway.resource_id,
'internet gateway')
示例10: test_create
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import create [as 别名]
def test_create(self):
ctx = self.get_mock_ctx(DHCPOPTIONS)
config = {DHCPOPTIONS_ID: 'dhcp'}
self.dhcp.resource_id = config[DHCPOPTIONS_ID]
iface = MagicMock()
iface.create = self.mock_return({DHCPOPTIONS: config})
dhcp.create(ctx, iface, config)
self.assertEqual(self.dhcp.resource_id,
'dhcp')
示例11: test_create
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import create [as 别名]
def test_create(self):
ctx = self.get_mock_ctx("CustomerGateway")
config = {CUSTOMERGATEWAY_ID: 'customer gateway'}
self.customer_gateway.resource_id = config[CUSTOMERGATEWAY_ID]
iface = MagicMock()
iface.create = self.mock_return({'CustomerGateway': config})
customer_gateway.create(ctx=ctx, iface=iface, resource_config=config)
self.assertEqual(self.customer_gateway.resource_id,
'customer gateway')
示例12: test_create
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import create [as 别名]
def test_create(self):
ctx = self.get_mock_ctx("NetworkInterface")
config = {NETWORKINTERFACE_ID: 'eni', SUBNET_ID: 'subnet'}
self.eni.resource_id = config[NETWORKINTERFACE_ID]
iface = MagicMock()
iface.create = self.mock_return({'NetworkInterface': config})
eni.create(ctx=ctx, iface=iface, resource_config=config)
self.assertEqual(self.eni.resource_id,
'eni')
示例13: test_create
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import create [as 别名]
def test_create(self):
ctx = self.get_mock_ctx("VpnGateway")
config = {VPNGATEWAY_ID: 'vpn gateway'}
self.vpn_gateway.resource_id = config[VPNGATEWAY_ID]
iface = MagicMock()
iface.create = self.mock_return({'VpnGateway': config})
vpn_gateway.create(ctx=ctx, iface=iface, resource_config=config)
self.assertEqual(self.vpn_gateway.resource_id,
'vpn gateway')
示例14: test_create
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import create [as 别名]
def test_create(self):
ctx = self.get_mock_ctx("PublicIp")
config = {ELASTICIP_ID: 'elasticip', INSTANCE_ID: 'instance'}
self.elasticip.resource_id = config[ELASTICIP_ID]
iface = MagicMock()
iface.create = self.mock_return(config)
elasticip.create(ctx=ctx, iface=iface, resource_config=config)
self.assertEqual(self.elasticip.resource_id,
'elasticip')
示例15: test_create
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import create [as 别名]
def test_create(self):
ctx = self.get_mock_ctx("Subnet")
config = {SUBNET_ID: 'subnet', CIDR_BLOCK: 'cidr_block',
VPC_ID: 'vpc'}
self.subnet.resource_id = config[SUBNET_ID]
iface = MagicMock()
iface.create = self.mock_return({SUBNET: config})
subnet.create(ctx=ctx, iface=iface, resource_config=config)
self.assertEqual(self.subnet.resource_id,
'subnet')