當前位置: 首頁>>代碼示例>>Python>>正文


Python Schedule.delete方法代碼示例

本文整理匯總了Python中schedule.Schedule.delete方法的典型用法代碼示例。如果您正苦於以下問題:Python Schedule.delete方法的具體用法?Python Schedule.delete怎麽用?Python Schedule.delete使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在schedule.Schedule的用法示例。


在下文中一共展示了Schedule.delete方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestScheduleClass

# 需要導入模塊: from schedule import Schedule [as 別名]
# 或者: from schedule.Schedule import delete [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",
#.........這裏部分代碼省略.........
開發者ID:Sanji-IO,項目名稱:sanji-bundle-schedule,代碼行數:103,代碼來源:test_index.py


注:本文中的schedule.Schedule.delete方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。