How to use _set_monitor_stubs method in autotest

Best Python code snippet using autotest_python

monitor_db_unittest.py

Source:monitor_db_unittest.py Github

copy

Full Screen

...62 frontend_test_utils.FrontendTestMixin):63 _config_section = 'AUTOTEST_WEB'64 def _do_query(self, sql):65 self._database.execute(sql)66 def _set_monitor_stubs(self):67 self.mock_config = global_config.FakeGlobalConfig()68 self.god.stub_with(global_config, 'global_config', self.mock_config)69 # Clear the instance cache as this is a brand new database.70 scheduler_models.DBObject._clear_instance_cache()71 self._database = (72 database_connection.TranslatingDatabase.get_test_database(73 translators=scheduler_lib._DB_TRANSLATORS))74 self._database.connect(db_type='django')75 self._database.debug = _DEBUG76 connection_manager = scheduler_lib.ConnectionManager(autocommit=False)77 self.god.stub_with(connection_manager, 'db_connection', self._database)78 self.god.stub_with(monitor_db, '_db_manager', connection_manager)79 self.god.stub_with(monitor_db, '_db', self._database)80 self.god.stub_with(monitor_db.Dispatcher,81 '_get_pending_queue_entries',82 self._get_pending_hqes)83 self.god.stub_with(scheduler_models, '_db', self._database)84 self.god.stub_with(drone_manager.instance(), '_results_dir',85 '/test/path')86 self.god.stub_with(drone_manager.instance(), '_temporary_directory',87 '/test/path/tmp')88 self.god.stub_with(drone_manager.instance(), 'initialize',89 lambda *args: None)90 self.god.stub_with(drone_manager.instance(), 'execute_actions',91 lambda *args: None)92 monitor_db.initialize_globals()93 scheduler_models.initialize_globals()94 def setUp(self):95 self._frontend_common_setup()96 self._set_monitor_stubs()97 self._set_global_config_values()98 self._dispatcher = monitor_db.Dispatcher()99 def tearDown(self):100 self._database.disconnect()101 self._frontend_common_teardown()102 def _set_global_config_values(self):103 """Set global_config values to suit unittest needs."""104 self.mock_config.set_config_value(105 'SCHEDULER', 'inline_host_acquisition', True)106 def _update_hqe(self, set, where=''):107 query = 'UPDATE afe_host_queue_entries SET ' + set108 if where:109 query += ' WHERE ' + where110 self._do_query(query)111 def _get_pending_hqes(self):112 query_string=('afe_jobs.priority DESC, '113 'ifnull(nullif(host_id, NULL), host_id) DESC, '114 'ifnull(nullif(meta_host, NULL), meta_host) DESC, '115 'job_id')116 return list(scheduler_models.HostQueueEntry.fetch(117 joins='INNER JOIN afe_jobs ON (job_id=afe_jobs.id)',118 where='NOT complete AND NOT active AND status="Queued"',119 order_by=query_string))120class DispatcherSchedulingTest(BaseSchedulerTest):121 _jobs_scheduled = []122 def tearDown(self):123 super(DispatcherSchedulingTest, self).tearDown()124 def _set_monitor_stubs(self):125 super(DispatcherSchedulingTest, self)._set_monitor_stubs()126 def hqe__do_schedule_pre_job_tasks_stub(queue_entry):127 """Called by HostQueueEntry.run()."""128 self._record_job_scheduled(queue_entry.job.id, queue_entry.host.id)129 queue_entry.set_status('Starting')130 self.god.stub_with(scheduler_models.HostQueueEntry,131 '_do_schedule_pre_job_tasks',132 hqe__do_schedule_pre_job_tasks_stub)133 def _record_job_scheduled(self, job_id, host_id):134 record = (job_id, host_id)135 self.assert_(record not in self._jobs_scheduled,136 'Job %d scheduled on host %d twice' %137 (job_id, host_id))138 self._jobs_scheduled.append(record)139 def _assert_job_scheduled_on(self, job_id, host_id):...

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 autotest 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