Best Python code snippet using localstack_python
test_dhcp_options.py
Source:test_dhcp_options.py
...24 def setUpClass(cls):25 super(DhcpOptionsTest, cls).setUpClass()26 if not base.TesterStateHolder().get_vpc_enabled():27 raise cls.skipException('VPC is disabled')28 def test_create_delete_dhcp_options(self):29 kwargs = {30 'DhcpConfigurations': [31 {'Key': 'domain-name',32 'Values': ['my.com', 'it.com']},33 {'Key': 'domain-name-servers',34 'Values': ['8.8.8.8', '8.8.4.4']},35 {'Key': 'ntp-servers',36 'Values': ['1.2.3.4']},37 {'Key': 'netbios-name-servers',38 'Values': ['4.3.2.1']},39 {'Key': 'netbios-node-type',40 'Values': ['2']},41 ],42 }43 data = self.client.create_dhcp_options(*[], **kwargs)44 options = data['DhcpOptions']45 id = options['DhcpOptionsId']46 res_clean = self.addResourceCleanUp(self.client.delete_dhcp_options,47 DhcpOptionsId=id)48 self.assertEqual(5, len(options['DhcpConfigurations']))49 for cfg in options['DhcpConfigurations']:50 self.assertEqual(2, len(cfg))51 if cfg['Key'] == 'domain-name':52 self.assertEqual(2, len(cfg['Values']))53 values = [i['Value'] for i in cfg['Values']]54 self.assertIn('my.com', values)55 self.assertIn('it.com', values)56 elif cfg['Key'] == 'domain-name-servers':57 self.assertEqual(2, len(cfg['Values']))58 values = [i['Value'] for i in cfg['Values']]59 self.assertIn('8.8.8.8', values)60 self.assertIn('8.8.4.4', values)61 elif cfg['Key'] == 'ntp-servers':62 self.assertEqual(1, len(cfg['Values']))63 self.assertEqual('1.2.3.4', cfg['Values'][0]['Value'])64 elif cfg['Key'] == 'netbios-name-servers':65 self.assertEqual(1, len(cfg['Values']))66 self.assertEqual('4.3.2.1', cfg['Values'][0]['Value'])67 elif cfg['Key'] == 'netbios-node-type':68 self.assertEqual(1, len(cfg['Values']))69 self.assertEqual('2', cfg['Values'][0]['Value'])70 else:71 self.fail('Unknown key name in result - %s' % cfg['Key'])72 data = self.client.delete_dhcp_options(DhcpOptionsId=id)73 self.cancelResourceCleanUp(res_clean)74 def test_invalid_create_delete(self):75 def _rollback(fn_data):76 self.client.delete_dhcp_options(77 DhcpOptionsId=fn_data['DhcpOptions']['DhcpOptionsId'])78 kwargs = {79 'DhcpConfigurations': [80 ],81 }82 self.assertRaises('MissingParameter',83 self.client.create_dhcp_options,84 **kwargs)85 kwargs = {86 'DhcpConfigurations': [{'Key': 'aaa', 'Values': []}],87 }88 self.assertRaises('InvalidParameterValue',89 self.client.create_dhcp_options, rollback_fn=_rollback,90 **kwargs)91 kwargs = {92 'DhcpConfigurations': [{'Key': 'domain-name', 'Values': []}],93 }94 self.assertRaises('InvalidParameterValue',95 self.client.create_dhcp_options, rollback_fn=_rollback,96 **kwargs)97 def test_describe_dhcp_options(self):98 kwargs = {99 'DhcpConfigurations': [100 {'Key': 'domain-name',101 'Values': ['my.com']},102 ],103 }104 data = self.client.create_dhcp_options(*[], **kwargs)105 options = data['DhcpOptions']106 id = options['DhcpOptionsId']107 res_clean = self.addResourceCleanUp(self.client.delete_dhcp_options,108 DhcpOptionsId=id)109 time.sleep(10)110 kwargs = {111 'DhcpOptionsIds': [id],112 }113 data = self.client.describe_dhcp_options(*[], **kwargs)114 self.assertEqual(1, len(data['DhcpOptions']))115 options = data['DhcpOptions'][0]116 self.assertEqual(id, options['DhcpOptionsId'])117 self.assertEqual(1, len(options['DhcpConfigurations']))118 cfg = options['DhcpConfigurations'][0]119 self.assertEqual(2, len(cfg))120 self.assertEqual('domain-name', cfg['Key'])121 self.assertEqual(1, len(cfg['Values']))122 self.assertIn('my.com', cfg['Values'][0]['Value'])123 data = self.client.delete_dhcp_options(DhcpOptionsId=id)124 self.cancelResourceCleanUp(res_clean)125 def test_associate_dhcp_options(self):126 kwargs = {127 'DhcpConfigurations': [128 {'Key': 'domain-name',129 'Values': ['my.com']},130 ],131 }132 data = self.client.create_dhcp_options(*[], **kwargs)133 options = data['DhcpOptions']134 id = options['DhcpOptionsId']135 res_clean = self.addResourceCleanUp(self.client.delete_dhcp_options,136 DhcpOptionsId=id)137 cidr = '10.0.0.0/24'138 data = self.client.create_vpc(CidrBlock=cidr)139 vpc_id = data['Vpc']['VpcId']140 dv_clean = self.addResourceCleanUp(self.client.delete_vpc,141 VpcId=vpc_id)142 kwargs = {143 'DhcpOptionsId': id,144 'VpcId': vpc_id,145 }146 data = self.client.associate_dhcp_options(*[], **kwargs)147 self.assertRaises('DependencyViolation',148 self.client.delete_dhcp_options,149 DhcpOptionsId=id)150 data = self.client.delete_vpc(VpcId=vpc_id)151 self.cancelResourceCleanUp(dv_clean)152 self.get_vpc_waiter().wait_delete(vpc_id)153 data = self.client.delete_dhcp_options(DhcpOptionsId=id)...
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!!