class TestTask(unittest.TestCase): def setUp(self): self.task = Task() def test_title(self): self.assertIsNone(self.task.title) def test_task_id(self): self.assertIsInstance(self.task.tid, str) def test_priority(self): self.assertEqual(self.task.priority, Priority.LOW) def test_connection_list(self): self.assertIsInstance(self.task.connection, list) def test_status(self): self.assertEqual(self.task.is_completed, Status.UNDONE) def test_complete(self): self.task.complete() self.assertEqual(self.task.is_completed, Status.DONE) def test_begin(self): self.task.begin() self.assertEqual(self.task.is_completed, Status.PROCESS)
def test_add_scheduler(self): task = Task("Hello, world") scheduler = Scheduler(task=task, uid=self.storage.current_uid) len_before = len(self.scheduler_controller.get()) self.scheduler_controller.add(scheduler) len_after = len(self.scheduler_controller.get()) self.assertEqual(len_before + 1, len_after)
def test_edit(self): task = Task(title="Test") self.task_controller.add(task) tid = self.task_controller.get_list()[-1].tid self.task_controller.edit(tid, title="EditedName") edited_task_title = self.task_controller.get_list()[-1].title self.assertEqual(edited_task_title, "EditedName")
def test_begin(self): task = Task() self.task_controller.add(task) tid = self.task_controller.get_list()[-1].tid self.task_controller.begin_task(tid) loaded_task = self.task_controller.get_task(tid) self.assertEqual(str(Status.PROCESS.value), loaded_task.is_completed)
def test_serialization(self): task = Task(start=datetime.now(), end=datetime.now(), priority=Priority.HIGH, tag=Tag("Name")) dict_task = serialization.task_to_dict(task).__dict__ self.assertIsInstance(dict_task['start'], str) self.assertIsInstance(dict_task['end'], str) self.assertIsInstance(dict_task['priority'], str)
def test_uncomplete(self): task = Task() self.task_controller.add(task) tid = self.task_controller.get_list()[-1].tid self.task_controller.uncomplete_task(tid) loaded_task = self.task_controller.get_task(tid) self.assertEqual(str(Status.UNDONE.value), loaded_task.is_completed)
def setUp(self): self.storage = Storage({'storage_path': '/tmp/tman_tests/'}) self.user = User("test_user", "test", "test ") self.storage.save_new_user_to_json(self.user) self.storage.change_user_config(self.user.login) self.task_controller = TaskController(self.storage) self.task = Task() self.storage.load_user_tasks()
def test_get_list(self): task = Task() self.task_controller.task_storage.load_tasks_from_json() len_before = len(self.task_controller.task_storage.tasks) self.task_controller.add(task) self.task_controller.task_storage.load_tasks_from_json() len_after = len(self.task_controller.task_storage.tasks) self.assertEqual(len_before + 1, len_after)
def test_get_scheduler(self): last = datetime.now() - timedelta(days=10) task = Task("Hello, world") scheduler = Scheduler(last=last, task=task, uid=self.storage.current_uid) self.scheduler_controller.add(scheduler) new_scheduler = self.scheduler_controller.get()[-1] self.task_controller.task_storage.load_tasks_from_json() len_before = len(self.task_controller.task_storage.tasks) self.scheduler_controller.generate_task(new_scheduler) self.task_controller.task_storage.load_tasks_from_json() len_after = len(self.task_controller.task_storage.tasks) self.assertEqual(len_before+1, len_after)
def __init__(self, last=None, task=None, interval=None, uid=None, sid=None): self.last = last if task is None: self.task = Task() else: self.task = task if interval is None: self.interval = 0 else: self.interval = interval self.uid = uid if sid is None: self.sid = str(uuid.uuid1()) else: self.sid = sid
def dict_to_task(task_dict): """Converting dict object to current Task object""" title = task_dict['title'] start = utils.str_to_date(task_dict['start']) end = utils.str_to_date(task_dict['end']) desc = task_dict['description'] tag = Tag(task_dict['tag']['tag_name'], task_dict['tag']['description']) observers = task_dict['observers'] priority = Priority[Priority(int(task_dict['priority'])).name] author = task_dict['author'] reminder = utils.str_to_time(task_dict['reminder']) is_completed = Status(int(task_dict['is_completed'])) parent = task_dict['parent'] tid = task_dict['tid'] subtasks = task_dict['subtasks'] changed = task_dict['changed'] connection = task_dict['connection'] height = task_dict['height'] planned = task_dict['planned'] task = Task(title=title, description=desc, start=start, end=end, tag=tag, author=author, observers=observers, reminder=reminder, priority=priority, height=height, changed=changed, parent=parent, tid=tid, subtasks=subtasks, is_completed=is_completed, connection=connection, planned=planned) return task
def add_scheduler(self, title, start, end, interval, **kwargs): """ Adding new planned task Created pattern of task and then creates Scheduler's object :param title: title of planned task :param start: datetime object describing start of task :param end: datetime object describing end of task :param interval: interval between creation of task :param kwargs: other parameters describing task pattern :return: """ task = Task(title=title, author=self.current_user.uid, start=start, end=end, height=0, **kwargs) last = datetime.now() scheduler = Scheduler(task=task, last=last, interval=interval, uid=self.current_user.uid) scheduler.task.planned = scheduler.sid self.scheduler_controller.add(scheduler)
def add_task(self, title, start, end, **kwargs): """ Method for creating new task and save it to storage :param title: title of task :param start: datetime object describing start of task :param end: datetime object describing end of task :param kwargs: other parameters describing task :return: """ parent = kwargs['parent'] if parent is None: height = 0 else: height = self.get_subtask_height(parent) + 1 task = Task(title=title, author=self.current_user.uid, start=start, end=end, height=height, **kwargs) self.task_controller.add(task)
def test_deserialize(self): task = Task() task_dict = serialization.task_to_dict(task).__dict__ task = serialization.dict_to_task(task_dict) self.assertIsInstance(task.priority, Priority)
def test_add_subtask(self): first = Task() second = Task(parent=first.tid) self.assertEqual(first.tid, second.parent)
def setUp(self): self.task = Task()
def test_add_task(self): task = Task() self.task_controller.add(task) self.task_controller.get_list() self.assertIn(task, self.storage.tasks)