Best Python code snippet using tempest_python
test_nova.py
Source:test_nova.py
...242 mock_novaclient.assert_called_once_with(self.ctx)243 mock_aggregates.add_host.assert_called_once_with(244 mock_aggregate.id, 'fake_host')245 @mock.patch('masakari.compute.nova.novaclient')246 def test_lock_server(self, mock_novaclient):247 uuid = uuidsentinel.fake_server248 mock_servers = mock.MagicMock()249 mock_novaclient.return_value = mock.MagicMock(servers=mock_servers)250 self.api.lock_server(self.ctx, uuid)251 mock_novaclient.assert_called_once_with(self.ctx)252 mock_servers.lock.assert_called_once_with(uuidsentinel.fake_server)253 @mock.patch('masakari.compute.nova.novaclient')254 def test_unlock_server(self, mock_novaclient):255 uuid = uuidsentinel.fake_server256 mock_servers = mock.MagicMock()257 mock_novaclient.return_value = mock.MagicMock(servers=mock_servers)258 self.api.unlock_server(self.ctx, uuid)259 mock_novaclient.assert_called_once_with(self.ctx)260 mock_servers.unlock.assert_called_once_with(uuidsentinel.fake_server)...
test_server_misc_policy_actions_rbac.py
Source:test_server_misc_policy_actions_rbac.py
...109 @rbac_rule_validation.action(110 service="nova",111 rule="os_compute_api:os-lock-server:lock")112 @decorators.idempotent_id('b81e10fb-1864-498f-8c1d-5175c6fec5fb')113 def test_lock_server(self):114 """Test lock server, part of os-lock-server."""115 self.rbac_utils.switch_role(self, toggle_rbac_role=True)116 self.servers_client.lock_server(self.server_id)117 self.addCleanup(self.servers_client.unlock_server, self.server_id)118 @rbac_rule_validation.action(119 service="nova",120 rule="os_compute_api:os-lock-server:unlock")121 @decorators.idempotent_id('d50ef8e8-4bce-11e7-b114-b2f933d5fe66')122 def test_unlock_server(self):123 """Test unlock server, part of os-lock-server."""124 self.servers_client.lock_server(self.server_id)125 self.addCleanup(self.servers_client.unlock_server, self.server_id)126 self.rbac_utils.switch_role(self, toggle_rbac_role=True)127 self.servers_client.unlock_server(self.server_id)...
generate_example_data.py
Source:generate_example_data.py
1import random2import time3files = [4 'network/linux_net.py',5 'test.py',6 'tests/unit/api/openstack/compute/admin_only_action_common.py',7 'tests/unit/api/openstack/compute/test_admin_actions.py',8 'tests/unit/api/openstack/compute/test_block_device_mapping.py',9 'tests/unit/api/openstack/compute/test_lock_server.py',10 'tests/unit/api/openstack/compute/test_migrate_server.py',11 'tests/unit/api/openstack/compute/test_migrations.py',12 'tests/unit/api/openstack/compute/test_pause_server.py',13 'tests/unit/api/openstack/compute/test_quotas.py',14 'tests/unit/api/openstack/compute/test_suspend_server.py',15 'tests/unit/api/openstack/compute/test_virtual_interfaces.py',16 'tests/unit/api/openstack/compute/test_volumes.py',17 'tests/unit/cells/fakes.py',18 'tests/unit/cells/test_cells_manager.py',19 'tests/unit/cells/test_cells_messaging.py',20 'tests/unit/cells/test_cells_rpc_driver.py',21 'tests/unit/compute/test_compute_api.py',22 'tests/unit/conductor/tasks/test_live_migrate.py',23 'tests/unit/conductor/test_conductor.py',24 'tests/unit/consoleauth/test_consoleauth.py',25 'tests/unit/network/test_linux_net.py',26 'tests/unit/network/test_manager.py',27 'tests/unit/network/test_neutronv2.py',28 'tests/unit/objects/test_instance.py',29 'tests/unit/test_service.py',30 'tests/unit/virt/libvirt/test_driver.py',31 'tests/unit/virt/test_block_device.py',32 'tests/unit/virt/test_virt_drivers.py',33 'tests/unit/virt/vmwareapi/test_driver_api.py',34 'tests/unit/virt/xenapi/image/test_utils.py',35 'tests/unit/virt/xenapi/image/test_vdi_through_dev.py',36 'tests/unit/virt/xenapi/test_vm_utils.py',37 'tests/unit/virt/xenapi/test_vmops.py',38 'tests/unit/virt/xenapi/test_xenapi.py',39]40with open('data/num_matched_files.csv', 'w') as f:41 ts = int(time.time())42 hr = 60*6043 records = 10044 c = ''45 for i in range(0, records):46 cts = ts-((records-i)*hr)47 val = len(files)-int((i/(float(records))*len(files)))48 c += '{0},{1}'.format(cts, val) + '\n'49 f.write(c)50with open('data/num_matched_lines.csv', 'w') as f:51 ts = int(time.time())52 hr = 60*6053 records = 100054 todo = 180055 c = ''56 for i in range(0, records):57 cts = ts-((records-i)*hr)58 done = random.randint(0, int(todo/float(100)))59 todo -= done60 c += '{0},{1}'.format(cts, todo) + '\n'...
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!!