From 528cf0e21d886c35d14d24c0fb5d6ed69e6a5e59 Mon Sep 17 00:00:00 2001 From: Cat Cai Date: Tue, 12 Nov 2019 14:51:31 -0800 Subject: [PATCH] Run black to fix linting --- moto/ec2/models.py | 7 +++-- moto/ec2/responses/vpcs.py | 55 +++++++++++++++++++++++++++---------- tests/test_ec2/test_vpcs.py | 22 +++++++++++---- 3 files changed, 63 insertions(+), 21 deletions(-) diff --git a/moto/ec2/models.py b/moto/ec2/models.py index 5b4ef62f6..31056e4fd 100644 --- a/moto/ec2/models.py +++ b/moto/ec2/models.py @@ -2537,8 +2537,11 @@ class VPC(TaggedEC2Resource): # Doesn't check any route tables, maybe something for in the future? # See https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/vpc-classiclink.html#classiclink-limitations network_address = ipaddress.ip_network(self.cidr_block).network_address - if network_address not in ipaddress.ip_network("10.0.0.0/8") or network_address in ipaddress.ip_network( - "10.0.0.0/16") or network_address in ipaddress.ip_network("10.1.0.0/16"): + if ( + network_address not in ipaddress.ip_network("10.0.0.0/8") + or network_address in ipaddress.ip_network("10.0.0.0/16") + or network_address in ipaddress.ip_network("10.1.0.0/16") + ): self.classic_link_enabled = "true" return self.classic_link_enabled diff --git a/moto/ec2/responses/vpcs.py b/moto/ec2/responses/vpcs.py index f6b20f962..0fd198378 100644 --- a/moto/ec2/responses/vpcs.py +++ b/moto/ec2/responses/vpcs.py @@ -6,14 +6,23 @@ from moto.ec2.utils import filters_from_querystring class VPCs(BaseResponse): def _get_doc_date(self): - return "2013-10-15" if "Boto/" in self.headers.get("user-agent", "") else "2016-11-15" + return ( + "2013-10-15" + if "Boto/" in self.headers.get("user-agent", "") + else "2016-11-15" + ) def create_vpc(self): - cidr_block = self._get_param('CidrBlock') - instance_tenancy = self._get_param('InstanceTenancy', if_none='default') - amazon_provided_ipv6_cidr_blocks = self._get_param('AmazonProvidedIpv6CidrBlock') - vpc = self.ec2_backend.create_vpc(cidr_block, instance_tenancy, - amazon_provided_ipv6_cidr_block=amazon_provided_ipv6_cidr_blocks) + cidr_block = self._get_param("CidrBlock") + instance_tenancy = self._get_param("InstanceTenancy", if_none="default") + amazon_provided_ipv6_cidr_blocks = self._get_param( + "AmazonProvidedIpv6CidrBlock" + ) + vpc = self.ec2_backend.create_vpc( + cidr_block, + instance_tenancy, + amazon_provided_ipv6_cidr_block=amazon_provided_ipv6_cidr_blocks, + ) doc_date = self._get_doc_date() template = self.response_template(CREATE_VPC_RESPONSE) return template.render(vpc=vpc, doc_date=doc_date) @@ -28,7 +37,11 @@ class VPCs(BaseResponse): vpc_ids = self._get_multi_param("VpcId") filters = filters_from_querystring(self.querystring) vpcs = self.ec2_backend.get_all_vpcs(vpc_ids=vpc_ids, filters=filters) - doc_date = '2013-10-15' if 'Boto/' in self.headers.get('user-agent', '') else '2016-11-15' + doc_date = ( + "2013-10-15" + if "Boto/" in self.headers.get("user-agent", "") + else "2016-11-15" + ) template = self.response_template(DESCRIBE_VPCS_RESPONSE) return template.render(vpcs=vpcs, doc_date=doc_date) @@ -45,22 +58,32 @@ class VPCs(BaseResponse): filters = filters_from_querystring(self.querystring) vpcs = self.ec2_backend.get_all_vpcs(vpc_ids=vpc_ids, filters=filters) doc_date = self._get_doc_date() - template = self.response_template(DESCRIBE_VPC_CLASSIC_LINK_DNS_SUPPORT_RESPONSE) + template = self.response_template( + DESCRIBE_VPC_CLASSIC_LINK_DNS_SUPPORT_RESPONSE + ) return template.render(vpcs=vpcs, doc_date=doc_date) def enable_vpc_classic_link_dns_support(self): vpc_id = self._get_param("VpcId") - classic_link_dns_supported = self.ec2_backend.enable_vpc_classic_link_dns_support(vpc_id=vpc_id) + classic_link_dns_supported = self.ec2_backend.enable_vpc_classic_link_dns_support( + vpc_id=vpc_id + ) doc_date = self._get_doc_date() template = self.response_template(ENABLE_VPC_CLASSIC_LINK_DNS_SUPPORT_RESPONSE) - return template.render(classic_link_dns_supported=classic_link_dns_supported, doc_date=doc_date) + return template.render( + classic_link_dns_supported=classic_link_dns_supported, doc_date=doc_date + ) def disable_vpc_classic_link_dns_support(self): vpc_id = self._get_param("VpcId") - classic_link_dns_supported = self.ec2_backend.disable_vpc_classic_link_dns_support(vpc_id=vpc_id) + classic_link_dns_supported = self.ec2_backend.disable_vpc_classic_link_dns_support( + vpc_id=vpc_id + ) doc_date = self._get_doc_date() template = self.response_template(DISABLE_VPC_CLASSIC_LINK_DNS_SUPPORT_RESPONSE) - return template.render(classic_link_dns_supported=classic_link_dns_supported, doc_date=doc_date) + return template.render( + classic_link_dns_supported=classic_link_dns_supported, doc_date=doc_date + ) def describe_vpc_classic_link(self): vpc_ids = self._get_multi_param("VpcId") @@ -75,14 +98,18 @@ class VPCs(BaseResponse): classic_link_enabled = self.ec2_backend.enable_vpc_classic_link(vpc_id=vpc_id) doc_date = self._get_doc_date() template = self.response_template(ENABLE_VPC_CLASSIC_LINK_RESPONSE) - return template.render(classic_link_enabled=classic_link_enabled, doc_date=doc_date) + return template.render( + classic_link_enabled=classic_link_enabled, doc_date=doc_date + ) def disable_vpc_classic_link(self): vpc_id = self._get_param("VpcId") classic_link_enabled = self.ec2_backend.disable_vpc_classic_link(vpc_id=vpc_id) doc_date = self._get_doc_date() template = self.response_template(DISABLE_VPC_CLASSIC_LINK_RESPONSE) - return template.render(classic_link_enabled=classic_link_enabled, doc_date=doc_date) + return template.render( + classic_link_enabled=classic_link_enabled, doc_date=doc_date + ) def modify_vpc_attribute(self): vpc_id = self._get_param("VpcId") diff --git a/tests/test_ec2/test_vpcs.py b/tests/test_ec2/test_vpcs.py index c8a931333..1bc3ddd98 100644 --- a/tests/test_ec2/test_vpcs.py +++ b/tests/test_ec2/test_vpcs.py @@ -747,10 +747,15 @@ def test_describe_classic_link_multiple(): ec2.meta.client.enable_vpc_classic_link(VpcId=vpc2.id) response = ec2.meta.client.describe_vpc_classic_link(VpcIds=[vpc1.id, vpc2.id]) - expected = [{"VpcId": vpc1.id, "ClassicLinkDnsSupported": False}, {"VpcId": vpc2.id, "ClassicLinkDnsSupported": True}] + expected = [ + {"VpcId": vpc1.id, "ClassicLinkDnsSupported": False}, + {"VpcId": vpc2.id, "ClassicLinkDnsSupported": True}, + ] # Ensure response is sorted, because they can come in random order - assert response.get("Vpcs").sort(key=lambda x: x["VpcId"]) == expected.sort(key=lambda x: x["VpcId"]) + assert response.get("Vpcs").sort(key=lambda x: x["VpcId"]) == expected.sort( + key=lambda x: x["VpcId"] + ) @mock_ec2 @@ -808,8 +813,15 @@ def test_describe_classic_link_dns_support_multiple(): vpc2 = ec2.create_vpc(CidrBlock="10.0.0.0/16") ec2.meta.client.enable_vpc_classic_link_dns_support(VpcId=vpc2.id) - response = ec2.meta.client.describe_vpc_classic_link_dns_support(VpcIds=[vpc1.id, vpc2.id]) - expected = [{"VpcId": vpc1.id, "ClassicLinkDnsSupported": False}, {"VpcId": vpc2.id, "ClassicLinkDnsSupported": True}] + response = ec2.meta.client.describe_vpc_classic_link_dns_support( + VpcIds=[vpc1.id, vpc2.id] + ) + expected = [ + {"VpcId": vpc1.id, "ClassicLinkDnsSupported": False}, + {"VpcId": vpc2.id, "ClassicLinkDnsSupported": True}, + ] # Ensure response is sorted, because they can come in random order - assert response.get("Vpcs").sort(key=lambda x: x["VpcId"]) == expected.sort(key=lambda x: x["VpcId"]) + assert response.get("Vpcs").sort(key=lambda x: x["VpcId"]) == expected.sort( + key=lambda x: x["VpcId"] + )