How to use generate_random_security_group_id method in tempest

Best Python code snippet using tempest_python

test_security_groups_negative.py

Source:test_security_groups_negative.py Github

copy

Full Screen

...30 @test.services('network')31 def test_security_group_get_nonexistent_group(self):32 # Negative test:Should not be able to GET the details33 # of non-existent Security Group34 non_exist_id = self.generate_random_security_group_id()35 self.assertRaises(lib_exc.NotFound, self.client.show_security_group,36 non_exist_id)37 @decorators.skip_because(bug="1161411",38 condition=CONF.service_available.neutron)39 @test.attr(type=['negative'])40 @decorators.idempotent_id('1759c3cb-b0fc-44b7-86ce-c99236be911d')41 @test.services('network')42 def test_security_group_create_with_invalid_group_name(self):43 # Negative test: Security Group should not be created with group name44 # as an empty string/with white spaces/chars more than 25545 s_description = data_utils.rand_name('description')46 # Create Security Group with empty string as group name47 self.assertRaises(lib_exc.BadRequest,48 self.client.create_security_group,49 name="", description=s_description)50 # Create Security Group with white space in group name51 self.assertRaises(lib_exc.BadRequest,52 self.client.create_security_group,53 name=" ", description=s_description)54 # Create Security Group with group name longer than 255 chars55 s_name = 'securitygroup-'.ljust(260, '0')56 self.assertRaises(lib_exc.BadRequest,57 self.client.create_security_group,58 name=s_name, description=s_description)59 @decorators.skip_because(bug="1161411",60 condition=CONF.service_available.neutron)61 @test.attr(type=['negative'])62 @decorators.idempotent_id('777b6f14-aca9-4758-9e84-38783cfa58bc')63 @test.services('network')64 def test_security_group_create_with_invalid_group_description(self):65 # Negative test: Security Group should not be created with description66 # longer than 255 chars. Empty description is allowed by the API67 # reference, however.68 s_name = data_utils.rand_name('securitygroup')69 # Create Security Group with group description longer than 255 chars70 s_description = 'description-'.ljust(260, '0')71 self.assertRaises(lib_exc.BadRequest,72 self.client.create_security_group,73 name=s_name, description=s_description)74 @decorators.idempotent_id('9fdb4abc-6b66-4b27-b89c-eb215a956168')75 @testtools.skipIf(CONF.service_available.neutron,76 "Neutron allows duplicate names for security groups")77 @test.attr(type=['negative'])78 @test.services('network')79 def test_security_group_create_with_duplicate_name(self):80 # Negative test:Security Group with duplicate name should not81 # be created82 s_name = data_utils.rand_name('securitygroup')83 s_description = data_utils.rand_name('description')84 self.create_security_group(name=s_name, description=s_description)85 # Now try the Security Group with the same 'Name'86 self.assertRaises(lib_exc.BadRequest,87 self.client.create_security_group,88 name=s_name, description=s_description)89 @test.attr(type=['negative'])90 @decorators.idempotent_id('36a1629f-c6da-4a26-b8b8-55e7e5d5cd58')91 @test.services('network')92 def test_delete_the_default_security_group(self):93 # Negative test:Deletion of the "default" Security Group should Fail94 default_security_group_id = None95 body = self.client.list_security_groups()['security_groups']96 for i in range(len(body)):97 if body[i]['name'] == 'default':98 default_security_group_id = body[i]['id']99 break100 # Deleting the "default" Security Group101 self.assertRaises(lib_exc.BadRequest,102 self.client.delete_security_group,103 default_security_group_id)104 @test.attr(type=['negative'])105 @decorators.idempotent_id('6727c00b-214c-4f9e-9a52-017ac3e98411')106 @test.services('network')107 def test_delete_nonexistent_security_group(self):108 # Negative test:Deletion of a non-existent Security Group should fail109 non_exist_id = self.generate_random_security_group_id()110 self.assertRaises(lib_exc.NotFound,111 self.client.delete_security_group, non_exist_id)112 @test.attr(type=['negative'])113 @decorators.idempotent_id('1438f330-8fa4-4aeb-8a94-37c250106d7f')114 @test.services('network')115 def test_delete_security_group_without_passing_id(self):116 # Negative test:Deletion of a Security Group with out passing ID117 # should Fail118 self.assertRaises(lib_exc.NotFound,119 self.client.delete_security_group, '')120 @decorators.idempotent_id('00579617-fe04-4e1c-9d08-ca7467d2e34b')121 @testtools.skipIf(CONF.service_available.neutron,122 "Neutron does not check the security group ID")123 @test.attr(type=['negative'])124 @test.services('network')125 def test_update_security_group_with_invalid_sg_id(self):126 # Update security_group with invalid sg_id should fail127 s_name = data_utils.rand_name('sg')128 s_description = data_utils.rand_name('description')129 # Create a non int sg_id130 sg_id_invalid = data_utils.rand_name('sg')131 self.assertRaises(lib_exc.BadRequest,132 self.client.update_security_group, sg_id_invalid,133 name=s_name, description=s_description)134 @decorators.idempotent_id('cda8d8b4-59f8-4087-821d-20cf5a03b3b1')135 @testtools.skipIf(CONF.service_available.neutron,136 "Neutron does not check the security group name")137 @test.attr(type=['negative'])138 @test.services('network')139 def test_update_security_group_with_invalid_sg_name(self):140 # Update security_group with invalid sg_name should fail141 securitygroup = self.create_security_group()142 self.assertIn('id', securitygroup)143 securitygroup_id = securitygroup['id']144 # Update Security Group with group name longer than 255 chars145 s_new_name = 'securitygroup-'.ljust(260, '0')146 self.assertRaises(lib_exc.BadRequest,147 self.client.update_security_group,148 securitygroup_id, name=s_new_name)149 @decorators.idempotent_id('97d12b1c-a610-4194-93f1-ba859e718b45')150 @testtools.skipIf(CONF.service_available.neutron,151 "Neutron does not check the security group description")152 @test.attr(type=['negative'])153 @test.services('network')154 def test_update_security_group_with_invalid_sg_des(self):155 # Update security_group with invalid sg_des should fail156 securitygroup = self.create_security_group()157 self.assertIn('id', securitygroup)158 securitygroup_id = securitygroup['id']159 # Update Security Group with group description longer than 255 chars160 s_new_des = 'des-'.ljust(260, '0')161 self.assertRaises(lib_exc.BadRequest,162 self.client.update_security_group,163 securitygroup_id, description=s_new_des)164 @test.attr(type=['negative'])165 @decorators.idempotent_id('27edee9c-873d-4da6-a68a-3c256efebe8f')166 @test.services('network')167 def test_update_non_existent_security_group(self):168 # Update a non-existent Security Group should Fail169 non_exist_id = self.generate_random_security_group_id()170 s_name = data_utils.rand_name('sg')171 s_description = data_utils.rand_name('description')172 self.assertRaises(lib_exc.NotFound,173 self.client.update_security_group,174 non_exist_id, name=s_name,...

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