def task_show_handler(service: AppService, namespace): if namespace.show_type == 'id': task = service.get_task(user=namespace.user, task_id=namespace.task_id) print(task) elif namespace.show_type == 'own': own_tasks = service.get_own_tasks(user=namespace.user) print_collection(own_tasks, mes1='Your own tasks:', mes2='You dont have any tasks') elif namespace.show_type == 'subtasks': task = service.get_task(namespace.user, task_id=namespace.task_id) subtasks = service.get_subtasks(user=namespace.user, task_id=namespace.task_id) if subtasks: print_task_with_subtask(service, namespace.user, task) else: print('Task dont have any subtasks') elif namespace.show_type == 'all': available_tasks = service.get_available_tasks(user=namespace.user) print_collection(available_tasks, mes1='Available tasks:', mes2='You dont have any tasks') elif namespace.show_type == 'assigned': assigned_tasks = service.get_user_assigned_tasks(user=namespace.user) print_collection(assigned_tasks, mes1='Assigned tasks:', mes2='You dont have assigned tasks') elif namespace.show_type == 'todo': todo_tasks = service.get_filtered_tasks(user=namespace.user, status=TaskStatus.TODO) print_collection(todo_tasks, mes1='Todo tasks:', mes2='You dont have todo tasks') elif namespace.show_type == 'inwork': inwork_tasks = service.get_filtered_tasks(user=namespace.user, status=TaskStatus.INWORK) print_collection(inwork_tasks, mes1='Inwork tasks:', mes2='You dont have any inwork tasks') elif namespace.show_type == 'done': done_tasks = service.get_filtered_tasks(user=namespace.user, status=TaskStatus.DONE) print_collection(done_tasks, mes1='Done tasks:', mes2='You dont have any done tasks') elif namespace.show_type == 'archived': archived_tasks = service.get_filtered_tasks(user=namespace.user, status=TaskStatus.ARCHIVED) print_collection(archived_tasks, mes1='Archived tasks:', mes2='You dont have any archived tasks') elif namespace.show_type == 'planless': planless = [ task for task in service.get_available_tasks(user=namespace.user) if task.plan is None ] print_collection(planless, mes1='Tasks without plan:', mes2='You dont have any tasks without a plan')
class PlanTest(unittest.TestCase): def setUp(self): session = mo.set_up_connection(DRIVER_NAME, CONNECTIONSTRING) self.serv = AppService(session) def test_create_plan(self): task = self.serv.create_task(user=TEST_USER, name=TEST_NAME, start_date=TEST_DATE_FIRST) with self.assertRaises(ex.ObjectNotFound): plan = self.serv.create_plan(user=TEST_RECEIVER, task_id=task.id, period_amount=TEST_RANDOM_INT, period=TEST_PERIOD_VALUE) DATE = datetime.now() plan = self.serv.create_plan(user=TEST_USER, task_id=task.id, period_amount=TEST_RANDOM_INT, period=TEST_PERIOD_VALUE, end_date=TEST_PLAN_END_DATE, repetitions_amount=TEST_RANDOM_INT, start_date=DATE) self.assertEqual(plan.user, TEST_USER) self.assertEqual(plan.task.id, task.id) self.assertEqual(plan.period_amount, TEST_RANDOM_INT) self.assertEqual(plan.period, TEST_PERIOD) self.assertEqual(plan.end_date, TEST_PLAN_END_DATE) self.assertEqual(plan.repetitions_amount, TEST_RANDOM_INT) self.assertEqual(plan.start_date, DATE) with self.assertRaises(ValueError): plan = self.serv.create_plan(user=TEST_USER, task_id=task.id, period=TEST_PERIOD_VALUE, period_amount=TEST_RANDOM_INT) with self.assertRaises(KeyError): task.plan = None self.serv.save_updates() plan = self.serv.create_plan(user=TEST_USER, task_id=task.id, period=TEST_RANDOM_STR, period_amount=TEST_RANDOM_INT) task.plan = None subtask = self.serv.create_task(user=TEST_USER, name=TEST_NAME) self.serv.add_subtask(user=TEST_USER, task_id=subtask.id, parent_task_id=task.id) with self.assertRaises(ValueError): plan = self.serv.create_plan(user=TEST_USER, task_id=task.id, period=TEST_PERIOD_VALUE, period_amount=TEST_RANDOM_INT) def test_update_plan(self): task = self.serv.create_task(user=TEST_USER, name=TEST_NAME, start_date=TEST_DATE_FIRST) plan = self.serv.create_plan(user=TEST_USER, task_id=task.id, period_amount=10, period=mo.Period.MONTH.value, end_date=TEST_PLAN_END_DATE, repetitions_amount=100) with self.assertRaises(KeyError): self.serv.update_plan(user=TEST_USER, plan_id=plan.id, period=TEST_RANDOM_STR) with self.assertRaises(ValueError): self.serv.update_plan(user=TEST_USER, plan_id=plan.id, end_date=TEST_DATE_FIRST) plan = self.serv.update_plan(user=TEST_USER, plan_id=plan.id, period=TEST_PERIOD_VALUE, period_amount=TEST_RANDOM_INT, end_date=TEST_DATE_THIRD, repetitions_amount=TEST_RANDOM_INT) self.assertEqual(plan.period, TEST_PERIOD) self.assertEqual(plan.period_amount, TEST_RANDOM_INT) self.assertEqual(plan.end_date, TEST_DATE_THIRD) self.assertEqual(plan.repetitions_amount, TEST_RANDOM_INT) def test_execute_and_get_active_plans(self): taskslen = len(self.serv.get_available_tasks(user=TEST_USER)) self.assertEqual(taskslen, 0) plans = self.serv.get_active_plans(TEST_USER) self.assertEqual(len(plans), 0) task1 = self.serv.create_task(user=TEST_USER, name=TEST_NAME, start_date=TEST_DATE_FIRST) plan1 = self.serv.create_plan(user=TEST_USER, task_id=task1.id, period_amount=1, period=TEST_PERIOD_VALUE, end_date=TEST_PLAN_END_DATE, start_date=TEST_DATE_FIRST) self.assertEqual(plan1.task.id, task1.id) task2 = self.serv.create_task(user=TEST_USER, name=TEST_NAME, start_date=TEST_DATE_FIRST) plan2 = self.serv.create_plan(user=TEST_USER, task_id=task2.id, period_amount=1, period=TEST_PERIOD_VALUE, repetitions_amount=100, start_date=TEST_DATE_FIRST) task3 = self.serv.create_task(user=TEST_USER, name=TEST_NAME, start_date=TEST_DATE_FIRST) plan3 = self.serv.create_plan(user=TEST_USER, task_id=task3.id, period_amount=1, period=TEST_PERIOD_VALUE, start_date=TEST_DATE_FIRST) plans = self.serv.get_active_plans(TEST_USER) self.assertEqual(len(plans), 3) self.assertEqual(plan1.end_type, mo.EndType.DATE) self.assertEqual(plan2.end_type, mo.EndType.AMOUNT) self.assertEqual(plan3.end_type, mo.EndType.NEVER) self.serv.execute_plans(user=TEST_USER) taskslen = len(self.serv.get_available_tasks(user=TEST_USER)) res = plan1.repetitions_counter + plan2.repetitions_counter res += plan3.repetitions_counter + 3 self.assertTrue(len, res)