Example #1
0
    def test_tasker_full_scenario(self):
        tasker = Tasker(self.db)

        tasker.create_task('Make coffee', 'daily', date(2016, 11, 3))
        tasker.create_task('Get gas', 'weekly', date(2016, 11, 5))
        tasker.create_task('Pay bills', 'monthly', date(2016, 11, 4))

        tasker.schedule_tasks()

        tasker.complete_task_instance(1)
        tasker.complete_task_instance(2)
        tasker.complete_task_instance(3)

        # Schedule next iteration of every task.
        tasker.schedule_tasks()

        tis = self.db.query(TaskInstance).order_by(TaskInstance.date,
                                                   TaskInstance.task).all()

        self.assertEqual(tis, [
            TaskInstance(id=1, task=1, date=date(2016, 11, 3), done=True),
            TaskInstance(id=4, task=1, date=date(2016, 11, 4), done=False),
            TaskInstance(id=3, task=3, date=date(2016, 11, 4), done=True),
            TaskInstance(id=2, task=2, date=date(2016, 11, 5), done=True),
            TaskInstance(id=5, task=2, date=date(2016, 11, 12), done=False),
            TaskInstance(id=6, task=3, date=date(2016, 12, 4), done=False)
        ])
Example #2
0
    def test_schedule_tasks_repeated_tasks_done(self):
        tasker = Tasker(self.db)

        # All tasks should be scheduled
        tasker.create_task('Fix bike', 'once', date(2016, 11, 2))
        tasker.create_task('Make coffee', 'daily', date(2016, 11, 3))
        tasker.create_task('Get gas', 'weekly', date(2016, 11, 5))
        tasker.create_task('Pay bills', 'monthly', date(2016, 11, 4))

        tasker.schedule_tasks()
        tasker.complete_task_instance(1)
        tasker.complete_task_instance(2)
        tasker.complete_task_instance(3)
        tasker.complete_task_instance(4)
        tasker.schedule_tasks()
        tasker.schedule_tasks()

        tis = self.db.query(TaskInstance).order_by(TaskInstance.date,
                                                   TaskInstance.task).all()

        self.assertEqual(tis, [
            TaskInstance(id=1, task=1, date=date(2016, 11, 2), done=True),
            TaskInstance(id=2, task=2, date=date(2016, 11, 3), done=True),
            TaskInstance(id=5, task=2, date=date(2016, 11, 4), done=False),
            TaskInstance(id=4, task=4, date=date(2016, 11, 4), done=True),
            TaskInstance(id=3, task=3, date=date(2016, 11, 5), done=True),
            TaskInstance(id=6, task=3, date=date(2016, 11, 12), done=False),
            TaskInstance(id=7, task=4, date=date(2016, 12, 4), done=False)
        ])
Example #3
0
    def test_complete_task_instance(self):
        tasker = Tasker(self.db)

        tasker.create_task('Make coffee', 'daily', date(2016, 11, 3))

        tasker.schedule_tasks()
        tasker.complete_task_instance(1)

        tis = self.db.query(TaskInstance).all()

        self.assertEqual(
            tis,
            [TaskInstance(id=1, task=1, date=date(2016, 11, 3), done=True)])
Example #4
0
    def test_schedule_tasks_new_year(self):
        tasker = Tasker(self.db)

        # All tasks should be scheduled
        tasker.create_task('Pay bills', 'monthly', date(2016, 12, 4))

        tasker.schedule_tasks()
        tasker.complete_task_instance(1)
        tasker.schedule_tasks()

        tis = self.db.query(TaskInstance).order_by(TaskInstance.date).all()

        self.assertEqual(tis, [
            TaskInstance(id=1, task=1, date=date(2016, 12, 4), done=True),
            TaskInstance(id=2, task=1, date=date(2017, 1, 4), done=False)
        ])
Example #5
0
    def test_tasker_full_scenario_schedule_complete(self):
        tasker = Tasker(self.db)

        tasker.create_task('Get gas', 'weekly', date(2016, 11, 5))
        tasker.create_task('Pay bills', 'monthly', date(2016, 11, 4))

        tasker.schedule_tasks()

        tasker.complete_task_instance(1)
        tasker.complete_task_instance(2)

        tasker.schedule_tasks(until_date=date(2016, 11, 11))

        tis = self.db.query(TaskInstance).order_by(TaskInstance.date,
                                                   TaskInstance.task).all()

        self.assertEqual(tis, [
            TaskInstance(id=2, task=2, date=date(2016, 11, 4), done=True),
            TaskInstance(id=1, task=1, date=date(2016, 11, 5), done=True)
        ])