Best Python code snippet using localstack_python
test_vpcs.py
Source: test_vpcs.py
...22 def setUpClass(cls):23 super(VPCTest, cls).setUpClass()24 if not base.TesterStateHolder().get_vpc_enabled():25 raise cls.skipException('VPC is disabled')26 def test_create_delete_vpc(self):27 cidr = '10.1.0.0/16'28 data = self.client.create_vpc(CidrBlock=cidr)29 vpc_id = data['Vpc']['VpcId']30 dv_clean = self.addResourceCleanUp(self.client.delete_vpc,31 VpcId=vpc_id)32 self.assertEqual(cidr, data['Vpc']['CidrBlock'])33 if CONF.aws.run_incompatible_tests:34 # NOTE(andrey-mp): not ready35 self.assertEqual('default', data['Vpc']['InstanceTenancy'])36 self.assertIsNotNone(data['Vpc'].get('DhcpOptionsId'))37 self.get_vpc_waiter().wait_available(vpc_id)38 self.client.delete_vpc(VpcId=vpc_id)39 self.cancelResourceCleanUp(dv_clean)40 self.get_vpc_waiter().wait_delete(vpc_id)41 self.assertRaises('InvalidVpcID.NotFound',42 self.client.describe_vpcs,43 VpcIds=[vpc_id])44 self.assertRaises('InvalidVpcID.NotFound',45 self.client.delete_vpc,46 VpcId=vpc_id)47 def test_create_more_than_one_vpc(self):48 cidr = '10.0.0.0/16'49 data = self.client.create_vpc(CidrBlock=cidr)50 vpc_id1 = data['Vpc']['VpcId']51 rc1 = self.addResourceCleanUp(self.client.delete_vpc, VpcId=vpc_id1)52 self.get_vpc_waiter().wait_available(vpc_id1)53 cidr = '10.1.0.0/16'54 data = self.client.create_vpc(CidrBlock=cidr)55 vpc_id2 = data['Vpc']['VpcId']56 rc2 = self.addResourceCleanUp(self.client.delete_vpc, VpcId=vpc_id2)57 self.get_vpc_waiter().wait_available(vpc_id2)58 self.client.delete_vpc(VpcId=vpc_id1)59 self.cancelResourceCleanUp(rc1)60 self.get_vpc_waiter().wait_delete(vpc_id1)61 self.client.delete_vpc(VpcId=vpc_id2)62 self.cancelResourceCleanUp(rc2)63 self.get_vpc_waiter().wait_delete(vpc_id2)64 def test_describe_vpcs_base(self):65 cidr = '10.1.0.0/16'66 data = self.client.create_vpc(CidrBlock=cidr)67 vpc_id = data['Vpc']['VpcId']68 dv_clean = self.addResourceCleanUp(self.client.delete_vpc,69 VpcId=vpc_id)70 self.get_vpc_waiter().wait_available(vpc_id)71 # NOTE(andrey-mp): by real id72 data = self.client.describe_vpcs(VpcIds=[vpc_id])73 self.assertEqual(1, len(data['Vpcs']))74 # NOTE(andrey-mp): by fake id75 self.assertRaises('InvalidVpcID.NotFound',76 self.client.describe_vpcs,77 VpcIds=['vpc-0'])78 self.client.delete_vpc(VpcId=vpc_id)79 self.cancelResourceCleanUp(dv_clean)80 self.get_vpc_waiter().wait_delete(vpc_id)81 def test_describe_vpcs_filters(self):82 cidr = '10.163.0.0/16'83 data = self.client.create_vpc(CidrBlock=cidr)84 vpc_id = data['Vpc']['VpcId']85 dv_clean = self.addResourceCleanUp(self.client.delete_vpc,86 VpcId=vpc_id)87 self.get_vpc_waiter().wait_available(vpc_id)88 # NOTE(andrey-mp): by filter real cidr89 data = self.client.describe_vpcs(90 Filters=[{'Name': 'cidr', 'Values': [cidr]}])91 self.assertEqual(1, len(data['Vpcs']))92 # NOTE(andrey-mp): by filter fake cidr93 data = self.client.describe_vpcs(94 Filters=[{'Name': 'cidr', 'Values': ['123.0.0.0/16']}])95 self.assertEqual(0, len(data['Vpcs']))96 # NOTE(andrey-mp): by fake filter97 self.assertRaises('InvalidParameterValue',98 self.client.describe_vpcs,99 Filters=[{'Name': 'fake', 'Values': ['fake']}])100 data = self.client.delete_vpc(VpcId=vpc_id)101 self.cancelResourceCleanUp(dv_clean)102 self.get_vpc_waiter().wait_delete(vpc_id)103 @testtools.skipUnless(CONF.aws.run_incompatible_tests,104 "Invalid request on checking vpc atributes.")105 def test_vpc_attributes(self):106 cidr = '10.1.0.0/16'107 data = self.client.create_vpc(CidrBlock=cidr)108 vpc_id = data['Vpc']['VpcId']109 dv_clean = self.addResourceCleanUp(self.client.delete_vpc,110 VpcId=vpc_id)111 self.get_vpc_waiter().wait_available(vpc_id)112 self._check_attribute(vpc_id, 'EnableDnsHostnames')113 self._check_attribute(vpc_id, 'EnableDnsSupport')114 data = self.client.delete_vpc(VpcId=vpc_id)115 self.cancelResourceCleanUp(dv_clean)116 self.get_vpc_waiter().wait_delete(vpc_id)117 def _check_attribute(self, vpc_id, attribute):118 req_attr = attribute[0].lower() + attribute[1:]119 data = self.client.describe_vpc_attribute(VpcId=vpc_id,120 Attribute=req_attr)121 attr = data[attribute].get('Value')122 self.assertIsNotNone(attr)123 kwargs = {'VpcId': vpc_id, attribute: {'Value': not attr}}124 data = self.client.modify_vpc_attribute(*[], **kwargs)125 data = self.client.describe_vpc_attribute(VpcId=vpc_id,126 Attribute=req_attr)127 self.assertNotEqual(attr, data[attribute].get('Value'))128 def test_create_with_invalid_cidr(self):129 def _rollback(fn_data):130 self.client.delete_vpc(VpcId=fn_data['Vpc']['VpcId'])131 # NOTE(andrey-mp): The largest uses a /16 netmask132 self.assertRaises('InvalidVpc.Range',133 self.client.create_vpc, rollback_fn=_rollback,134 CidrBlock='10.0.0.0/15')135 # NOTE(andrey-mp): The smallest VPC you can create uses a /28 netmask136 self.assertRaises('InvalidVpc.Range',137 self.client.create_vpc, rollback_fn=_rollback,138 CidrBlock='10.0.0.0/29')139 def test_describe_non_existing_vpc_by_id(self):140 vpc_id = 'vpc-00000000'141 self.assertRaises('InvalidVpcID.NotFound',142 self.client.describe_vpcs,143 VpcIds=[vpc_id])144 def test_describe_non_existing_vpc_by_cidr(self):145 data = self.client.describe_vpcs(146 Filters=[{'Name': 'cidr', 'Values': ['123.0.0.0/16']}])147 self.assertEqual(0, len(data['Vpcs']))148 def test_describe_with_invalid_filter(self):149 cidr = '10.1.0.0/16'150 data = self.client.create_vpc(CidrBlock=cidr)151 vpc_id = data['Vpc']['VpcId']152 dv_clean = self.addResourceCleanUp(self.client.delete_vpc,153 VpcId=vpc_id)154 self.get_vpc_waiter().wait_available(vpc_id)155 self.assertRaises('InvalidParameterValue',156 self.client.describe_vpcs,157 Filters=[{'Name': 'unknown', 'Values': ['unknown']}])158 data = self.client.delete_vpc(VpcId=vpc_id)159 self.cancelResourceCleanUp(dv_clean)...
clear_ch2.py
Source: clear_ch2.py
...30def delete_subnet(ec2_client, subnet_id):31 # https://boto3.readthedocs.io/en/latest/reference/services/ec2.html#EC2.Client.delete_subnet32 response = ec2_client.delete_subnet(SubnetId=subnet_id)33 print(response)34def delete_vpc(ec2_client, vpc_id):35 # https://boto3.readthedocs.io/en/latest/reference/services/ec2.html#EC2.Client.delete_vpc36 response = ec2_client.delete_vpc(VpcId=vpc_id)37 print(response)38def delete_each_vpc_items(ec2_client, aws):39 # éé ã«è§£æ¾ãã¦ãã40 # ããã©ã«ãã²ã¼ãã¦ã§ã¤ããã¤ã³ã¿ã¼ãããã²ã¼ãã¦ã§ã¤ãåé¤41 delete_route_from_route_table(ec2_client, aws['public_route_table_id'])42 # ã«ã¼ããã¼ãã«ã¨ãµããããã®é¢é£ä»ããåé¤43 disassociate_route_table(ec2_client, aws['public_route_table_association_id'])44 # ã«ã¼ããã¼ãã«ã®åé¤45 delete_route_table(ec2_client, aws['public_route_table_id'])46 # ã¤ã³ã¿ã¼ãããã²ã¼ãã¦ã§ã¤ã®åé¤47 # ã¤ã³ã¿ã¼ãããã²ã¼ãã¦ã§ã¤ãVPCé åããåé¤48 detach_internet_gateway_from_vpc(ec2_client, aws['internet_gateway_id'], aws['vpc_id'])49 # ã¤ã³ã¿ã¼ãããã²ã¼ãã¦ã§ã¤ã®åé¤50 delete_internet_gateway(ec2_client, aws['internet_gateway_id'])51 # ãµããããã®åé¤52 delete_subnet(ec2_client, aws['public_subnet_id'])53 # VPCé åã®åé¤54 delete_vpc(ec2_client, aws_keys['vpc_id'])55if __name__ == '__main__':56 # Profileããã¼ã57 session = boto3.Session(profile_name='my-profile')58 # ã¯ã©ã¤ã¢ã³ãã¨ãªã½ã¼ã¹ãä½ã£ã¦ãã59 client = create_ec2_client(session)60 resource = create_ec2_resource(session)61 # AWSã®å種IDããã¼ã62 with open('aws.json', mode='r') as f:63 aws_keys = json.load(f)64 # ããããã®ãªãã¸ã§ã¯ãããä½æããã®ã¨ã¯éé ã«åé¤ããå ´å65 delete_each_vpc_items(client, aws_keys)66 # GUIã§ã¯VPCãåé¤ããã¨ããããã®ãªãã¸ã§ã¯ããèªåçã«åé¤ãããããboto3ã ã¨ã¨ã©ã¼ã§åé¤ã§ããªã67 # botocore.exceptions.ClientError: An error occurred (DependencyViolation) when calling the DeleteVpc operation:68 # The vpc 'vpc-a781dac3' has dependencies and cannot be deleted....
Check out the latest blogs from LambdaTest on this topic:
The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.
QA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.
Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.
Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!