How to use mock_domains method in tempest

Best Python code snippet using tempest_python

dispvm.py

Source:dispvm.py Github

copy

Full Screen

1import unittest.mock as mock23import asyncio45import vanir.vm.dispvm6import vanir.vm.appvm7import vanir.vm.templatevm8import vanir.tests9import vanir.tests.vm10import vanir.tests.vm.appvm1112class TestApp(vanir.tests.vm.TestApp):13 def __init__(self):14 super(TestApp, self).__init__()15 self.qid_counter = 11617 def add_new_vm(self, cls, **kwargs):18 qid = self.qid_counter19 self.qid_counter += 120 vm = cls(self, None, qid=qid, **kwargs)21 self.domains[vm.name] = vm22 self.domains[vm] = vm23 return vm2425class TC_00_DispVM(vanir.tests.VanirTestCase):26 def setUp(self):27 super(TC_00_DispVM, self).setUp()28 self.app = TestApp()29 self.app.save = mock.Mock()30 self.app.pools['default'] = vanir.tests.vm.appvm.TestPool('default')31 self.app.pools['linux-kernel'] = mock.Mock(**{32 'init_volume.return_value.pool': 'linux-kernel'})33 self.app.vmm.offline_mode = True34 self.template = self.app.add_new_vm(vanir.vm.templatevm.TemplateVM,35 name='test-template', label='red')36 self.appvm = self.app.add_new_vm(vanir.vm.appvm.AppVM,37 name='test-vm', template=self.template, label='red')38 self.app.domains[self.appvm.name] = self.appvm39 self.app.domains[self.appvm] = self.appvm40 self.addCleanup(self.cleanup_dispvm)4142 def cleanup_dispvm(self):43 self.template.close()44 self.appvm.close()45 del self.template46 del self.appvm47 self.app.domains.clear()48 self.app.pools.clear()4950 @asyncio.coroutine51 def mock_coro(self, *args, **kwargs):52 pass5354 @mock.patch('os.symlink')55 @mock.patch('os.makedirs')56 @mock.patch('vanir.storage.Storage')57 def test_000_from_appvm(self, mock_storage, mock_makedirs, mock_symlink):58 mock_storage.return_value.create.side_effect = self.mock_coro59 self.appvm.template_for_dispvms = True60 orig_getitem = self.app.domains.__getitem__61 with mock.patch.object(self.app, 'domains', wraps=self.app.domains) \62 as mock_domains:63 mock_domains.configure_mock(**{64 'get_new_unused_dispid': mock.Mock(return_value=42),65 '__getitem__.side_effect': orig_getitem66 })67 dispvm = self.loop.run_until_complete(68 vanir.vm.dispvm.DispVM.from_appvm(self.appvm))69 mock_domains.get_new_unused_dispid.assert_called_once_with()70 self.assertEqual(dispvm.name, 'disp42')71 self.assertEqual(dispvm.template, self.appvm)72 self.assertEqual(dispvm.label, self.appvm.label)73 self.assertEqual(dispvm.label, self.appvm.label)74 self.assertEqual(dispvm.auto_cleanup, True)75 mock_makedirs.assert_called_once_with(76 '/var/lib/vanir/appvms/' + dispvm.name, mode=0o775, exist_ok=True)77 mock_symlink.assert_called_once_with(78 '/usr/share/icons/hicolor/128x128/devices/appvm-red.png',79 '/var/lib/vanir/appvms/{}/icon.png'.format(dispvm.name))8081 def test_001_from_appvm_reject_not_allowed(self):82 with self.assertRaises(vanir.exc.VanirException):83 dispvm = self.loop.run_until_complete(84 vanir.vm.dispvm.DispVM.from_appvm(self.appvm))8586 def test_002_template_change(self):87 self.appvm.template_for_dispvms = True88 orig_getitem = self.app.domains.__getitem__89 with mock.patch.object(self.app, 'domains', wraps=self.app.domains) \90 as mock_domains:91 mock_domains.configure_mock(**{92 'get_new_unused_dispid': mock.Mock(return_value=42),93 '__getitem__.side_effect': orig_getitem94 })95 dispvm = self.app.add_new_vm(vanir.vm.dispvm.DispVM,96 name='test-dispvm', template=self.appvm)9798 with self.assertRaises(vanir.exc.VanirValueError):99 dispvm.template = self.appvm100 with self.assertRaises(vanir.exc.VanirValueError):101 dispvm.template = vanir.property.DEFAULT102103104 def test_010_create_direct(self):105 self.appvm.template_for_dispvms = True106 orig_getitem = self.app.domains.__getitem__107 with mock.patch.object(self.app, 'domains', wraps=self.app.domains) \108 as mock_domains:109 mock_domains.configure_mock(**{110 'get_new_unused_dispid': mock.Mock(return_value=42),111 '__getitem__.side_effect': orig_getitem112 })113 dispvm = self.app.add_new_vm(vanir.vm.dispvm.DispVM,114 name='test-dispvm', template=self.appvm)115 mock_domains.get_new_unused_dispid.assert_called_once_with()116 self.assertEqual(dispvm.name, 'test-dispvm')117 self.assertEqual(dispvm.template, self.appvm)118 self.assertEqual(dispvm.label, self.appvm.label)119 self.assertEqual(dispvm.label, self.appvm.label)120 self.assertEqual(dispvm.auto_cleanup, False)121122 def test_011_create_direct_generate_name(self):123 self.appvm.template_for_dispvms = True124 orig_getitem = self.app.domains.__getitem__125 with mock.patch.object(self.app, 'domains', wraps=self.app.domains) \126 as mock_domains:127 mock_domains.configure_mock(**{128 'get_new_unused_dispid': mock.Mock(return_value=42),129 '__getitem__.side_effect': orig_getitem130 })131 dispvm = self.app.add_new_vm(vanir.vm.dispvm.DispVM,132 template=self.appvm)133 mock_domains.get_new_unused_dispid.assert_called_once_with()134 self.assertEqual(dispvm.name, 'disp42')135 self.assertEqual(dispvm.template, self.appvm)136 self.assertEqual(dispvm.label, self.appvm.label)137 self.assertEqual(dispvm.auto_cleanup, False)138139 def test_011_create_direct_reject(self):140 orig_getitem = self.app.domains.__getitem__141 with mock.patch.object(self.app, 'domains', wraps=self.app.domains) \142 as mock_domains:143 mock_domains.configure_mock(**{144 'get_new_unused_dispid': mock.Mock(return_value=42),145 '__getitem__.side_effect': orig_getitem146 })147 with self.assertRaises(vanir.exc.VanirException):148 self.app.add_new_vm(vanir.vm.dispvm.DispVM,149 name='test-dispvm', template=self.appvm) ...

Full Screen

Full Screen

test_utils.py

Source:test_utils.py Github

copy

Full Screen

...3import pytest4from nanotext.utils import get_interval_uid5from nanotext.utils import remove_overlap, deduplicate, create_domain_sequence6@pytest.fixture7def mock_domains():8 '''9 https://docs.pytest.org/en/latest/fixture.html10 stackoverflow.com/questions/77949511 '''12 fp = pkg_resources.resource_filename('nanotext', 'data/') + 'domains.bed'13 intervals = {}14 for i in BedTool(fp):15 intervals[get_interval_uid(i)] = i16 return intervals17def test_remove_overlap(mock_domains):18 text = []19 for i in remove_overlap(mock_domains):20 text.append(i.fields[3])21 assert text == [...

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