Best Python code snippet using tempest_python
test_ports.py
Source:test_ports.py  
...130        self.assertEqual(2, len(port['fixed_ips']))131        # Update the port to return to a single IP address132        port = self.update_port(port, fixed_ips=fixed_ip_1)133        self.assertEqual(1, len(port['fixed_ips']))134    def _update_port_with_security_groups(self, security_groups_names):135        post_body = {"network_id": self.network['id']}136        self.create_subnet(self.network)137        security_groups_list = list()138        for name in security_groups_names:139            _, group_create_body = self.client.create_security_group(140                name=name)141            self.addCleanup(self.client.delete_security_group,142                            group_create_body['security_group']['id'])143            security_groups_list.append(group_create_body['security_group']144                                        ['id'])145        # Create a port146        _, body = self.client.create_port(**post_body)147        self.addCleanup(self.client.delete_port, body['port']['id'])148        port = body['port']149        # Update the port with security groups150        update_body = {"security_groups": security_groups_list}151        _, body = self.client.update_port(152            port['id'], **update_body)153        # Verify the security groups updated to port154        port_show = body['port']155        for security_group in security_groups_list:156            self.assertIn(security_group, port_show['security_groups'])157    @test.attr(type='smoke')158    def test_update_port_with_security_group(self):159        self._update_port_with_security_groups(160            [data_utils.rand_name('secgroup')])161    @test.attr(type='smoke')162    def test_update_port_with_two_security_groups(self):163        self._update_port_with_security_groups(164            [data_utils.rand_name('secgroup'),165             data_utils.rand_name('secgroup')])166class PortsTestXML(PortsTestJSON):167    _interface = 'xml'168class PortsAdminExtendedAttrsTestJSON(base.BaseAdminNetworkTest):169    _interface = 'json'170    @classmethod171    def resource_setup(cls):172        super(PortsAdminExtendedAttrsTestJSON, cls).resource_setup()173        cls.identity_client = cls._get_identity_admin_client()174        cls.tenant = cls.identity_client.get_tenant_by_name(175            CONF.identity.tenant_name)176        cls.network = cls.create_network()177        cls.host_id = socket.gethostname()...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!!
