本文整理汇总了Python中unittest.mock.MagicMock.region方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.region方法的具体用法?Python MagicMock.region怎么用?Python MagicMock.region使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.region方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_component_auto_scaling_group_configurable_properties2
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import region [as 别名]
def test_component_auto_scaling_group_configurable_properties2():
definition = {"Resources": {}}
configuration = {
'Name': 'Foo',
'InstanceType': 't2.micro',
'Image': 'foo',
'SpotPrice': 0.250
}
args = MagicMock()
args.region = "foo"
info = {
'StackName': 'FooStack',
'StackVersion': 'FooVersion'
}
result = component_auto_scaling_group(definition, configuration, args, info, False, MagicMock())
assert result["Resources"]["FooConfig"]["Properties"]["SpotPrice"] == 0.250
del configuration["SpotPrice"]
result = component_auto_scaling_group(definition, configuration, args, info, False, MagicMock())
assert "SpotPrice" not in result["Resources"]["FooConfig"]["Properties"]
示例2: test_component_redis_node
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import region [as 别名]
def test_component_redis_node(monkeypatch):
mock_string = "foo"
configuration = {
"Name": mock_string,
"SecurityGroups": "",
}
info = {'StackName': 'foobar'*5, 'StackVersion': '0.1'}
definition = {"Resources": {}}
args = MagicMock()
args.region = "foo"
mock_string_result = MagicMock()
mock_string_result.return_value = mock_string
monkeypatch.setattr('senza.components.redis_node.resolve_security_groups', mock_string_result)
result = component_redis_node(definition, configuration, args, info, False)
assert 'RedisCacheCluster' in result['Resources']
assert mock_string == result['Resources']['RedisCacheCluster']['Properties']['VpcSecurityGroupIds']
assert mock_string == result['Resources']['RedisCacheCluster']['Properties']['ClusterName']
assert 1 == result['Resources']['RedisCacheCluster']['Properties']['NumCacheNodes']
assert 'Engine' in result['Resources']['RedisCacheCluster']['Properties']
assert 'EngineVersion' in result['Resources']['RedisCacheCluster']['Properties']
assert 'CacheNodeType' in result['Resources']['RedisCacheCluster']['Properties']
assert 'CacheSubnetGroupName' in result['Resources']['RedisCacheCluster']['Properties']
assert 'RedisSubnetGroup' in result['Resources']
assert 'SubnetIds' in result['Resources']['RedisSubnetGroup']['Properties']
示例3: test_component_load_balancer_healthcheck
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import region [as 别名]
def test_component_load_balancer_healthcheck(monkeypatch):
configuration = {
"Name": "test_lb",
"SecurityGroups": "",
"HTTPPort": "9999",
"HealthCheckPath": "/healthcheck"
}
definition = {"Resources": {}}
args = MagicMock()
args.region = "foo"
mock_string_result = MagicMock()
mock_string_result.return_value = "foo"
monkeypatch.setattr('senza.components.find_ssl_certificate_arn', mock_string_result)
monkeypatch.setattr('senza.components.resolve_security_groups', mock_string_result)
result = component_load_balancer(definition, configuration, args, MagicMock(), False)
# Defaults to HTTP
assert "HTTP:9999/healthcheck" == result["Resources"]["test_lb"]["Properties"]["HealthCheck"]["Target"]
# Supports other AWS protocols
configuration["HealthCheckProtocol"] = "TCP"
result = component_load_balancer(definition, configuration, args, MagicMock(), False)
assert "TCP:9999/healthcheck" == result["Resources"]["test_lb"]["Properties"]["HealthCheck"]["Target"]
# Will fail on incorrect protocol
configuration["HealthCheckProtocol"] = "MYFANCYPROTOCOL"
try:
component_load_balancer(definition, configuration, args, MagicMock(), False)
except click.UsageError:
pass
except:
assert False, "check for supported protocols failed"
示例4: test_component_load_balancer_namelength
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import region [as 别名]
def test_component_load_balancer_namelength(monkeypatch):
configuration = {
"Name": "test_lb",
"SecurityGroups": "",
"HTTPPort": "9999",
"HealthCheckPath": "/healthcheck"
}
info = {'StackName': 'foobar'*5, 'StackVersion': '0.1'}
definition = {"Resources": {}}
args = MagicMock()
args.region = "foo"
mock_string_result = MagicMock()
mock_string_result.return_value = "foo"
monkeypatch.setattr('senza.components.elastic_load_balancer.find_ssl_certificate_arn', mock_string_result)
monkeypatch.setattr('senza.components.elastic_load_balancer.resolve_security_groups', mock_string_result)
try:
component_elastic_load_balancer(definition, configuration, args, info, False)
except click.UsageError:
pass
except:
assert False, "check for supported protocols returns unknown Exception"
else:
assert False, "check for supported protocols failed"
示例5: test_component_stups_auto_configuration
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import region [as 别名]
def test_component_stups_auto_configuration(monkeypatch):
args = MagicMock()
args.region = 'myregion'
configuration = {
'Name': 'Config',
'AvailabilityZones': ['az-1']
}
sn1 = MagicMock()
sn1.id = 'sn-1'
sn1.tags.get.return_value = 'dmz-1'
sn1.availability_zone = 'az-1'
sn2 = MagicMock()
sn2.id = 'sn-2'
sn2.tags.get.return_value = 'dmz-2'
sn2.availability_zone = 'az-2'
sn3 = MagicMock()
sn3.id = 'sn-3'
sn3.tags.get.return_value = 'internal-3'
sn3.availability_zone = 'az-1'
vpc = MagicMock()
vpc.get_all_subnets.return_value = [sn1, sn2, sn3]
image = MagicMock()
ec2 = MagicMock()
ec2.get_all_images.return_value = [image]
monkeypatch.setattr('boto.vpc.connect_to_region', lambda x: vpc)
monkeypatch.setattr('boto.ec2.connect_to_region', lambda x: ec2)
result = component_stups_auto_configuration({}, configuration, args, MagicMock(), False)
assert {'myregion': {'Subnets': ['sn-1']}} == result['Mappings']['LoadBalancerSubnets']
assert {'myregion': {'Subnets': ['sn-3']}} == result['Mappings']['ServerSubnets']
示例6: test_component_load_balancer_cert_arn
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import region [as 别名]
def test_component_load_balancer_cert_arn(monkeypatch):
configuration = {
"Name": "test_lb",
"SecurityGroups": "",
"HTTPPort": "9999",
"SSLCertificateId": "foo2"
}
info = {'StackName': 'foobar', 'StackVersion': '0.1'}
definition = {"Resources": {}}
args = MagicMock()
args.region = "foo"
mock_string_result = MagicMock()
mock_string_result.return_value = "foo"
monkeypatch.setattr('senza.components.elastic_load_balancer.resolve_security_groups', mock_string_result)
m_acm = MagicMock()
m_acm_certificate = MagicMock()
m_acm_certificate.arn = "foo"
m_acm.get_certificates.return_value = iter([m_acm_certificate])
m_acm_certificate.is_arn_certificate.return_value = True
m_acm_certificate.get_by_arn.return_value = True
monkeypatch.setattr('senza.components.elastic_load_balancer.ACM', m_acm)
monkeypatch.setattr('senza.components.elastic_load_balancer.ACMCertificate', m_acm_certificate)
# issue 105: support additional ELB properties
result = component_elastic_load_balancer(definition, configuration, args, info, False, MagicMock())
assert "foo2" == result["Resources"]["test_lb"]["Properties"]["Listeners"][0]["SSLCertificateId"]
示例7: test_component_stups_auto_configuration
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import region [as 别名]
def test_component_stups_auto_configuration(monkeypatch):
args = MagicMock()
args.region = "myregion"
configuration = {"Name": "Config", "AvailabilityZones": ["az-1"]}
sn1 = MagicMock()
sn1.id = "sn-1"
sn1.tags.get.return_value = "dmz-1"
sn1.availability_zone = "az-1"
sn2 = MagicMock()
sn2.id = "sn-2"
sn2.tags.get.return_value = "dmz-2"
sn2.availability_zone = "az-2"
sn3 = MagicMock()
sn3.id = "sn-3"
sn3.tags.get.return_value = "internal-3"
sn3.availability_zone = "az-1"
vpc = MagicMock()
vpc.get_all_subnets.return_value = [sn1, sn2, sn3]
image = MagicMock()
ec2 = MagicMock()
ec2.get_all_images.return_value = [image]
monkeypatch.setattr("boto.vpc.connect_to_region", lambda x: vpc)
monkeypatch.setattr("boto.ec2.connect_to_region", lambda x: ec2)
result = component_stups_auto_configuration({}, configuration, args, MagicMock(), False)
assert {"myregion": {"Subnets": ["sn-1"]}} == result["Mappings"]["LoadBalancerSubnets"]
assert {"myregion": {"Subnets": ["sn-3"]}} == result["Mappings"]["ServerSubnets"]
示例8: test_component_load_balancer_idletimeout
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import region [as 别名]
def test_component_load_balancer_idletimeout(monkeypatch):
configuration = {
"Name": "test_lb",
"SecurityGroups": "",
"HTTPPort": "9999",
"ConnectionSettings": {"IdleTimeout": 300}
}
info = {'StackName': 'foobar', 'StackVersion': '0.1'}
definition = {"Resources": {}}
args = MagicMock()
args.region = "foo"
mock_string_result = MagicMock()
mock_string_result.return_value = "foo"
monkeypatch.setattr('senza.components.elastic_load_balancer.resolve_security_groups', mock_string_result)
m_acm = MagicMock()
m_acm_certificate = MagicMock()
m_acm_certificate.arn = "foo"
m_acm.get_certificates.return_value = iter([m_acm_certificate])
monkeypatch.setattr('senza.components.elastic_load_balancer.ACM', m_acm)
# issue 105: support additional ELB properties
result = component_elastic_load_balancer(definition, configuration, args, info, False, MagicMock())
assert 300 == result["Resources"]["test_lb"]["Properties"]["ConnectionSettings"]["IdleTimeout"]
assert 'HTTPPort' not in result["Resources"]["test_lb"]["Properties"]
示例9: test_component_stups_auto_configuration
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import region [as 别名]
def test_component_stups_auto_configuration(monkeypatch):
args = MagicMock()
args.region = 'myregion'
configuration = {
'Name': 'Config',
'AvailabilityZones': ['az-1']
}
sn1 = MagicMock()
sn1.id = 'sn-1'
sn1.tags = [{'Key': 'Name', 'Value': 'dmz-1'}]
sn1.availability_zone = 'az-1'
sn2 = MagicMock()
sn2.id = 'sn-2'
sn2.tags = [{'Key': 'Name', 'Value': 'dmz-2'}]
sn2.availability_zone = 'az-2'
sn3 = MagicMock()
sn3.id = 'sn-3'
sn3.tags = [{'Key': 'Name', 'Value': 'internal-3'}]
sn3.availability_zone = 'az-1'
ec2 = MagicMock()
ec2.subnets.filter.return_value = [sn1, sn2, sn3]
image = MagicMock()
ec2.images.filter.return_value = [image]
monkeypatch.setattr('boto3.resource', lambda x, y: ec2)
result = component_stups_auto_configuration({}, configuration, args, MagicMock(), False, MagicMock())
assert {'myregion': {'Subnets': ['sn-1']}} == result['Mappings']['LoadBalancerSubnets']
assert {'myregion': {'Subnets': ['sn-3']}} == result['Mappings']['ServerSubnets']
示例10: test_component_subnet_auto_configuration
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import region [as 别名]
def test_component_subnet_auto_configuration(monkeypatch):
configuration = {
'PublicOnly': True,
'VpcId': 'vpc-123'
}
info = {'StackName': 'foobar', 'StackVersion': '0.1'}
definition = {"Resources": {}}
args = MagicMock()
args.region = "foo"
subnet1 = MagicMock()
subnet1.id = 'subnet-1'
subnet2 = MagicMock()
subnet2.id = 'subnet-2'
ec2 = MagicMock()
ec2.subnets.filter.return_value = [subnet1, subnet2]
monkeypatch.setattr('boto3.resource', lambda *args: ec2)
result = component_subnet_auto_configuration(definition, configuration, args, info, False, MagicMock())
assert ['subnet-1', 'subnet-2'] == result['Mappings']['ServerSubnets']['foo']['Subnets']
configuration = {
'PublicOnly': False,
'VpcId': 'vpc-123'
}
result = component_subnet_auto_configuration(definition, configuration, args, info, False, MagicMock())
assert ['subnet-1', 'subnet-2'] == result['Mappings']['ServerSubnets']['foo']['Subnets']
示例11: test_component_redis_cluster
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import region [as 别名]
def test_component_redis_cluster(monkeypatch):
mock_string = "foo"
configuration = {
"Name": mock_string,
"SecurityGroups": "",
}
info = {'StackName': 'foobar' * 5, 'StackVersion': '0.1'}
definition = {"Resources": {}}
args = MagicMock()
args.region = "foo"
mock_string_result = MagicMock()
mock_string_result.return_value = mock_string
monkeypatch.setattr('senza.components.redis_cluster.resolve_security_groups', mock_string_result)
result = component_redis_cluster(definition, configuration, args, info, False, MagicMock())
assert 'RedisReplicationGroup' in result['Resources']
assert mock_string == result['Resources']['RedisReplicationGroup']['Properties']['SecurityGroupIds']
assert 2 == result['Resources']['RedisReplicationGroup']['Properties']['NumCacheClusters']
assert result['Resources']['RedisReplicationGroup']['Properties']['AutomaticFailoverEnabled']
assert 'Engine' in result['Resources']['RedisReplicationGroup']['Properties']
assert 'EngineVersion' in result['Resources']['RedisReplicationGroup']['Properties']
assert 'CacheNodeType' in result['Resources']['RedisReplicationGroup']['Properties']
assert 'CacheSubnetGroupName' in result['Resources']['RedisReplicationGroup']['Properties']
assert 'CacheParameterGroupName' in result['Resources']['RedisReplicationGroup']['Properties']
assert 'RedisSubnetGroup' in result['Resources']
assert 'SubnetIds' in result['Resources']['RedisSubnetGroup']['Properties']
示例12: test_weighted_dns_load_balancer
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import region [as 别名]
def test_weighted_dns_load_balancer(monkeypatch, boto_client, boto_resource): # noqa: F811
senza.traffic.DNS_ZONE_CACHE = {}
configuration = {
"Name": "test_lb",
"SecurityGroups": "",
"HTTPPort": "9999",
'MainDomain': 'great.api.zo.ne',
'VersionDomain': 'version.api.zo.ne'
}
info = {'StackName': 'foobar', 'StackVersion': '0.1'}
definition = {"Resources": {}}
args = MagicMock()
args.region = "foo"
mock_string_result = MagicMock()
mock_string_result.return_value = "foo"
monkeypatch.setattr('senza.components.elastic_load_balancer.resolve_security_groups', mock_string_result)
m_acm = MagicMock()
m_acm_certificate = MagicMock()
m_acm_certificate.arn = "foo"
m_acm.get_certificates.return_value = iter([m_acm_certificate])
monkeypatch.setattr('senza.components.elastic_load_balancer.ACM', m_acm)
result = component_weighted_dns_elastic_load_balancer(definition,
configuration,
args,
info,
False,
AccountArguments('dummyregion'))
assert 'MainDomain' not in result["Resources"]["test_lb"]["Properties"]
示例13: test_component_load_balancer_namelength
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import region [as 别名]
def test_component_load_balancer_namelength(monkeypatch):
configuration = {
"Name": "test_lb",
"SecurityGroups": "",
"HTTPPort": "9999",
"HealthCheckPath": "/healthcheck"
}
info = {'StackName': 'foobar' * 5, 'StackVersion': '0.1'}
definition = {"Resources": {}}
args = MagicMock()
args.region = "foo"
mock_string_result = MagicMock()
mock_string_result.return_value = "foo"
monkeypatch.setattr('senza.components.elastic_load_balancer.resolve_security_groups', mock_string_result)
m_acm = MagicMock()
m_acm_certificate = MagicMock()
m_acm_certificate.arn = "foo"
m_acm.get_certificates.return_value = iter([m_acm_certificate])
monkeypatch.setattr('senza.components.elastic_load_balancer.ACM', m_acm)
result = component_elastic_load_balancer(definition, configuration, args, info, False, MagicMock())
lb_name = result['Resources']['test_lb']['Properties']['LoadBalancerName']
assert lb_name == 'foobarfoobarfoobarfoobarfoob-0.1'
assert len(lb_name) == 32
示例14: test_weighted_dns_load_balancer_with_different_domains
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import region [as 别名]
def test_weighted_dns_load_balancer_with_different_domains(monkeypatch, # noqa: F811
boto_client,
boto_resource):
senza.traffic.DNS_ZONE_CACHE = {}
boto_client['route53'].list_hosted_zones.return_value = {
'HostedZones': [HOSTED_ZONE_ZO_NE_DEV,
HOSTED_ZONE_ZO_NE_COM],
'IsTruncated': False,
'MaxItems': '100'}
configuration = {
"Name": "test_lb",
"SecurityGroups": "",
"HTTPPort": "9999",
'MainDomain': 'great.api.zo.ne.com',
'VersionDomain': 'version.api.zo.ne.dev'
}
info = {'StackName': 'foobar', 'StackVersion': '0.1'}
definition = {"Resources": {}}
args = MagicMock()
args.region = "foo"
mock_string_result = MagicMock()
mock_string_result.return_value = "foo"
monkeypatch.setattr('senza.components.elastic_load_balancer.resolve_security_groups', mock_string_result)
m_acm = MagicMock()
m_acm_certificate = MagicMock()
m_acm_certificate.arn = "foo"
m_acm.get_certificates.return_value = iter([m_acm_certificate])
monkeypatch.setattr('senza.components.elastic_load_balancer.ACM', m_acm)
result = component_weighted_dns_elastic_load_balancer(definition,
configuration,
args,
info,
False,
AccountArguments('dummyregion'))
assert 'zo.ne.com.' == result["Resources"]["test_lbMainDomain"]["Properties"]['HostedZoneName']
assert 'zo.ne.dev.' == result["Resources"]["test_lbVersionDomain"]["Properties"]['HostedZoneName']
configuration = {
"Name": "test_lb",
"SecurityGroups": "",
"HTTPPort": "9999",
'MainDomain': 'this.does.not.exists.com',
'VersionDomain': 'this.does.not.exists.com'
}
senza.traffic.DNS_ZONE_CACHE = {}
with pytest.raises(AttributeError):
result = component_weighted_dns_elastic_load_balancer(definition,
configuration,
args,
info,
False,
AccountArguments('dummyregion'))
示例15: test_component_auto_scaling_group_configurable_properties
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import region [as 别名]
def test_component_auto_scaling_group_configurable_properties():
definition = {"Resources": {}}
configuration = {
'Name': 'Foo',
'InstanceType': 't2.micro',
'Image': 'foo',
'AutoScaling': {
'Minimum': 2,
'Maximum': 10,
'SuccessRequires': '4 within 30m',
'MetricType': 'CPU',
'Period': 60,
'ScaleUpThreshold': 50,
'ScaleDownThreshold': 20,
'EvaluationPeriods': 1,
'Cooldown': 30,
'Statistic': 'Maximum'
}
}
args = MagicMock()
args.region = "foo"
info = {
'StackName': 'FooStack',
'StackVersion': 'FooVersion'
}
result = component_auto_scaling_group(definition, configuration, args, info, False, MagicMock())
assert result["Resources"]["FooScaleUp"] is not None
assert result["Resources"]["FooScaleUp"]["Properties"] is not None
assert result["Resources"]["FooScaleUp"]["Properties"]["ScalingAdjustment"] == "1"
assert result["Resources"]["FooScaleUp"]["Properties"]["Cooldown"] == "30"
assert result["Resources"]["FooScaleDown"] is not None
assert result["Resources"]["FooScaleDown"]["Properties"] is not None
assert result["Resources"]["FooScaleDown"]["Properties"]["Cooldown"] == "30"
assert result["Resources"]["FooScaleDown"]["Properties"]["ScalingAdjustment"] == "-1"
assert result["Resources"]["Foo"] is not None
assert result["Resources"]["Foo"]["CreationPolicy"] is not None
assert result["Resources"]["Foo"]["CreationPolicy"]["ResourceSignal"] is not None
assert result["Resources"]["Foo"]["CreationPolicy"]["ResourceSignal"]["Timeout"] == "PT30M"
assert result["Resources"]["Foo"]["CreationPolicy"]["ResourceSignal"]["Count"] == "4"
assert result["Resources"]["Foo"]["Properties"] is not None
assert result["Resources"]["Foo"]["Properties"]["HealthCheckType"] == "EC2"
assert result["Resources"]["Foo"]["Properties"]["MinSize"] == 2
assert result["Resources"]["Foo"]["Properties"]["DesiredCapacity"] == 2
assert result["Resources"]["Foo"]["Properties"]["MaxSize"] == 10
expected_desc = "Scale-down if CPU < 20% for 1.0 minutes (Maximum)"
assert result["Resources"]["FooCPUAlarmHigh"]["Properties"]["Statistic"] == "Maximum"
assert result["Resources"]["FooCPUAlarmLow"]["Properties"]["Period"] == "60"
assert result["Resources"]["FooCPUAlarmHigh"]["Properties"]["EvaluationPeriods"] == "1"
assert result["Resources"]["FooCPUAlarmLow"]["Properties"]["AlarmDescription"] == expected_desc