本文整理匯總了Python中schedule.Schedule.insert方法的典型用法代碼示例。如果您正苦於以下問題:Python Schedule.insert方法的具體用法?Python Schedule.insert怎麽用?Python Schedule.insert使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類schedule.Schedule
的用法示例。
在下文中一共展示了Schedule.insert方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestScheduleClass
# 需要導入模塊: from schedule import Schedule [as 別名]
# 或者: from schedule.Schedule import insert [as 別名]
class TestScheduleClass(unittest.TestCase):
def setUp(self):
self.schedule = Schedule()
self.schedule.insert({
"enable": 1,
"alias": "reboot",
"command": "uptime && reboot",
"schedule": "0 0 * * *",
"executer": True
})
# self.reboot = Reboot(connection=Mockup())
def tearDown(self):
self.schedule = None
cron = CronTab(user=True)
cron.remove_all()
cron.write()
def test_insert(self):
'''Insert a job, It should insert a job and return it with id'''
result = self.schedule.insert({
"enable": 1,
"alias": "reboot",
"command": "uptime && test_insert",
"schedule": "0 0 * * *",
"executer": True
})
self.assertDictEqual({
"id": 2,
"enable": 1,
"alias": "reboot",
"command": "uptime && test_insert",
"schedule": "0 0 * * *",
"executer": True,
"comment": "sanji_schedule_2"
}, result)
jobs = []
cron = CronTab(user=True)
for job in cron.find_comment("sanji_schedule_2"):
jobs.append(job)
self.assertEqual(len(jobs), 1)
def test_update(self):
'''Update a job, It should update a job and return it'''
added = self.schedule.get()[0]
result = self.schedule.update({
"id": added["id"],
"enable": 1,
"alias": "uptime",
"command": "uptime && test_update",
"schedule": "1 1 1 * *",
"executer": True
})
self.assertNotEqual(result, None)
self.assertDictEqual({
"id": added["id"],
"enable": 1,
"alias": "uptime",
"command": "uptime && test_update",
"schedule": "1 1 1 * *",
"executer": True,
"comment": added["comment"]
}, result)
jobs = []
cron = CronTab(user=True)
for job in cron.find_comment(result["comment"]):
jobs.append(job)
self.assertEqual(job.slices, result["schedule"])
self.assertEqual(job.command, result["command"])
self.assertEqual(len(jobs), 1)
def test_delete(self):
'''Delete a job,
It should delete a job by id and return effected count'''
added = self.schedule.get()[0]
result = self.schedule.delete(added["id"])
self.assertEqual(result, 1)
result = self.schedule.get()
self.assertEqual(len(result), 0)
def test_get_all(self):
'''Get all jobs,
It should return all jobs'''
self.schedule.insert({
"enable": 1,
"alias": "1",
"command": "uptime && test_get_all",
"schedule": "0 0 * * *",
"executer": True
})
self.schedule.insert({
"enable": 1,
"alias": "1",
#.........這裏部分代碼省略.........