How to use _create_subnet method in tempest

Best Python code snippet using tempest_python

test_models.py

Source:test_models.py Github

copy

Full Screen

...4 def test_ip_address_string_representation(self):5 ipaddress = self.ipaddress_model(ip_address='entry ip_address')6 self.assertEqual(str(ipaddress), ipaddress.ip_address)7 def test_invalid_ipaddress_subnet(self):8 self._create_subnet(subnet='192.168.2.0/24')9 try:10 self._create_ipaddress(ip_address='10.0.0.2',11 subnet=self.subnet_model.objects.first())12 except ValidationError as e:13 self.assertTrue(e.message_dict['ip_address'] == ['IP address does not belong to the subnet'])14 else:15 self.fail('ValidationError not raised')16 def test_valid_ipaddress_subnet(self):17 self._create_subnet(subnet='192.168.2.0/24')18 try:19 self._create_ipaddress(ip_address='192.168.2.1',20 subnet=self.subnet_model.objects.first())21 except ValidationError:22 self.fail('ValidationError raised')23 def test_used_ipaddress(self):24 self._create_subnet(subnet='10.0.0.0/24')25 self._create_ipaddress(ip_address='10.0.0.1',26 subnet=self.subnet_model.objects.first())27 try:28 self._create_ipaddress(ip_address='10.0.0.1',29 subnet=self.subnet_model.objects.first())30 except ValidationError as e:31 self.assertTrue(e.message_dict['ip_address'] == ['IP address already used.'])32 else:33 self.fail('ValidationError not raised')34 def test_invalid_ipaddress(self):35 error_message = "'1234325' does not appear to be an IPv4 or IPv6 address"36 self._create_subnet(subnet='10.0.0.0/24')37 try:38 self._create_ipaddress(ip_address='1234325',39 subnet=self.subnet_model.objects.first())40 except ValueError as e:41 self.assertEqual(str(e), error_message)42 else:43 self.fail('ValueError not raised')44 def test_available_ipv4(self):45 subnet = self._create_subnet(subnet='10.0.0.0/24')46 self._create_ipaddress(ip_address='10.0.0.1',47 subnet=subnet)48 ipaddr = subnet.get_first_available_ip()49 self.assertEqual(str(ipaddr), '10.0.0.2')50 def test_available_ipv6(self):51 subnet = self._create_subnet(subnet='fdb6:21b:a477::9f7/64')52 self._create_ipaddress(ip_address='fdb6:21b:a477::1',53 subnet=subnet)54 ipaddr = subnet.get_first_available_ip()55 self.assertEqual(str(ipaddr), 'fdb6:21b:a477::2')56 def test_unavailable_ip(self):57 subnet = self._create_subnet(subnet='10.0.0.0/32')58 ipaddr = subnet.get_first_available_ip()59 self.assertEqual(ipaddr, None)60 def test_request_ipv4(self):61 subnet = self._create_subnet(subnet='10.0.0.0/24')62 self._create_ipaddress(ip_address='10.0.0.1',63 subnet=subnet)64 ipaddr = subnet.request_ip()65 self.assertEqual(str(ipaddr), '10.0.0.2')66 def test_request_ipv6(self):67 subnet = self._create_subnet(subnet='fdb6:21b:a477::9f7/64')68 self._create_ipaddress(ip_address='fdb6:21b:a477::1',69 subnet=subnet)70 ipaddr = subnet.request_ip()71 self.assertEqual(str(ipaddr), 'fdb6:21b:a477::2')72 def test_unavailable_request_ip(self):73 subnet = self._create_subnet(subnet='10.0.0.0/32')74 ipaddr = subnet.request_ip()75 self.assertEqual(ipaddr, None)76 def test_subnet_string_representation(self):77 subnet = self.subnet_model(subnet='entry subnet')78 self.assertEqual(str(subnet), str(subnet.subnet))79 def test_subnet_string_representation_with_name(self):80 subnet = self.subnet_model(subnet='entry subnet', name='test1')81 self.assertEqual(str(subnet), '{0} {1}'.format(subnet.name, str(subnet.subnet)))82 def test_valid_cidr_field(self):83 try:84 self._create_subnet(subnet='22.0.0.0/24')85 except ValidationError:86 self.fail('ValidationError raised')87 def test_invalid_cidr_field(self):88 error_message = ["'192.192.192.192.192' does not appear to be an IPv4 or IPv6 network"]89 try:90 self._create_subnet(subnet='192.192.192.192.192')91 except ValidationError as e:92 self.assertTrue(e.message_dict['subnet'] == error_message)93 else:94 self.fail('ValidationError not raised')95 def test_overlapping_subnet(self):96 self._create_subnet(subnet='192.168.2.0/24')97 try:98 self._create_subnet(subnet='192.168.2.0/25')99 except ValidationError as e:100 self.assertTrue(e.message_dict['subnet'] == ['Subnet overlaps with 192.168.2.0/24'])101 else:102 self.fail('ValidationError not raised')103 def test_invalid_master_subnet(self):104 subnet = self._create_subnet(subnet='10.20.0.0/24')105 try:106 self._create_subnet(subnet='192.168.2.0/24', master_subnet=subnet)107 except ValidationError as e:108 self.assertTrue(e.message_dict['master_subnet'] == ['Invalid master subnet'])109 else:110 self.fail('ValidationError not raised')111 def test_valid_subnet_relation_tree(self):112 subnet1 = self._create_subnet(subnet='12.0.56.0/24')113 try:114 subnet2 = self._create_subnet(subnet='12.0.56.0/25', master_subnet=subnet1)115 self._create_subnet(subnet='12.0.56.0/26', master_subnet=subnet2)116 except ValidationError:117 self.fail('Correct master_subnet not accepted')118 def test_invalid_subnet_relation_tree(self):119 subnet1 = self._create_subnet(subnet='12.0.56.0/24')120 self._create_subnet(subnet='12.0.56.0/25', master_subnet=subnet1)121 try:122 self._create_subnet(subnet='12.0.56.0/26', master_subnet=subnet1)123 except ValidationError as e:124 self.assertEqual(e.message_dict['subnet'], ['Subnet overlaps with 12.0.56.0/25'])125 else:126 self.fail('ValidationError not raised')127 def test_save_none_subnet_fails(self):128 try:129 self._create_subnet(subnet=None)130 except ValidationError as err:131 self.assertTrue(err.message_dict['subnet'] == ['This field cannot be null.'])132 else:133 self.fail('ValidationError not raised')134 def test_save_blank_subnet_fails(self):135 try:136 self._create_subnet(subnet='')137 except ValidationError as err:138 self.assertTrue(err.message_dict['subnet'] == ['This field cannot be blank.'])139 else:140 self.fail('ValidationError not raised')141 def test_retrieves_ipv4_ipnetwork_type(self):142 instance = self._create_subnet(subnet='10.1.2.0/24')143 instance = self.subnet_model.objects.get(pk=instance.pk)144 self.assertIsInstance(instance.subnet, IPv4Network)145 def test_retrieves_ipv6_ipnetwork_type(self):146 instance = self._create_subnet(subnet='2001:db8::0/32')147 instance = self.subnet_model.objects.get(pk=instance.pk)148 self.assertIsInstance(instance.subnet, IPv6Network)149 def test_incompatible_ipadresses(self):150 instance = self._create_subnet(subnet='10.1.2.0/24')151 try:152 self._create_subnet(subnet='2001:db8::0/32', master_subnet=instance)153 except TypeError as err:154 self.assertEqual(str(err), '2001:db8::/32 and 10.1.2.0/24 are not of the same version')155 else:156 self.fail('TypeError not raised')157 def test_ipadresses_missing_attribute(self):158 instance = self._create_subnet(subnet='10.1.2.0/24')159 instance2 = self._create_subnet(subnet='10.1.3.0/25')160 del instance.subnet.network_address161 try:162 instance2.subnet.subnet_of(instance.subnet)163 except AttributeError as err:164 self.assertIn(str(err), '\'IPv4Network\' object has no attribute \'network_address\'')165 else:...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful