def test_make_shift_smaller(self): task1 = Task() task1.pid = 1 task1.title = 'Title 1' self.storage_task.save_task(task1) plan1 = Plan() plan1.shift = utils.datetime_to_milliseconds( datetime.datetime.utcfromtimestamp(0) + datetime.timedelta(days=10)) plan1.exclude = [0, 1, 3, 4] plan1.tid = 1 self.storage_plan.save_plan(plan1) new_shift = utils.datetime_to_milliseconds( datetime.datetime.utcfromtimestamp(0) + datetime.timedelta(days=3)) args = {Plan.Field.plan_id: 1, Plan.Field.shift: new_shift} success = self.storage_plan.edit_plan(args) self.assertEqual(success, True) plans = self.storage_plan.get_plans(plan_id=1)[0] plan1.plan_id = 1 plan1.shift = new_shift plan1.exclude = [0, 10] self.assertEqual(plans, plan1)
def test_recalculate_exclude_when_start_time_shifted_backward(self): task1 = Task() task1.pid = 1 task1.title = 'Title 1' task1.supposed_start_time = utils.datetime_to_milliseconds( datetime.datetime.today()) self.storage_task.save_task(task1) plan1 = Plan() plan1.shift = utils.datetime_to_milliseconds( datetime.datetime.utcfromtimestamp(0) + datetime.timedelta(days=2)) plan1.exclude = [0, 1, 3, 4] plan1.tid = 1 self.storage_plan.save_plan(plan1) new_time = utils.datetime_to_milliseconds(datetime.datetime.today() - datetime.timedelta(days=4)) self.storage_task.edit_task({ Task.Field.tid: 1, Task.Field.supposed_start_time: new_time }) start_time_shift = utils.datetime_to_milliseconds( datetime.datetime.utcfromtimestamp(0) + datetime.timedelta(days=4)) success = self.storage_plan.recalculate_exclude_when_start_time_shifted( 1, -start_time_shift) self.assertEqual(success, True) plan = self.storage_plan.get_plans(plan_id=1)[0] plan1.plan_id = 1 plan1.exclude = [2, 3, 5, 6] self.assertEqual(plan, plan1)
def test_get_plans_for_common_tid(self): task1 = Task() task1.pid = 1 task1.title = 'Title 1' task2 = Task() task2.pid = 1 task2.title = 'Title 2' self.storage_task.save_task(task1) self.storage_task.save_task(task2) plan1 = Plan() plan1.shift = utils.datetime_to_milliseconds( datetime.datetime.utcfromtimestamp(0) + datetime.timedelta(days=3)) plan1.exclude = [3, 5] plan1.tid = 2 plan2 = Plan() plan2.shift = utils.datetime_to_milliseconds( datetime.datetime.utcfromtimestamp(0) + datetime.timedelta(days=4)) plan2.exclude = [2, 8] plan2.tid = 1 self.storage_plan.save_plan(plan1) self.storage_plan.save_plan(plan2) plans = self.storage_plan.get_plans(common_tid=1) self.assertEqual(len(plans), 1) plan2.plan_id = 2 self.assertEqual(plans[0], plan2)
def test_plans_edit_repeat(self): task1 = Task() task1.pid = 1 task1.title = 'Title 1' self.storage_task.save_task(task1) plan1 = Plan() plan1.shift = utils.datetime_to_milliseconds( datetime.datetime.utcfromtimestamp(0) + datetime.timedelta(days=3)) plan1.exclude = [] plan1.tid = 1 self.storage_plan.save_plan(plan1) task2 = Task() task2.pid = 1 task2.title = 'Title 2' self.storage_task.save_task(task2) success = self.storage_plan.edit_plan_repeat(1, 8, 2) self.assertEqual(success, True) plan_in_db = self.storage_plan.get_plans(1)[0] plan1.plan_id = 1 plan1.exclude.append(8) self.assertEqual(plan_in_db, plan1)
def get_plans(self, plan_id): plan = Plan() plan.tid = 1 plan.plan_id = 1 plan.shift = utils.create_shift_in_millis(datetime.timedelta(days=3)) plan.exclude = [4, 5] return [plan]
def get_plans(self, plan_id): plan = Plan() plan.tid = 1 plan.plan_id = 1 plan.shift = 3000 plan.exclude = [5] return [plan]
def get_plans(self, plan_id): plan = Plan() plan.tid = 1 plan.plan_id = 1 plan.shift = utils.create_shift_in_millis(datetime.timedelta(days=3)) plan.exclude = [5] plan.end = utils.shift_datetime_in_millis(datetime.datetime.today(), datetime.timedelta(days=10)) return [plan]
def test_plans_restore_repeat(self): task1 = Task() task1.pid = 1 task1.title = 'Title 1' self.storage_task.save_task(task1) plan1 = Plan() plan1.shift = utils.datetime_to_milliseconds( datetime.datetime.utcfromtimestamp(0) + datetime.timedelta(days=3)) plan1.exclude = [3, 5] plan1.tid = 1 self.storage_plan.save_plan(plan1) self.storage_plan.delete_plan_repeat(1, 8) success = self.storage_plan.restore_plan_repeat(1, 8) self.assertEqual(success, True) plan_in_database = self.storage_plan.get_plans(plan_id=1)[0] plan1.plan_id = 1 self.assertEqual(plan_in_database, plan1)
def to_plan(self): plan = Plan() plan.plan_id = self.plan_id plan.end = self.end plan.shift = self.shift return plan