def test_duplicate_tasks(self):
        trigger = IntervalTrigger(timedelta(hours=1))

        @periodic_task(priority=9, run_every=trigger)
        def test_fn():
            pass

        jobs_to_unschedule, tasks_to_add = process_periodic_tasks(
               [], [test_fn, test_fn])

        self.assertEqual(jobs_to_unschedule, [])
        self.assertEqual(tasks_to_add, [test_fn])
    def test_same_task(self):
        trigger = IntervalTrigger(timedelta(hours=1))

        @periodic_task(priority=9, run_every=trigger)
        def test_fn():
            pass

        job = Mock(trigger=trigger, func=test_fn)

        jobs_to_unschedule, tasks_to_add = process_periodic_tasks(
               [job], [test_fn])

        self.assertEqual(jobs_to_unschedule, [])
        self.assertEqual(tasks_to_add, [])
    def test_same_func_diff_triggers(self):
        trigger_a = IntervalTrigger(timedelta(hours=1))
        trigger_b = IntervalTrigger(timedelta(hours=2))

        def test_fn():
            pass

        test_fn_a = periodic_task(priority=9, run_every=trigger_a)(test_fn)
        test_fn_b = periodic_task(priority=9, run_every=trigger_b)(test_fn)

        job = Mock(trigger=trigger_a, func=test_fn_a)

        jobs_to_unschedule, tasks_to_add = process_periodic_tasks(
               [job], [test_fn_b])

        self.assertEqual(jobs_to_unschedule, [job])
        self.assertEqual(tasks_to_add, [test_fn_b])
    def test_same_func_diff_priorities(self):
        # This test isn't strictly necessary, since APScheduler doesn't store
        # priority information to db, it loads it from the module each time.
        # Were that to change, this should fail!
        trigger = IntervalTrigger(timedelta(hours=1))

        def test_fn():
            pass

        test_fn_a = periodic_task(priority=9, run_every=trigger)(test_fn)
        test_fn_b = periodic_task(priority=8, run_every=trigger)(test_fn)

        job = Mock(trigger=trigger, func=test_fn_a)

        jobs_to_unschedule, tasks_to_add = process_periodic_tasks(
               [job], [test_fn_b])

        self.assertEqual(jobs_to_unschedule, [job])
        self.assertEqual(tasks_to_add, [test_fn_b])