Best Python code snippet using autotest_python
monitor_db_unittest.py
Source:monitor_db_unittest.py
...646 def setUp(self):647 self._frontend_common_setup()648 def tearDown(self):649 self._frontend_common_teardown()650 def _setup_drones(self):651 self.god.stub_function(models.DroneSet, 'drone_sets_enabled')652 models.DroneSet.drone_sets_enabled.expect_call().and_return(True)653 drones = []654 for x in xrange(4):655 drones.append(models.Drone.objects.create(hostname=str(x)))656 drone_set_1 = models.DroneSet.objects.create(name='1')657 drone_set_1.drones.add(*drones[0:2])658 drone_set_2 = models.DroneSet.objects.create(name='2')659 drone_set_2.drones.add(*drones[2:4])660 drone_set_3 = models.DroneSet.objects.create(name='3')661 job_1 = self._create_job_simple([self.hosts[0].id],662 drone_set=drone_set_1)663 job_2 = self._create_job_simple([self.hosts[0].id],664 drone_set=drone_set_2)665 job_3 = self._create_job_simple([self.hosts[0].id],666 drone_set=drone_set_3)667 job_4 = self._create_job_simple([self.hosts[0].id])668 job_4.drone_set = None669 job_4.save()670 hqe_1 = job_1.hostqueueentry_set.all()[0]671 hqe_2 = job_2.hostqueueentry_set.all()[0]672 hqe_3 = job_3.hostqueueentry_set.all()[0]673 hqe_4 = job_4.hostqueueentry_set.all()[0]674 return (hqe_1, hqe_2, hqe_3, hqe_4), agent_task.AgentTask()675 def test_get_drone_hostnames_allowed_no_drones_in_set(self):676 hqes, task = self._setup_drones()677 task.queue_entry_ids = (hqes[2].id,)678 self.assertEqual(set(), task.get_drone_hostnames_allowed())679 self.god.check_playback()680 def test_get_drone_hostnames_allowed_no_drone_set(self):681 hqes, task = self._setup_drones()682 hqe = hqes[3]683 task.queue_entry_ids = (hqe.id,)684 result = object()685 self.god.stub_function(task, '_user_or_global_default_drone_set')686 task._user_or_global_default_drone_set.expect_call(687 hqe.job, hqe.job.user()).and_return(result)688 self.assertEqual(result, task.get_drone_hostnames_allowed())689 self.god.check_playback()690 def test_get_drone_hostnames_allowed_success(self):691 hqes, task = self._setup_drones()692 task.queue_entry_ids = (hqes[0].id,)693 self.assertEqual(set(('0','1')), task.get_drone_hostnames_allowed([]))694 self.god.check_playback()695 def test_get_drone_hostnames_allowed_multiple_jobs(self):696 hqes, task = self._setup_drones()697 task.queue_entry_ids = (hqes[0].id, hqes[1].id)698 self.assertRaises(AssertionError,699 task.get_drone_hostnames_allowed)700 self.god.check_playback()701 def test_get_drone_hostnames_allowed_no_hqe(self):702 class MockSpecialTask(object):703 requested_by = object()704 class MockSpecialAgentTask(agent_task.SpecialAgentTask):705 task = MockSpecialTask()706 queue_entry_ids = []707 def __init__(self, *args, **kwargs):708 super(agent_task.SpecialAgentTask, self).__init__()709 task = MockSpecialAgentTask()710 self.god.stub_function(models.DroneSet, 'drone_sets_enabled')...
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!!