Best Python code snippet using tempest_python
base.py
Source: base.py
...25):26 @classmethod27 def resource_setup(cls):28 super(BaseFlowClassifierTest, cls).resource_setup()29 if not test.is_extension_enabled('flow_classifier', 'network'):30 msg = "FlowClassifier Extension not enabled."31 raise cls.skipException(msg)32 cls.network = cls.create_network()33 cls.subnet = cls.create_subnet(cls.network)34 cls.host_id = socket.gethostname()35 @classmethod36 def resource_cleanup(cls):37 if not test.is_extension_enabled('flow_classifier', 'network'):38 msg = "FlowClassifier Extension not enabled."39 raise cls.skipException(msg)40 super(BaseFlowClassifierTest, cls).resource_cleanup()41 @classmethod42 def _create_port(cls, network, **kwargs):43 body = cls.admin_ports_client.create_port(44 network_id=network['id'],45 **kwargs)46 port = body['port']47 return port48 def _try_create_flowclassifier(self, **kwargs):49 if 'logical_source_port' not in kwargs:50 port_kwargs = {"binding:host_id": self.host_id}51 port = self._create_port(network=self.network, **port_kwargs)52 self.addCleanup(self._try_delete_port, port['id'])53 kwargs['logical_source_port'] = port['id']54 if 'source_ip_prefix' not in kwargs:55 port_ip_prefix = str(netaddr.IPNetwork(56 port['fixed_ips'][0]['ip_address']))57 kwargs['source_ip_prefix'] = port_ip_prefix58 fc = self.create_flowclassifier(**kwargs)59 self.addCleanup(self._try_delete_flowclassifier, fc['id'])60 return fc61 def _try_delete_port(self, port_id):62 try:63 self.admin_ports_client.delete_port(port_id)64 except lib_exc.NotFound:65 pass66 body = self.admin_ports_client.list_ports()67 ports_list = body['ports']68 self.assertNotIn(port_id, [n['id'] for n in ports_list])69 def _try_delete_flowclassifier(self, fc_id):70 # delete flowclassifier, if it exists71 try:72 self.flowclassifier_client.delete_flowclassifier(fc_id)73 # if flowclassifier is not found, this means it was deleted74 except lib_exc.NotFound:75 pass76 body = self.flowclassifier_client.list_flowclassifiers()77 fc_list = body['flow_classifiers']78 self.assertNotIn(fc_id, [n['id'] for n in fc_list])79class BaseSfcTest(80 sfc_client.SfcClientMixin, BaseFlowClassifierTest81):82 @classmethod83 def resource_setup(cls):84 super(BaseSfcTest, cls).resource_setup()85 if not test.is_extension_enabled('sfc', 'network'):86 msg = "Sfc Extension not enabled."87 raise cls.skipException(msg)88 @classmethod89 def resource_cleanup(cls):90 if not test.is_extension_enabled('sfc', 'network'):91 msg = "Sfc Extension not enabled."92 raise cls.skipException(msg)93 super(BaseSfcTest, cls).resource_cleanup()94 def _try_create_port_pair(self, **kwargs):95 if 'ingress' not in kwargs or 'egress' not in 'kwargs':96 router = self.admin_routers_client.create_router(97 name=data_utils.rand_name('router-'))['router']98 self.addCleanup(99 self.admin_routers_client.delete_router, router['id'])100 port_kwargs = {"binding:host_id": self.host_id}101 port = self._create_port(102 network=self.network, **port_kwargs)103 self.addCleanup(self._try_delete_port, port['id'])104 self.admin_routers_client.add_router_interface(...
test_networks.py
Source: test_networks.py
...34 # Verify the details of a network35 body = self.client.show_network(self.network['id'])36 network = body['network']37 fields = ['id', 'name']38 if test.is_extension_enabled('net-mtu', 'network'):39 fields.append('mtu')40 for key in fields:41 self.assertEqual(network[key], self.network[key])42 @test.idempotent_id('867819bb-c4b6-45f7-acf9-90edcf70aa5e')43 def test_show_network_fields(self):44 # Verify specific fields of a network45 fields = ['id', 'name']46 if test.is_extension_enabled('net-mtu', 'network'):47 fields.append('mtu')48 body = self.client.show_network(self.network['id'],49 fields=fields)50 network = body['network']51 self.assertEqual(sorted(network.keys()), sorted(fields))52 for field_name in fields:53 self.assertEqual(network[field_name], self.network[field_name])54 @test.idempotent_id('c72c1c0c-2193-4aca-ccc4-b1442640bbbb')55 @test.requires_ext(extension="standard-attr-description",56 service="network")57 def test_create_update_network_description(self):58 body = self.create_network(description='d1')59 self.assertEqual('d1', body['description'])60 net_id = body['id']61 body = self.client.list_networks(id=net_id)['networks'][0]62 self.assertEqual('d1', body['description'])63 body = self.client.update_network(body['id'],64 description='d2')65 self.assertEqual('d2', body['network']['description'])66 body = self.client.list_networks(id=net_id)['networks'][0]67 self.assertEqual('d2', body['description'])68 @test.idempotent_id('6ae6d24f-9194-4869-9c85-c313cb20e080')69 def test_list_networks_fields(self):70 # Verify specific fields of the networks71 fields = ['id', 'name']72 if test.is_extension_enabled('net-mtu', 'network'):73 fields.append('mtu')74 body = self.client.list_networks(fields=fields)75 networks = body['networks']76 self.assertNotEmpty(networks, "Network list returned is empty")77 for network in networks:78 self.assertEqual(sorted(network.keys()), sorted(fields))79class NetworksSearchCriteriaTest(base.BaseSearchCriteriaTest):80 resource = 'network'81 list_kwargs = {'shared': False}82 @classmethod83 def resource_setup(cls):84 super(NetworksSearchCriteriaTest, cls).resource_setup()85 for name in cls.resource_names:86 cls.create_network(network_name=name)...
Check out the latest blogs from LambdaTest on this topic:
I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.
“Test frequently and early.” If you’ve been following my testing agenda, you’re probably sick of hearing me repeat that. However, it is making sense that if your tests detect an issue soon after it occurs, it will be easier to resolve. This is one of the guiding concepts that makes continuous integration such an effective method. I’ve encountered several teams who have a lot of automated tests but don’t use them as part of a continuous integration approach. There are frequently various reasons why the team believes these tests cannot be used with continuous integration. Perhaps the tests take too long to run, or they are not dependable enough to provide correct results on their own, necessitating human interpretation.
Sometimes, in our test code, we need to handle actions that apparently could not be done automatically. For example, some mouse actions such as context click, double click, drag and drop, mouse movements, and some special key down and key up actions. These specific actions could be crucial depending on the project context.
JavaScript is one of the most widely used programming languages. This popularity invites a lot of JavaScript development and testing frameworks to ease the process of working with it. As a result, numerous JavaScript testing frameworks can be used to perform unit testing.
When software developers took years to create and introduce new products to the market is long gone. Users (or consumers) today are more eager to use their favorite applications with the latest bells and whistles. However, users today don’t have the patience to work around bugs, errors, and design flaws. People have less self-control, and if your product or application doesn’t make life easier for users, they’ll leave for a better solution.
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!!