def test_parenting(self): store = TaskStore() root_task = store.new('My Root Task') child_task = store.new('My Child task') store.parent(child_task.id, root_task.id) self.assertEqual(store.count(), 2) self.assertEqual(store.count(root_only=True), 1) self.assertEqual(child_task.parent, root_task) self.assertEqual(root_task.children[0], child_task) store.unparent(child_task.id, root_task.id) self.assertEqual(store.count(), 2) self.assertEqual(store.count(root_only=True), 2) self.assertEqual(child_task.parent, None) self.assertEqual(len(root_task.children), 0) inner_child_task = store.new('Inner Child task') store.parent(child_task.id, root_task.id) store.parent(inner_child_task.id, child_task.id) self.assertEqual(store.count(), 3) self.assertEqual(store.count(root_only=True), 1) self.assertEqual(child_task.parent, root_task) self.assertEqual(root_task.children[0], child_task) self.assertEqual(child_task.children[0], inner_child_task) self.assertEqual(child_task.parent, root_task) self.assertEqual(inner_child_task.parent, child_task) store.unparent(inner_child_task.id, inner_child_task.parent.id) self.assertEqual(inner_child_task.parent, None) self.assertEqual(len(child_task.children), 0)
def test_filter_tag(self): task_store = TaskStore() task1 = task_store.new('My Task') task2 = task_store.new('My Other Task') task3 = task_store.new('My Other Other Task') task4 = task_store.new('My Other Other Other Task') tag1 = Tag2(id=uuid4(), name='A Tag') tag2 = Tag2(id=uuid4(), name='Another Tag') task1.add_tag(tag1) task2.add_tag(tag2) # Test single tags filtered = task_store.filter(Filter.TAG, tag1) expected = [task1] self.assertEqual(filtered, expected) filtered = task_store.filter(Filter.TAG, tag2) expected = [task2] self.assertEqual(filtered, expected) # Test tag intersection task3.add_tag(tag1) task3.add_tag(tag2) filtered = task_store.filter(Filter.TAG, [tag1, tag2]) expected = [task3] self.assertEqual(filtered, expected)
def test_new_tree(self): store = TaskStore() root_task = store.new('My Root Task') child_task = store.new('My Child Task', root_task.id) self.assertEqual(store.count(), 2) self.assertEqual(store.count(root_only=True), 1)
def test_filter_custom(self): task_store = TaskStore() task1 = task_store.new('My Task') task2 = task_store.new('My Other Task') filtered = task_store.filter_custom('title', lambda t: 'Other' in t) expected = [task2] self.assertEqual(filtered, expected)
def test_simple_reverse_sort(self): task_store = TaskStore() task1 = task_store.new('1. My Task') task2 = task_store.new('2. My Other Task') # Simple sort task_store.sort(key='title', reverse=True) expected = [task2, task1] self.assertEqual(task_store.data, expected)
def test_default_sort(self): task_store = TaskStore() task1 = task_store.new('My Task') task2 = task_store.new('My Other Task') # Sort by added date task_store.sort() expected = [task1, task2] self.assertEqual(task_store.data, expected)
def test_sort_custom_list(self): task_store = TaskStore() task1 = task_store.new('1. My Task') task2 = task_store.new('2. My Other Task') task3 = task_store.new('3. My Other Other Task') task4 = task_store.new('4. My Other Other Other Task') tasks = [task2, task4, task1] task_store.sort(tasks, key='title') expected = [task1, task2, task4] self.assertEqual(tasks, expected)
def test_filter_children(self): task_store = TaskStore() task1 = task_store.new('My Task') task2 = task_store.new('My Other Task') task3 = task_store.new('My Other Other Task') task_store.parent(task2.id, task1.id) task_store.parent(task3.id, task2.id) filtered = task_store.filter(Filter.CHILDREN) expected = [task2, task3] self.assertEqual(filtered, expected)
def test_new_simple(self): store = TaskStore() task = store.new('My Task') self.assertIsInstance(task, Task2) self.assertEqual(store.get(task.id), task) self.assertEqual(task.title, 'My Task') self.assertEqual(store.count(), 1)
def test_xml_write_simple(self): task_store = TaskStore() task_store.new('My Task') task_store.new('My Other Task') task_store.new('My Other Other Task') task_store.new('My Other Other Other Task') xml_root = task_store.to_xml() self.assertEqual(len(xml_root), 4)
def test_nested_sort(self): task_store = TaskStore() task1 = task_store.new('2. My Task') task2 = task_store.new('3. My Other Task') task3 = task_store.new('1. My Other Other Task') task4 = task_store.new('5. My Other Other Other Task') task_store.parent(task3.id, task2.id) task_store.parent(task4.id, task2.id) # Tree sort task_store.sort(key='title') expected = [task1, task2] expected_children = [task3, task4] self.assertEqual(task_store.data, expected) self.assertEqual(task_store.data[1].children, expected_children)
def test_filter_status(self): task_store = TaskStore() task1 = task_store.new('My Task') task2 = task_store.new('My Other Task') task3 = task_store.new('My Other Other Task') task4 = task_store.new('My Other Other Other Task') task1.toggle_active() task2.toggle_dismiss() task3.toggle_active() filtered = task_store.filter(Filter.STATUS, Status.ACTIVE) expected = [task4] self.assertEqual(filtered, expected) filtered = task_store.filter(Filter.STATUS, Status.DISMISSED) expected = [task2] self.assertEqual(filtered, expected) filtered = task_store.filter(Filter.STATUS, Status.DONE) expected = [task1, task3] self.assertEqual(filtered, expected)