Best Python code snippet using lisa_python
test_bm_node.py
Source: test_bm_node.py
...19from nova.tests.baremetal.db import base20from nova.tests.baremetal.db import utils21from nova.virt.baremetal import db22class BareMetalNodesTestCase(base.BMDBTestCase):23 def _create_nodes(self):24 nodes = [25 utils.new_bm_node(pm_address='0', service_host="host1",26 memory_mb=100000, cpus=100, local_gb=10000),27 utils.new_bm_node(pm_address='1', service_host="host2",28 instance_uuid='A',29 memory_mb=100000, cpus=100, local_gb=10000),30 utils.new_bm_node(pm_address='2', service_host="host2",31 memory_mb=1000, cpus=1, local_gb=1000),32 utils.new_bm_node(pm_address='3', service_host="host2",33 memory_mb=1000, cpus=2, local_gb=1000),34 utils.new_bm_node(pm_address='4', service_host="host2",35 memory_mb=2000, cpus=1, local_gb=1000),36 utils.new_bm_node(pm_address='5', service_host="host2",37 memory_mb=2000, cpus=2, local_gb=1000),38 ]39 self.ids = []40 for n in nodes:41 ref = db.bm_node_create(self.context, n)42 self.ids.append(ref['id'])43 def test_get_all(self):44 r = db.bm_node_get_all(self.context)45 self.assertEquals(r, [])46 self._create_nodes()47 r = db.bm_node_get_all(self.context)48 self.assertEquals(len(r), 6)49 def test_get(self):50 self._create_nodes()51 r = db.bm_node_get(self.context, self.ids[0])52 self.assertEquals(r['pm_address'], '0')53 r = db.bm_node_get(self.context, self.ids[1])54 self.assertEquals(r['pm_address'], '1')55 self.assertRaises(56 exception.NodeNotFound,57 db.bm_node_get,58 self.context, -1)59 def test_get_by_service_host(self):60 self._create_nodes()61 r = db.bm_node_get_all(self.context, service_host=None)62 self.assertEquals(len(r), 6)63 r = db.bm_node_get_all(self.context, service_host="host1")64 self.assertEquals(len(r), 1)65 self.assertEquals(r[0]['pm_address'], '0')66 r = db.bm_node_get_all(self.context, service_host="host2")67 self.assertEquals(len(r), 5)68 pmaddrs = [x['pm_address'] for x in r]69 self.assertIn('1', pmaddrs)70 self.assertIn('2', pmaddrs)71 self.assertIn('3', pmaddrs)72 self.assertIn('4', pmaddrs)73 self.assertIn('5', pmaddrs)74 r = db.bm_node_get_all(self.context, service_host="host3")75 self.assertEquals(r, [])76 def test_get_associated(self):77 self._create_nodes()78 r = db.bm_node_get_associated(self.context, service_host=None)79 self.assertEquals(len(r), 1)80 self.assertEquals(r[0]['pm_address'], '1')81 r = db.bm_node_get_unassociated(self.context, service_host=None)82 self.assertEquals(len(r), 5)83 pmaddrs = [x['pm_address'] for x in r]84 self.assertIn('0', pmaddrs)85 self.assertIn('2', pmaddrs)86 self.assertIn('3', pmaddrs)87 self.assertIn('4', pmaddrs)88 self.assertIn('5', pmaddrs)89 def test_destroy(self):90 self._create_nodes()91 db.bm_node_destroy(self.context, self.ids[0])92 self.assertRaises(93 exception.NodeNotFound,94 db.bm_node_get,95 self.context, self.ids[0])96 r = db.bm_node_get_all(self.context)97 self.assertEquals(len(r), 5)98 def test_destroy_with_interfaces(self):99 self._create_nodes()100 if_a_id = db.bm_interface_create(self.context, self.ids[0],101 'aa:aa:aa:aa:aa:aa', None, None)102 if_b_id = db.bm_interface_create(self.context, self.ids[0],103 'bb:bb:bb:bb:bb:bb', None, None)104 if_x_id = db.bm_interface_create(self.context, self.ids[1],105 '11:22:33:44:55:66', None, None)106 db.bm_node_destroy(self.context, self.ids[0])107 self.assertRaises(108 exception.NovaException,109 db.bm_interface_get,110 self.context, if_a_id)111 self.assertRaises(112 exception.NovaException,113 db.bm_interface_get,114 self.context, if_b_id)115 # Another node's interface is not affected116 if_x = db.bm_interface_get(self.context, if_x_id)117 self.assertEqual(self.ids[1], if_x['bm_node_id'])118 self.assertRaises(119 exception.NodeNotFound,120 db.bm_node_get,121 self.context, self.ids[0])122 r = db.bm_node_get_all(self.context)123 self.assertEquals(len(r), 5)124 def test_find_free(self):125 self._create_nodes()126 fn = db.bm_node_find_free(self.context, 'host2')127 self.assertEqual(fn['pm_address'], '2')128 fn = db.bm_node_find_free(self.context, 'host2',129 memory_mb=500, cpus=2, local_gb=100)130 self.assertEqual(fn['pm_address'], '3')131 fn = db.bm_node_find_free(self.context, 'host2',132 memory_mb=1001, cpus=1, local_gb=1000)133 self.assertEqual(fn['pm_address'], '4')134 fn = db.bm_node_find_free(self.context, 'host2',135 memory_mb=2000, cpus=1, local_gb=1000)136 self.assertEqual(fn['pm_address'], '4')137 fn = db.bm_node_find_free(self.context, 'host2',138 memory_mb=2000, cpus=2, local_gb=1000)139 self.assertEqual(fn['pm_address'], '5')...
test_mpnode.py
Source: test_mpnode.py
...8 node.path = 'ff/0/1/ff/9'9 assert node.node_id == int(encoder.charset[9])10 node.path = '666'11 assert node.node_id == int(encoder.decode('666'))12def _create_nodes(ids: List[int]):13 nodes = []14 for i in ids:15 node = Project()16 node.path = str(i)17 nodes.append(node)18 return nodes19@pytest.mark.parametrize('row, expected', [20 (_create_nodes([0, 2]), 1),21 (_create_nodes([0, 1]), 2),22 (_create_nodes([]), 0),23 (_create_nodes([666]), 0),24 (_create_nodes([0, 1, 2, 4]), 3),25 (_create_nodes([0, 1, 3, 5]), 2),26 (_create_nodes([0, 1]), 2),27])28def test_next_id(row, expected):29 node = Project(parent=None)...
Check out the latest blogs from LambdaTest on this topic:
Automating testing is a crucial step in the development pipeline of a software product. In an agile development environment, where there is continuous development, deployment, and maintenance of software products, automation testing ensures that the end software products delivered are error-free.
Before we discuss the Joomla testing, let us understand the fundamentals of Joomla and how this content management system allows you to create and maintain web-based applications or websites without having to write and implement complex coding requirements.
The QA testing career includes following an often long, winding road filled with fun, chaos, challenges, and complexity. Financially, the spectrum is broad and influenced by location, company type, company size, and the QA tester’s experience level. QA testing is a profitable, enjoyable, and thriving career choice.
It’s strange to hear someone declare, “This can’t be tested.” In reply, I contend that everything can be tested. However, one must be pleased with the outcome of testing, which might include failure, financial loss, or personal injury. Could anything be tested when a claim is made with this understanding?
When it comes to UI components, there are two versatile methods that we can use to build it for your website: either we can use prebuilt components from a well-known library or framework, or we can develop our UI components from scratch.
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!!