def test_create_security_group(): mock = mock_ec2() mock.start() conn = boto3.resource('ec2', region_name='us-east-1') conn.create_security_group(GroupName="vps", Description="Security group", VpcId='11111') mock.stop()
def setup(self): self.mocks = [mock_ec2()] for mock in self.mocks: mock.start() ec2_client = boto3.client("ec2", region_name="us-east-1") ec2 = boto3.resource("ec2", region_name="us-east-1") vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16") self.vpc_id = vpc.id self.ec2 = ec2 self.ec2_client = ec2_client
def setUpMock(self): """ Let Moto take over all socket communications """ self.ec2mock = mock_ec2() self.ec2mock.start() self.s3mock = mock_s3() self.s3mock.start() HTTPretty.register_uri( method="GET", uri="https://swift.rc.nectar.org.au:8888/v1/" "AUTH_377/cloud-bridge/aws/instance_data.json", body=""" [ { "family": "General Purpose", "enhanced_networking": false, "vCPU": 1, "generation": "previous", "ebs_iops": 0, "network_performance": "Low", "ebs_throughput": 0, "vpc": { "ips_per_eni": 4, "max_enis": 2 }, "arch": [ "i386", "x86_64" ], "linux_virtualization_types": [], "ebs_optimized": false, "storage": { "ssd": false, "devices": 1, "size": 160 }, "max_bandwidth": 0, "instance_type": "t1.micro", "ECU": 1.0, "memory": 1.7 } ] """ )
def setUpMock(self): """ Let Moto take over all socket communications """ self.ec2mock = mock_ec2() self.ec2mock.start() self.s3mock = mock_s3() self.s3mock.start() HTTPretty.register_uri( method="GET", uri="https://d168wakzal7fp0.cloudfront.net/aws_instance_data.json", body=""" [ { "family": "General Purpose", "enhanced_networking": false, "vCPU": 1, "generation": "current", "ebs_iops": 0, "network_performance": "Low", "ebs_throughput": 0, "vpc": { "ips_per_eni": 2, "max_enis": 2 }, "arch": [ "x86_64" ], "linux_virtualization_types": [ "HVM" ], "ebs_optimized": false, "storage": null, "max_bandwidth": 0, "instance_type": "t2.nano", "ECU": "variable, "memory": 0.5, "ebs_max_bandwidth": 0 } ] """ )
def ec2(): with mock_ec2(): yield boto3.client('ec2', region_name='us-east-1')
def ec2(): """Mocked EC2 Fixture.""" with mock_ec2(): yield boto3.client('ec2', region_name='us-east-1')
def ec2(): with mock_ec2(): yield boto3.client("ec2")